// Initialize the window and tray icon BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { // prepare for XP style controls InitCommonControls(); // store instance handle and create dialog hInst = hInstance; hDlg = CreateDialog( hInstance, MAKEINTRESOURCE(IDD_DLG_DIALOG), NULL, (DLGPROC)DlgProc); if (!hDlg) { return FALSE; } IntializeNotificationData(); const CPath * imagePath = config.GetOffIconPath(); UINT flags = LR_LOADFROMFILE; HICON icon = (HICON)LoadImage( NULL, *imagePath, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), flags); niData.hIcon = icon; Shell_NotifyIcon(NIM_ADD, &niData); DestroyIcon(icon); niData.hIcon = NULL; StartProcess(); return TRUE; }
void ShowNotificationData(bool on) { NOTIFYICONDATA nid; ZeroMemory(&nid, sizeof(nid)); const CPath * imagePath = on ? config.GetOnIconPath() : config.GetOffIconPath(); UINT flags = LR_MONOCHROME; flags |= LR_LOADFROMFILE; HICON icon = (HICON)LoadImage( NULL, *imagePath, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), flags); nid.hIcon = icon; nid.uID = niData.uID; nid.hWnd = niData.hWnd; nid.uFlags = NIF_ICON; Shell_NotifyIcon(NIM_MODIFY, &nid); DestroyIcon(icon); }
BOOL OnInitDialog(HWND hWnd) { const CPath *imagePath = config.GetOffIconPath(); HMENU hMenu = GetSystemMenu(hWnd, FALSE); if (hMenu) { AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); AppendMenu(hMenu, MF_STRING, IDM_ABOUT, _T("About")); } HICON hIcon = (HICON)LoadImage( NULL, *imagePath, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE); SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon); SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); DestroyIcon(hIcon); return TRUE; }