Advertisement
Guest User

Shell_NotifyIcon encapsulated

a guest
Jul 26th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define WIN32_LEAN_AND_MEAN
  2. #include <Windows.h>
  3. #include "../NotifyIcon.h"
  4.  
  5. static NOTIFYICON_TOKEN ni, ni2;
  6.  
  7. static void CALLBACK MyHandleNiEvent(
  8.     NOTIFYICON_EVENTINFO ei)
  9. {
  10.     if (ei.event == NOTIFYICON_EVENT_CLICK)
  11.     {
  12.         if (ei.token == ni) {
  13.             int ret = MessageBox(GetForegroundWindow(),
  14.                 TEXT("Do you want to quit?"),
  15.                 TEXT("Quit?"), MB_ICONQUESTION | MB_YESNO);
  16.             if (ret == IDYES) { PostQuitMessage(0); }
  17.         }
  18.         else if (ei.token == ni2) {
  19.             MessageBox(GetForegroundWindow(),
  20.                 TEXT("This is how the Shell_NotifyIcon API should be."),
  21.                 TEXT("Encapsulated the headache"), MB_ICONINFORMATION);
  22.         }
  23.     }
  24. }
  25.  
  26. int APIENTRY WinMain(HINSTANCE z, HINSTANCE zz, LPSTR zzz, int nCmdShow)
  27. {
  28.     MSG msg = {0};
  29.     ni = NotifyIcon_Create();
  30.     ni2 = NotifyIcon_Create();
  31.     NotifyIcon_SetIcon(ni, LoadIcon(NULL, IDI_APPLICATION));
  32.     NotifyIcon_SetTip(ni, TEXT("Application"));
  33.     NotifyIcon_SetIcon(ni2, LoadIcon(NULL, IDI_INFORMATION));
  34.     NotifyIcon_SetTip(ni2, TEXT("Information"));
  35.     NotifyIcon_SetEventCallback(ni, MyHandleNiEvent, NULL);
  36.     NotifyIcon_SetEventCallback(ni2, MyHandleNiEvent, NULL);
  37.     while (GetMessage(&msg, NULL, 0, 0))
  38.     {
  39.         TranslateMessage(&msg);
  40.         DispatchMessage(&msg);
  41.     }
  42.     NotifyIcon_Delete(ni);
  43.     NotifyIcon_Delete(ni2);
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement