@@ -20,6 +20,7 @@ INCTXT(wblocksLibMJS, "src/lib.mjs");
2020
2121JSClassID jsBlockClassId ;
2222UINT_PTR createWindowTimer ;
23+ HINSTANCE hInst ;
2324
2425#define WBLOCKS_MAX_LEN 1024
2526
@@ -190,6 +191,7 @@ void createWindow()
190191 err ("failed to find taskbar" );
191192 return ;
192193 }
194+
193195 // Create window
194196 assert (CreateWindowEx (
195197 WS_EX_LAYERED , WBLOCKS_BAR_CLASS , "wblocks2_bar" ,
@@ -211,6 +213,16 @@ void initWnd(HWND wnd)
211213 wb .hdc = CreateCompatibleDC (wb .screenHDC );
212214 SetParent (wnd , wb .bar );
213215 updateBlocks (wnd );
216+
217+ // Show tray icon
218+ NOTIFYICONDATA notifData = {
219+ .cbSize = sizeof (notifData ),
220+ .hWnd = wnd ,
221+ .hIcon = LoadIcon (hInst , MAKEINTRESOURCE (100 )),
222+ .uFlags = NIF_ICON | NIF_TIP ,
223+ .szTip = "wblocks" ,
224+ };
225+ Shell_NotifyIcon (NIM_ADD , & notifData );
214226}
215227
216228void cleanupWnd ()
@@ -220,6 +232,8 @@ void cleanupWnd()
220232 }
221233 DeleteDC (wb .hdc );
222234 ReleaseDC (NULL , wb .screenHDC );
235+ NOTIFYICONDATA notifData = { .cbSize = sizeof (notifData ), .hWnd = wb .wnd };
236+ Shell_NotifyIcon (NIM_DELETE , & notifData );
223237 memset (& wb , 0 , sizeof (wb ));
224238 createWindowTimer = SetTimer (NULL , 0 , 3000 , (TIMERPROC )retryCreateWindow );
225239}
@@ -501,6 +515,8 @@ JSValue jsShell(JSContext *ctx, JSValueConst this, int argc, JSValueConst *argv)
501515
502516int CALLBACK WinMain (HINSTANCE inst , HINSTANCE prevInst , LPSTR cmdLine , int cmdShow )
503517{
518+ hInst = inst ;
519+
504520 // Load default font
505521 defaultBlock .font = xmalloc (sizeof (fontref_t ));
506522 defaultBlock .font -> handle = CreateFont (22 , 0 , 0 , 0 , FW_NORMAL , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , "Courier New" );
0 commit comments