Ik ben al dagen bezig met het uitzoeken hoe ik een tray menu kan toevoegen aan mijn systray Icon. Ik krijg met geen mogelijkheid messages van het icon opgevangen in m'n WndProc.
Example

Ik heb `MYMSG_NOTIFYICON` meegegeven aan de uCallbackMessage van de NOTIFYICONDATA structure. En die probeer ik op te vangen in WndProc maar ik krijg niets binnen.
Ik hoop dat iemand mij kan helpen. Ik werk op Microsoft Visual C++ 2005 Express edition.
Take care,
Pherion
Example

Ik heb `MYMSG_NOTIFYICON` meegegeven aan de uCallbackMessage van de NOTIFYICONDATA structure. En die probeer ik op te vangen in WndProc maar ik krijg niets binnen.
C++: main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
| // Headers #include "main.h" #include <windows.h> // Globals NOTIFYICONDATA NotifyIconData; // Event Message Handler Prototype LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam); // Main Entry Point int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int nCmdShow) { MSG msg; HWND hWindow; WNDCLASSEX wndclass; // Window Properties wndclass.cbSize = sizeof(wndclass); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = NULL; wndclass.cbWndExtra = NULL; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(ID_ICON1)); wndclass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(ID_ICON1)); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = CreateSolidBrush(RGB(235,233,238)); wndclass.lpszMenuName = TEXT("ID_MENU"); wndclass.lpszClassName = APP_NAME; // Register Window Class if(!RegisterClassEx(&wndclass)) { return 0; } // Create Main Window hWindow = CreateWindow(APP_NAME, APP_NAME, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 320, 240, NULL, NULL, hInstance, NULL); // Show & Update Window ShowWindow(hWindow, nCmdShow); UpdateWindow(hWindow); // Tray Icon NotifyIconData.cbSize = sizeof(NotifyIconData); NotifyIconData.hWnd = hWindow; NotifyIconData.uID = 1; NotifyIconData.uFlags = NIF_ICON | NIF_TIP | NIF_INFO; NotifyIconData.uCallbackMessage = MYMSG_NOTIFYICON; NotifyIconData.hIcon = wndclass.hIcon; lstrcpy(NotifyIconData.szTip, APP_NAME); NotifyIconData.uTimeout = 10000; lstrcpy(NotifyIconData.szInfo, TEXT("Ik ben een gemene bug ;)")); lstrcpy(NotifyIconData.szInfoTitle, TEXT("Hallo!")); NotifyIconData.dwInfoFlags = NIIF_NONE; Shell_NotifyIcon(NIM_ADD, &NotifyIconData); // Process Messages while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } UnregisterClass(APP_NAME, wndclass.hInstance); return 0; } // Event Message Handler LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_COMMAND: if(HIWORD(wParam) == BN_CLICKED) { if(LOWORD(wParam) == ID_FILE_NEW) { MessageBox(NULL, TEXT("New File!"), APP_NAME, MB_ICONQUESTION | MB_OK); } if(LOWORD(wParam) == ID_FILE_OPEN) { MessageBox(NULL, TEXT("Open File!"), APP_NAME, MB_ICONQUESTION | MB_OK); } if(LOWORD(wParam) == ID_FILE_EXIT) { Shell_NotifyIcon(NIM_DELETE, &NotifyIconData); PostQuitMessage(0); } } break; case MYMSG_NOTIFYICON: MessageBox(NULL, TEXT("Icon Message"), APP_NAME, MB_ICONQUESTION | MB_OK); break; case WM_DESTROY: Shell_NotifyIcon(NIM_DELETE, &NotifyIconData); PostQuitMessage(0); break; default: return DefWindowProc(hWindow, msg, wParam, lParam); break; } return 0; } |
C++: main.h
1
2
3
4
5
6
7
8
9
10
11
| #define _WIN32_IE 0x0501 #define APP_NAME TEXT("Simple Window Example") #define ID_ICON1 100 #define ID_FILE_NEW 101 #define ID_FILE_OPEN 102 #define ID_FILE_EXIT 103 #define MYMSG_NOTIFYICON (WM_APP + 104) |
C++: main.rc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| #include "main.h" ID_ICON1 ICON bug.ico ID_MENU MENU DISCARDABLE BEGIN POPUP "&File" BEGIN MENUITEM "&New", ID_FILE_NEW MENUITEM "&Open", ID_FILE_OPEN MENUITEM SEPARATOR MENUITEM "E&xit", ID_FILE_EXIT END END |
Ik hoop dat iemand mij kan helpen. Ik werk op Microsoft Visual C++ 2005 Express edition.
Take care,
Pherion