@@ -16,8 +16,11 @@ class Main
1616 static bool someSetting = false ;
1717 static frmMyDlg frmMyDlg = null ;
1818 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
2124 static Icon tbIcon = null ;
2225
2326 public static void OnNotification ( ScNotification notification )
@@ -47,14 +50,25 @@ internal static void CommandMenuInit()
4750
4851 internal static void SetToolBarIcon ( )
4952 {
53+ // create struct
5054 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
5262 IntPtr pTbIcons = Marshal . AllocHGlobal ( Marshal . SizeOf ( tbIcons ) ) ;
5363 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
5569 Marshal . FreeHGlobal ( pTbIcons ) ;
5670 }
57-
71+
5872 internal static void PluginCleanUp ( )
5973 {
6074 Win32 . WritePrivateProfileString ( "SomeSection" , "SomeKey" , someSetting ? "1" : "0" , iniFilePath ) ;
@@ -70,8 +84,10 @@ internal static void myDockableDialog()
7084 {
7185 if ( frmMyDlg == null )
7286 {
87+ // show dialog for first time
7388 frmMyDlg = new frmMyDlg ( ) ;
7489
90+ // icon
7591 using ( Bitmap newBmp = new Bitmap ( 16 , 16 ) )
7692 {
7793 Graphics g = Graphics . FromImage ( newBmp ) ;
@@ -81,17 +97,21 @@ internal static void myDockableDialog()
8197 colorMap [ 0 ] . NewColor = Color . FromKnownColor ( KnownColor . ButtonFace ) ;
8298 ImageAttributes attr = new ImageAttributes ( ) ;
8399 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 ) ;
85101 tbIcon = Icon . FromHandle ( newBmp . GetHicon ( ) ) ;
86102 }
87103
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+
95115 IntPtr _ptrNppTbData = Marshal . AllocHGlobal ( Marshal . SizeOf ( _nppTbData ) ) ;
96116 Marshal . StructureToPtr ( _nppTbData , _ptrNppTbData , false ) ;
97117
0 commit comments