forked from AgileEhsan/winasm-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Managers.asm
289 lines (269 loc) · 8.57 KB
/
Managers.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
IDD_DLGOPTMNU EQU 3200
IDC_LSTME EQU 3201
IDC_EDTMEITEM EQU 3202
IDC_EDTMECMND EQU 3203
IDC_BTNMEU EQU 3204
IDC_BTNMED EQU 3205
IDC_BTNMEADD EQU 3206
IDC_BTNMEDEL EQU 3207
IDC_BTNMFILE EQU 3208
IDB_ARROWUP EQU 108
IDB_ARROWDN EQU 109
.DATA?
hArrowUp DD ?
hArrowDn DD ?
hManagerDlg DD ?
lpFilter DD ?
.CODE
FillMenuItemsList Proc Uses EBX EDI
Local szCounter[12]:BYTE
Local Buffer[288]:BYTE ;256+32
XOR EBX,EBX
@@:
INC EBX
Invoke BinToDec,EBX,ADDR szCounter
Invoke GetPrivateProfileString, Offset szTOOLS, ADDR szCounter, ADDR szNULL, ADDR Buffer, 288, Offset IniFileName
.If EAX!=0 && EBX<=20
LEA EDI,Buffer
.If BYTE PTR [EDI]=="-"
Invoke SendDlgItemMessage,hManagerDlg,IDC_LSTME,LB_ADDSTRING,0,Offset szMinus
.Else
.While BYTE PTR [EDI]!=0
.If BYTE PTR [EDI]==","
MOV BYTE PTR [EDI],VK_TAB
Invoke SendDlgItemMessage,hManagerDlg,IDC_LSTME,LB_ADDSTRING,0,ADDR Buffer
.Break
.EndIf
INC EDI
.EndW
.EndIf
JMP @B
.EndIf
RET
FillMenuItemsList EndP
GetMenuItem Proc Uses EDI mItem:DWORD
Local Buffer[288]:BYTE ;256+32
Invoke SendDlgItemMessage,hManagerDlg,IDC_LSTME,LB_GETTEXT,mItem,ADDR Buffer
LEA EDI,Buffer
.If BYTE PTR [EDI]=="-"
Invoke SendDlgItemMessage,hManagerDlg,IDC_EDTMEITEM,WM_SETTEXT,0,Offset szMinus
Invoke SendDlgItemMessage,hManagerDlg,IDC_EDTMECMND,WM_SETTEXT,0,NULL
.Else
.While BYTE PTR [EDI]!=0
.If BYTE PTR [EDI]==VK_TAB
MOV BYTE PTR [EDI],0
Invoke SendDlgItemMessage,hManagerDlg,IDC_EDTMEITEM,WM_SETTEXT,0,ADDR Buffer
INC EDI
Invoke SendDlgItemMessage,hManagerDlg,IDC_EDTMECMND,WM_SETTEXT,0,EDI
.Break
.EndIf
INC EDI
.EndW
.EndIf
RET
GetMenuItem EndP
SaveMenuItems Proc Uses ESI
Local Buffer[256]:BYTE
Local nInx:DWORD
Local szCounter[12]:BYTE
;Delete All Tools from INI
MOV nInx,0
@@:
INC nInx
Invoke BinToDec,nInx,ADDR szCounter
Invoke WritePrivateProfileString,Offset szTOOLS,ADDR szCounter,Offset szNULL,Offset IniFileName
.If nInx<20
JMP @B
.EndIf
;Add New Tools to INI
MOV nInx,0
.While TRUE && nInx<20
Invoke SendDlgItemMessage,hManagerDlg,IDC_LSTME,LB_GETTEXT,nInx,ADDR Buffer
.Break .If EAX==LB_ERR
MOV AL,Buffer[0]
.If AL=="-" || AL==VK_TAB
MOV Buffer[0],"-"
MOV Buffer[1],0
CALL AddIt
.Else;If AL!=VK_TAB
LEA ESI,Buffer
@@:
MOV AL,[ESI]
INC ESI
.If AL==09h
MOV BYTE PTR [ESI-1],","
CALL AddIt
.Else
JMP @B
.EndIf
.EndIf
INC nInx
.EndW
RET
AddIt:
MOV EAX,nInx
INC EAX
LEA EDX,szCounter
Invoke BinToDec,EAX,EDX
Invoke WritePrivateProfileString,Offset szTOOLS,ADDR szCounter,ADDR Buffer,Offset IniFileName
RETN
SaveMenuItems EndP
EditUpdate Proc Uses ESI
Local Buffer[256]:BYTE
Local nInx:DWORD
Invoke SendDlgItemMessage,hManagerDlg,IDC_LSTME,WM_SETREDRAW,FALSE,0
Invoke GetDlgItemText,hManagerDlg,IDC_EDTMEITEM,ADDR Buffer,256
Invoke lstrlen,ADDR Buffer
LEA ESI,Buffer
ADD ESI,EAX
MOV BYTE PTR [ESI],09h
INC ESI
Invoke GetDlgItemText,hManagerDlg,IDC_EDTMECMND,ESI,256
Invoke SendDlgItemMessage,hManagerDlg,IDC_LSTME,LB_GETCURSEL,0,0
.If EAX==LB_ERR
MOV EAX,0
.EndIf
MOV nInx,EAX
Invoke SendDlgItemMessage,hManagerDlg,IDC_LSTME,LB_DELETESTRING,nInx,0
Invoke SendDlgItemMessage,hManagerDlg,IDC_LSTME,LB_INSERTSTRING,nInx,ADDR Buffer
Invoke SendDlgItemMessage,hManagerDlg,IDC_LSTME,LB_SETCURSEL,nInx,0
Invoke SendDlgItemMessage,hManagerDlg,IDC_LSTME,WM_SETREDRAW,TRUE,0
RET
EditUpdate EndP
ManagerProc Proc hDlg:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
Local nInx:DWORD
Local Buffer[256]:BYTE
MOV EAX,uMsg
.If EAX==WM_VKEYTOITEM
; WM_VKEYTOITEM
; vkey = LOWORD(wParam); // virtual-key code
; nCaretPos = HIWORD(wParam); // caret position
; hwndLB = lParam; // handle of list box
;
; vkey
; Value of the low-order word of wParam. Specifies the virtual-key code of the key the user pressed.
;
; nCaretPos
; Value of the high-order word of wParam. Specifies the current position of the caret.
;
; hwndLB
; Value of lParam. Identifies the list box.
LOWORD wParam
.If EAX==VK_DELETE
Invoke SendMessage,hDlg,WM_COMMAND, (BN_CLICKED SHL 16) OR IDC_BTNMEDEL,0
MOV EAX,-2
.Else
;Default processing
MOV EAX,-1
.EndIf
RET
;A return value of -2 indicates that the application handled all aspects of selecting the item and requires no further action by the list box.
;A return value of -1 indicates that the list box should perform the default action in response to the keystroke.
;A return value of 0 or greater specifies the index of an item in the list box and indicates that the list box should perform the default action for the keystroke on the given item.
.ElseIf EAX==WM_INITDIALOG
M2M hManagerDlg,hDlg
Invoke SendDlgItemMessage,hDlg,IDC_EDTMEITEM,EM_LIMITTEXT,32,0
Invoke SendDlgItemMessage,hDlg,IDC_EDTMECMND,EM_LIMITTEXT,128,0
MOV nInx,120
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_SETTABSTOPS,1,ADDR nInx
LEA EAX,ExecutablesFilter
MOV lpFilter,EAX
Invoke LoadImage,hInstance,IDB_ARROWUP,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE + LR_LOADMAP3DCOLORS
MOV hArrowUp,EAX
Invoke SendDlgItemMessage,hDlg,IDC_BTNMEU,BM_SETIMAGE,IMAGE_BITMAP,EAX
Invoke LoadImage,hInstance,IDB_ARROWDN,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE + LR_LOADMAP3DCOLORS
MOV hArrowDn,EAX
Invoke SendDlgItemMessage,hDlg,IDC_BTNMED,BM_SETIMAGE,IMAGE_BITMAP,EAX
Invoke FillMenuItemsList
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_SETCURSEL,0,0
Invoke GetMenuItem,0
.ElseIf EAX==WM_COMMAND
MOV EAX,wParam
MOV EDX,EAX
SHR EDX,16
AND EAX,0FFFFh
.If EDX==BN_CLICKED
.If EAX==IDOK
Invoke SaveMenuItems
;Delete All Items after "Tools Manager"
.While TRUE
Invoke DeleteMenu,WinAsmHandles.PopUpMenus.hToolsMenu,7,MF_BYPOSITION
.Break .If !EAX
.EndW
Invoke AddToolsSubMenus
Invoke SendMessage,hDlg,WM_CLOSE,NULL,NULL
.ElseIf EAX==IDCANCEL
Invoke SendMessage,hDlg,WM_CLOSE,NULL,NULL
.ElseIf EAX==IDC_BTNMEU
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_GETCURSEL,0,0
.If EAX
MOV nInx,EAX
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_GETTEXT,nInx,ADDR Buffer
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_DELETESTRING,nInx,0
DEC nInx
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_INSERTSTRING,nInx,ADDR Buffer
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_SETCURSEL,nInx,0
.EndIf
.ElseIf EAX==IDC_BTNMED
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_GETCURSEL,0,0
MOV nInx,EAX
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_GETCOUNT,0,0
DEC EAX
.If EAX!=nInx
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_GETTEXT,nInx,ADDR Buffer
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_DELETESTRING,nInx,0
INC nInx
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_INSERTSTRING,nInx,ADDR Buffer
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_SETCURSEL,nInx,0
.EndIf
.ElseIf EAX==IDC_BTNMEADD
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_GETCURSEL,0,0
.If EAX==LB_ERR
MOV EAX,0
.EndIf
MOV nInx,EAX
MOV Buffer[0],09h
MOV Buffer[1],0
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_INSERTSTRING,nInx,addr Buffer
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_SETCURSEL,nInx,0
Invoke SendDlgItemMessage,hDlg,IDC_EDTMECMND,WM_SETTEXT,0,addr szNULL
Invoke SendDlgItemMessage,hDlg,IDC_EDTMEITEM,WM_SETTEXT,0,addr szNULL
.ElseIf EAX==IDC_BTNMEDEL
Invoke SendDlgItemMessage,hDlg,IDC_EDTMECMND,WM_SETTEXT,0,ADDR szNULL
Invoke SendDlgItemMessage,hDlg,IDC_EDTMEITEM,WM_SETTEXT,0,ADDR szNULL
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_GETCURSEL,0,0
.If EAX!=LB_ERR
MOV nInx,EAX
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_DELETESTRING,nInx,0
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_SETCURSEL,nInx,0
.If EAX==LB_ERR
DEC nInx
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_SETCURSEL,nInx,0
.EndIf
.If EAX!=LB_ERR
Invoke GetMenuItem,nInx
.EndIf
.EndIf
.ElseIf EAX==IDC_BTNMFILE
Invoke GetDlgItem,hDlg,IDC_EDTMECMND
Invoke BrowseForFile,hDlg,lpFilter,EAX,0
.EndIf
.ElseIf EDX==EN_CHANGE
Invoke EditUpdate
.ElseIf EDX==LBN_SELCHANGE
Invoke SendDlgItemMessage,hDlg,IDC_LSTME,LB_GETCURSEL,0,0
.If EAX!=LB_ERR
Invoke GetMenuItem,EAX
.EndIf
.EndIf
.ElseIf EAX==WM_CLOSE
Invoke DeleteObject,hArrowUp
Invoke DeleteObject,hArrowDn
Invoke EndDialog,hDlg,NULL
.Else
MOV EAX,FALSE
RET
.EndIf
MOV EAX,TRUE
RET
ManagerProc EndP