@@ -16,8 +16,11 @@ class Main
16
16
static bool someSetting = false ;
17
17
static frmMyDlg frmMyDlg = null ;
18
18
static int idMyDlg = - 1 ;
19
- static Bitmap tbBmp = Properties . Resources . star ;
20
- static Bitmap tbBmp_tbTab = Properties . Resources . star_bmp ;
19
+
20
+ // toolbar icons
21
+ static Bitmap tbBmp_color = Properties . Resources . star ; // standard icon small color
22
+ static Icon tbIco_black = Properties . Resources . star_black ; // Fluent UI icon black
23
+ static Icon tbIco_white = Properties . Resources . star_white ; // Fluent UI icon white
21
24
static Icon tbIcon = null ;
22
25
23
26
public static void OnNotification ( ScNotification notification )
@@ -47,14 +50,25 @@ internal static void CommandMenuInit()
47
50
48
51
internal static void SetToolBarIcon ( )
49
52
{
53
+ // create struct
50
54
toolbarIcons tbIcons = new toolbarIcons ( ) ;
51
- tbIcons . hToolbarBmp = tbBmp . GetHbitmap ( ) ;
55
+
56
+ // add bmp icon
57
+ tbIcons . hToolbarBmp = tbBmp_color . GetHbitmap ( ) ;
58
+ tbIcons . hToolbarIcon = tbIco_black . Handle ; // icon with black lines
59
+ tbIcons . hToolbarIconDarkMode = tbIco_white . Handle ; // icon with light grey lines
60
+
61
+ // convert to c++ pointer
52
62
IntPtr pTbIcons = Marshal . AllocHGlobal ( Marshal . SizeOf ( tbIcons ) ) ;
53
63
Marshal . StructureToPtr ( tbIcons , pTbIcons , false ) ;
54
- Win32 . SendMessage ( PluginBase . nppData . _nppHandle , ( uint ) NppMsg . NPPM_ADDTOOLBARICON , PluginBase . _funcItems . Items [ idMyDlg ] . _cmdID , pTbIcons ) ;
64
+
65
+ // call Notepad++ api
66
+ Win32 . SendMessage ( PluginBase . nppData . _nppHandle , ( uint ) NppMsg . NPPM_ADDTOOLBARICON_FORDARKMODE , PluginBase . _funcItems . Items [ idMyDlg ] . _cmdID , pTbIcons ) ;
67
+
68
+ // release pointer
55
69
Marshal . FreeHGlobal ( pTbIcons ) ;
56
70
}
57
-
71
+
58
72
internal static void PluginCleanUp ( )
59
73
{
60
74
Win32 . WritePrivateProfileString ( "SomeSection" , "SomeKey" , someSetting ? "1" : "0" , iniFilePath ) ;
@@ -70,8 +84,10 @@ internal static void myDockableDialog()
70
84
{
71
85
if ( frmMyDlg == null )
72
86
{
87
+ // show dialog for first time
73
88
frmMyDlg = new frmMyDlg ( ) ;
74
89
90
+ // icon
75
91
using ( Bitmap newBmp = new Bitmap ( 16 , 16 ) )
76
92
{
77
93
Graphics g = Graphics . FromImage ( newBmp ) ;
@@ -81,17 +97,21 @@ internal static void myDockableDialog()
81
97
colorMap [ 0 ] . NewColor = Color . FromKnownColor ( KnownColor . ButtonFace ) ;
82
98
ImageAttributes attr = new ImageAttributes ( ) ;
83
99
attr . SetRemapTable ( colorMap ) ;
84
- g . DrawImage ( tbBmp_tbTab , new Rectangle ( 0 , 0 , 16 , 16 ) , 0 , 0 , 16 , 16 , GraphicsUnit . Pixel , attr ) ;
100
+ g . DrawImage ( tbBmp_color , new Rectangle ( 0 , 0 , 16 , 16 ) , 0 , 0 , 16 , 16 , GraphicsUnit . Pixel , attr ) ;
85
101
tbIcon = Icon . FromHandle ( newBmp . GetHicon ( ) ) ;
86
102
}
87
103
88
- NppTbData _nppTbData = new NppTbData ( ) ;
89
- _nppTbData . hClient = frmMyDlg . Handle ;
90
- _nppTbData . pszName = "My dockable dialog" ;
91
- _nppTbData . dlgID = idMyDlg ;
92
- _nppTbData . uMask = NppTbMsg . DWS_DF_CONT_RIGHT | NppTbMsg . DWS_ICONTAB | NppTbMsg . DWS_ICONBAR ;
93
- _nppTbData . hIconTab = ( uint ) tbIcon . Handle ;
94
- _nppTbData . pszModuleName = PluginName ;
104
+ // dockable window struct data
105
+ var _nppTbData = new NppTbData
106
+ {
107
+ hClient = frmMyDlg . Handle ,
108
+ pszName = "My dockable dialog" ,
109
+ dlgID = idMyDlg ,
110
+ uMask = NppTbMsg . DWS_DF_CONT_RIGHT | NppTbMsg . DWS_ICONTAB | NppTbMsg . DWS_ICONBAR ,
111
+ hIconTab = ( uint ) tbIcon . Handle ,
112
+ pszModuleName = PluginName
113
+ } ;
114
+
95
115
IntPtr _ptrNppTbData = Marshal . AllocHGlobal ( Marshal . SizeOf ( _nppTbData ) ) ;
96
116
Marshal . StructureToPtr ( _nppTbData , _ptrNppTbData , false ) ;
97
117
0 commit comments