-
Notifications
You must be signed in to change notification settings - Fork 3
/
ni.asm
126 lines (110 loc) · 3.02 KB
/
ni.asm
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
.386
.model flat,stdcall
option casemap:none
include ni.inc
.code
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke WinMain,hInstance,NULL,NULL,SW_HIDE
invoke ExitProcess,eax
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
mov wc.cbSize,sizeof WNDCLASSEX
mov wc.lpfnWndProc,offset WndProc
mov wc.cbWndExtra,DLGWINDOWEXTRA
mov wc.cbClsExtra,0
mov wc.style,3
mov wc.hbrBackground,6
invoke LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
invoke LoadCursor, NULL, IDC_ARROW
mov wc.hCursor, eax
mov wc.lpszMenuName,0
mov wc.hIconSm,0
push hInst
pop wc.hInstance
mov wc.lpszClassName,offset ClassName
invoke RegisterClassEx,addr wc
invoke CreateDialogParam,hInstance,IDD_DIALOG,NULL,addr WndProc,NULL
mov nid.hwnd,eax
mov nid.cbSize,sizeof NOTIFYICONDATA
mov nid.uID,IDI_TRAY
mov nid.uFlags,NIF_ICON+NIF_MESSAGE+NIF_TIP
mov nid.uCallbackMessage,WM_SHELLNOTIFY
invoke LoadIcon,hInst,IDI_ON
mov IconOn,eax
invoke LoadIcon,hInst,IDI_OFF
mov IconOff,eax
invoke GetKeyState,VK_NUMLOCK
invoke lstrcpy,addr nid.szTip,addr StatusPrefix
.if eax==1
invoke lstrcat,addr nid.szTip,addr StatusOn
push IconOn
.else
invoke lstrcat,addr nid.szTip,addr StatusOff
push IconOff
.endif
pop nid.hIcon
invoke ShowWindow,hWnd,CmdShow
invoke Shell_NotifyIcon,NIM_ADD,addr nid
invoke UpdateWindow,hWnd
invoke SetTimer,hWnd,NULL,200,NULL
.while TRUE
invoke GetMessage,addr msg,NULL,0,0
.BREAK .if !eax
invoke TranslateMessage,addr msg
invoke DispatchMessage,addr msg
.endw
mov eax,msg.wParam
ret
WinMain endp
WndProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL pt:POINT
.if uMsg==WM_INITDIALOG
push hWin
pop hWnd
.elseif uMsg==WM_CREATE
invoke CreatePopupMenu
mov hPopupMenu,eax
invoke AppendMenu,hPopupMenu,MF_STRING,IDM_EXIT,addr ExitDesc
.elseif uMsg==WM_COMMAND
mov eax,wParam
and eax,0FFFFh
.if eax==IDM_EXIT
invoke SendMessage,hWin,WM_CLOSE,0,0
.endif
.elseif uMsg==WM_DESTROY
invoke DestroyMenu,hPopupMenu
invoke Shell_NotifyIcon,NIM_DELETE,addr nid
invoke DestroyWindow,hWin
invoke PostQuitMessage,NULL
.elseif uMsg==WM_TIMER
invoke lstrcpy,addr nid.szTip,addr StatusPrefix
invoke GetKeyState,VK_NUMLOCK
.if eax==1
invoke lstrcat,addr nid.szTip,addr StatusOn
push IconOn
.else
invoke lstrcat,addr nid.szTip,addr StatusOff
push IconOff
.endif
pop nid.hIcon
invoke Shell_NotifyIcon,NIM_MODIFY,addr nid
.elseif uMsg==WM_SHELLNOTIFY
.if wParam==IDI_TRAY
.if lParam==WM_RBUTTONDOWN
invoke GetCursorPos,addr pt
invoke SetForegroundWindow,hWnd
invoke TrackPopupMenu,hPopupMenu,TPM_RIGHTALIGN,pt.x,pt.y,NULL,hWnd,NULL
invoke PostMessage,hWnd,WM_NULL,0,0
.endif
.endif
.else
invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret
.endif
ret
WndProc endp
end start