Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "shellapi.h"
  3.  
  4. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  5.  
  6. int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
  7. {
  8. MSG msg;
  9.  
  10. WNDCLASS wc;
  11. memset(&wc, 0, sizeof(wc));
  12. wc.lpfnWndProc = WndProc;
  13. wc.hInstance = hInstance;
  14. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  15. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  16. wc.lpszClassName = "sysTrayTest";
  17. RegisterClass(&wc);
  18.  
  19. HWND hWnd = CreateWindow("sysTrayTest", "",
  20. WS_OVERLAPPEDWINDOW,
  21. CW_USEDEFAULT, 0, 500, 500,
  22. NULL, NULL, hInstance, NULL);
  23. if (hWnd)
  24. {
  25. ShowWindow(hWnd, nCmdShow);
  26. while (GetMessage(&msg, NULL, 0, 0))
  27. {
  28. TranslateMessage(&msg);
  29. DispatchMessage(&msg);
  30. }
  31. }
  32.  
  33. return 0;
  34. }
  35.  
  36. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  37. {
  38. switch (message)
  39. {
  40. case WM_DESTROY:
  41. {
  42. NOTIFYICONDATA nid;
  43. memset(&nid, 0, sizeof(NOTIFYICONDATA));
  44. nid.cbSize = sizeof(NOTIFYICONDATA);
  45. nid.hWnd = hWnd;
  46. nid.uID = 1;
  47. Shell_NotifyIcon(NIM_DELETE, &nid);
  48.  
  49. PostQuitMessage(0);
  50. }
  51. break;
  52.  
  53. case WM_CREATE:
  54. {
  55. NOTIFYICONDATA nid;
  56. memset(&nid, 0, sizeof(NOTIFYICONDATA));
  57. nid.cbSize = sizeof(NOTIFYICONDATA);
  58. nid.hWnd = hWnd;
  59. nid.uID = 1;
  60. nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  61. nid.uCallbackMessage = WM_USER + 200;
  62. nid.hIcon = LoadIcon(NULL, IDI_INFORMATION);
  63. lstrcpy (nid.szTip, "Test Tip");
  64. Shell_NotifyIcon(NIM_ADD, &nid);
  65. }
  66. break;
  67.  
  68. case WM_LBUTTONDOWN:
  69. {
  70. NOTIFYICONDATA nid;
  71. memset(&nid, 0, sizeof(NOTIFYICONDATA));
  72. nid.cbSize = sizeof(NOTIFYICONDATA);
  73. nid.hWnd = hWnd;
  74. nid.uID = 1;
  75. nid.uFlags = NIF_INFO;
  76. lstrcpy(nid.szInfo, "Test balloon tip");
  77. lstrcpy(nid.szInfoTitle, "Test Title");
  78. nid.dwInfoFlags = NIIF_INFO;
  79. nid.uTimeout = 15000;
  80. Shell_NotifyIcon(NIM_MODIFY, &nid);
  81. }
  82. break;
  83.  
  84. default:
  85. return DefWindowProc(hWnd, message, wParam, lParam);
  86. }
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement