Repository navigation
Expand file tree
/
Copy pathMenuToolsHook.cpp
More file actions
107 lines (97 loc) · 1.79 KB
/
Copy pathMenuToolsHook.cpp
File metadata and controls
107 lines (97 loc) · 1.79 KB
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
// MenuToolsHook.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "MenuTools.h"
#include "MenuCommon/TrayIcon.h"
#define WM_GETSYSMENU 0x313
// Process messages
LRESULT CALLBACK HookProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CONTEXTMENU:
case WM_INITMENU:
case WM_INITMENUPOPUP:
case WM_GETSYSMENU:
{
// Install custom menus
if (MenuTools::Install(hWnd))
{
// Update menu
MenuTools::Status(hWnd);
return TRUE;
}
break;
}
case MT_HOOK_MSG_TRAY:
{
// Process tray messages
MenuTools::TrayProc(hWnd, wParam, lParam);
return TRUE;
break;
}
case WM_COMMAND:
case WM_SYSCOMMAND:
{
// Process menu messages
MenuTools::WndProc(hWnd, wParam, lParam);
return TRUE;
break;
}
default:
{
// Quit message
if (message == MT_HOOK_MSG_QUIT)
{
// Restore previous windows
for (Tray_It it = mTrays.begin(); it != mTrays.end(); it++)
{
ShowWindow(it->first, SW_SHOW);
}
// Destroy all tray icons
mTrays.clear();
// Uninstall menus
MenuTools::Uninstall(hWnd);
return TRUE;
}
}
}
return FALSE;
}
// Sent messages
LRESULT CALLBACK CallWndProc(
_In_ int nCode,
_In_ WPARAM wParam,
_In_ LPARAM lParam
)
{
switch (nCode)
{
case HC_ACTION:
{
CWPSTRUCT* sMsg = (CWPSTRUCT*)lParam;
HookProc(sMsg->hwnd, sMsg->message, sMsg->wParam, sMsg->lParam);
}
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
// Post messages
LRESULT CALLBACK GetMsgProc(
_In_ int code,
_In_ WPARAM wParam,
_In_ LPARAM lParam
)
{
switch (code)
{
case HC_ACTION:
{
if (wParam == PM_REMOVE)
{
MSG* pMsg = (MSG*)lParam;
HookProc(pMsg->hwnd, pMsg->message, pMsg->wParam, pMsg->lParam);
}
}
}
return CallNextHookEx(NULL, code, wParam, lParam);
}