-
Notifications
You must be signed in to change notification settings - Fork 3
/
RCResources.asm
456 lines (401 loc) · 13 KB
/
RCResources.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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
.DATA?
hEditResourcesTable HWND ?
hBrowseResourceButton HWND ?
lpPrevEditResourcesTableProc DWORD ?
ItemBeingEdited DWORD ?
SubItemBeingEdited DWORD ?
lpPrevBrowseResourceButtonProc DWORD ?
bResourcesModified DWORD ?
.CODE
ParseResource Proc Uses EBX ESI EDI,lpRCMem:DWORD,lpProMem:DWORD,nType:DWORD
MOV ESI,lpRCMem
.If !lpResourcesMem
Invoke HeapAlloc,hMainHeap,HEAP_ZERO_MEMORY,64*1024
MOV lpResourcesMem,EAX
.EndIf
MOV EDI,lpResourcesMem
PUSH EDI
.While [EDI].RESOURCEMEM.szFile
LEA EDI,[EDI+SizeOf RESOURCEMEM]
.EndW
MOV EAX,nType
MOV [EDI].RESOURCEMEM.nType,EAX
Invoke GetName,lpProMem,Offset NameBuffer,ADDR [EDI].RESOURCEMEM.szName,ADDR [EDI].RESOURCEMEM.Value
XOR EBX,EBX
@@:
ADD ESI,EBX
Invoke GetWord,Offset ThisWord,ESI
MOV EBX,EAX
Invoke lstrcmpi,Offset ThisWord,Offset szPRELOAD
OR EAX,EAX
JE @B
Invoke lstrcmpi,Offset ThisWord,Offset szLOADONCALL
OR EAX,EAX
JE @B
Invoke lstrcmpi,Offset ThisWord,Offset szFIXED
OR EAX,EAX
JE @B
Invoke lstrcmpi,Offset ThisWord,Offset szMOVEABLE
OR EAX,EAX
JE @B
Invoke lstrcmpi,Offset ThisWord,Offset szDISCARDABLE
OR EAX,EAX
JE @B
Invoke lstrcmpi,Offset ThisWord,Offset szPURE
OR EAX,EAX
JE @B
Invoke lstrcmpi,Offset ThisWord,Offset szIMPURE
OR EAX,EAX
JE @B
Invoke ParseFileName,ESI
ADD ESI,EAX
Invoke lstrcpy,ADDR [EDI].RESOURCEMEM.szFile,Offset ThisWord
POP EDI
.If !hResourcesParentItem
Invoke AddToOthersTree,4,Offset szResources,EDI
MOV hResourcesParentItem,EAX
.EndIf
MOV EAX,ESI
SUB EAX,lpRCMem
RET
ParseResource EndP
ResourcesTableGiveCellFocus Proc hList:HWND, Item:DWORD, SubItem:DWORD
Local Rect :RECT
Local Buffer[256] :BYTE
MOV EAX,Item
MOV ItemBeingEdited,EAX
MOV EAX,SubItem
MOV SubItemBeingEdited,EAX
MOV Rect.top,EAX
MOV Rect.left,LVIR_LABEL
Invoke SendMessage,hList,LVM_GETSUBITEMRECT,Item,ADDR Rect
Invoke GetWindowLong,hEditResourcesTable,GWL_STYLE
.If SubItem!=0
ADD Rect.left,3
OR EAX,ES_NUMBER
.Else
AND EAX,-1 XOR ES_NUMBER
.EndIf
Invoke SetWindowLong,hEditResourcesTable,GWL_STYLE,EAX
MOV ECX,Rect.bottom
SUB ECX,Rect.top
DEC ECX
MOV EAX,Rect.right
SUB EAX,Rect.left
Invoke SetWindowPos,hEditResourcesTable,NULL,Rect.left,Rect.top,EAX,ECX,SWP_SHOWWINDOW
Invoke GetItemText,hList,Item,SubItem,ADDR Buffer
Invoke SendMessage,hEditResourcesTable,WM_SETTEXT,0,ADDR Buffer
Invoke SendMessage,hEditResourcesTable,WM_GETTEXTLENGTH,0,0
Invoke SendMessage,hEditResourcesTable,EM_SETSEL,EAX,EAX
Invoke SendMessage,hEditResourcesTable,EM_SETMODIFY,FALSE,0
Invoke SetFocus,hEditResourcesTable
RET
ResourcesTableGiveCellFocus EndP
EditResourcesTableProc Proc Uses EDI EBX hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
Local Buffer[256] :BYTE
.If uMsg==WM_KILLFOCUS
Invoke SendMessage,hWnd,EM_GETMODIFY,0,0
.If EAX
MOV bResourcesModified,TRUE
.EndIf
Invoke SendMessage,hWnd,WM_GETTEXT,256,ADDR Buffer
Invoke GetParent,hWnd
MOV ECX,EAX
Invoke SetItemText,ECX,ItemBeingEdited,SubItemBeingEdited,ADDR Buffer
Invoke ShowWindow,hWnd,SW_HIDE
.ElseIf uMsg==WM_KEYDOWN
.If wParam==VK_TAB || wParam==VK_RETURN
;PUSH EDI
Invoke GetParent,hWnd
MOV EDI,EAX
Invoke SetFocus,EDI ;List
Invoke GetKeyState, VK_SHIFT
AND EAX,80h
.If EAX==80h ;Shift is pressed
.If SubItemBeingEdited==1 ;|| SubItemBeingEdited==2
DEC SubItemBeingEdited
Invoke ResourcesTableGiveCellFocus,EDI,ItemBeingEdited,SubItemBeingEdited
.EndIf
.Else
.If SubItemBeingEdited==0 ;|| SubItemBeingEdited==1
INC SubItemBeingEdited
Invoke ResourcesTableGiveCellFocus,EDI,ItemBeingEdited,SubItemBeingEdited
;.ElseIf SubItemBeingEdited==1
;Invoke SetFocus,hBrowseResourceButton
.EndIf
.EndIf
;POP EDI
.EndIf
.EndIf
Invoke CallWindowProc,lpPrevEditResourcesTableProc,hWnd,uMsg,wParam,lParam
RET
EditResourcesTableProc EndP
BrowseResourceButtonProc Proc hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
Local Buffer2[256] :BYTE
Local Buffer[256] :BYTE
Local lvi :LVITEM
.If uMsg==WM_LBUTTONUP
Invoke BrowseForFile,hWnd,Offset ResourcesFilter,0,ADDR Buffer
.If EAX
PUSH EBX
DEC ECX ;(Filter index)
PUSH ECX ;Resource type
Invoke GetWindowLong,hRCEditorWindow,0
LEA ECX,CHILDWINDOWDATA.szFileName[EAX]
Invoke GetFilePath,ECX,ADDR Buffer2
MOV EBX,EAX
MOV CL,Buffer[EBX+1]
MOV Buffer[EBX+1],0
PUSH ECX
Invoke lstrcmpi,ADDR Buffer,ADDR Buffer2
POP ECX
MOV Buffer[EBX+1],CL
.If !EAX
LEA ECX,Buffer
ADD EBX,ECX
INC EBX
.Else
LEA EBX,Buffer
.EndIf
Invoke ReplaceBackSlashWithSlash,EBX
Invoke GetParent,hWnd
PUSH EAX
Invoke SendMessage,EAX,LVM_GETNEXTITEM,-1,LVNI_ALL or LVNI_SELECTED
MOV lvi.iItem,EAX
MOV lvi.imask,LVIF_TEXT or LVIF_STATE; or LVIF_PARAM
MOV lvi.cchTextMax,256
MOV lvi.iSubItem, 2
MOV lvi.state,LVIS_SELECTED
MOV lvi.pszText,EBX
POP EBX
Invoke SendMessage,EBX,LVM_SETITEM,0,ADDR lvi
POP ECX
Invoke SetItemParameter,EBX,lvi.iItem,ECX
MOV bResourcesModified,TRUE
Invoke SetFocus,EBX
POP EBX
.EndIf
.EndIf
Invoke CallWindowProc,lpPrevBrowseResourceButtonProc,hWnd,uMsg,wParam,lParam
RET
BrowseResourceButtonProc EndP
ResourcesDialogProc Proc Uses EBX EDI ESI hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
Local lvc :LV_COLUMN
Local lvi :LVITEM
Local Buffer[256] :BYTE
Local hList :HWND
Local Rect :RECT
Local Buffer2[256] :BYTE
.If uMsg == WM_INITDIALOG
MOV bResourcesModified,FALSE
Invoke GetDlgItem,hWnd,1
MOV hList,EAX
;I don't really need more than on line. I use ES_MULTILINE simply so that I can catch TAB & Enter keys
Invoke CreateWindowEx,NULL,ADDR szEditClass,NULL,WS_CHILD or ES_AUTOHSCROLL or ES_MULTILINE,0,0,0,0,hList,100,hInstance,NULL
MOV hEditResourcesTable,EAX
Invoke SendMessage,hWnd,WM_GETFONT,0,0
Invoke SendMessage,hEditResourcesTable,WM_SETFONT,EAX,FALSE
Invoke SetWindowLong,hEditResourcesTable,GWL_WNDPROC,Offset EditResourcesTableProc
MOV lpPrevEditResourcesTableProc,EAX
Invoke CreateWindowEx,NULL,ADDR szButton,Offset szTwoDots,WS_CHILD or WS_VISIBLE + WS_CLIPSIBLINGS,0,0,0,0,hList,100,hInstance,NULL
MOV hBrowseResourceButton,EAX
Invoke SetWindowLong,EAX,GWL_WNDPROC,Offset BrowseResourceButtonProc
MOV lpPrevBrowseResourceButtonProc,EAX
;MOV EAX, LVS_EX_GRIDLINES ;LVS_EX_FULLROWSELECT; OR
Invoke SendMessage,hList,LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_GRIDLINES OR LVS_EX_FULLROWSELECT
MOV lvc.imask, LVCF_TEXT OR LVCF_WIDTH OR LVCF_FMT
MOV lvc.fmt,LVCFMT_LEFT
MOV lvc.cchTextMax,MAX_PATH
MOV lvc.pszText,Offset szName
MOV lvc.lx,170
Invoke SendMessage, hList, LVM_INSERTCOLUMN, 0, ADDR lvc
MOV lvc.pszText,Offset szID
MOV lvc.lx,72
Invoke SendMessage, hList, LVM_INSERTCOLUMN, 1, ADDR lvc
MOV lvc.pszText,Offset szFile
MOV lvc.lx,167
Invoke SendMessage, hList, LVM_INSERTCOLUMN, 2, ADDR lvc
.If lpResourcesMem
MOV EDI,lpResourcesMem
MOV lvi.cchTextMax,256
MOV lvi.state,LVIS_SELECTED
XOR ESI,ESI
.While [EDI].RESOURCEMEM.szFile
MOV lvi.imask,LVIF_TEXT or LVIF_STATE or LVIF_PARAM
MOV lvi.iSubItem,0
MOV lvi.iItem,ESI
LEA EAX,[EDI].RESOURCEMEM.szName
MOV lvi.pszText,EAX
PUSH [EDI].RESOURCEMEM.nType
POP lvi.lParam
Invoke SendMessage,hList,LVM_INSERTITEM,0,ADDR lvi
MOV lvi.imask,LVIF_TEXT or LVIF_STATE
MOV lvi.iSubItem, 1
Invoke BinToDec,[EDI].RESOURCEMEM.Value,ADDR Buffer
LEA EAX,Buffer
MOV lvi.pszText,EAX
Invoke SendMessage,hList,LVM_SETITEM,0,ADDR lvi
MOV lvi.iSubItem,2; 3
LEA EAX,[EDI].RESOURCEMEM.szFile
MOV lvi.pszText,EAX
Invoke SendMessage,hList,LVM_SETITEM,0,ADDR lvi
LEA EDI,[EDI+SizeOf RESOURCEMEM]
INC ESI
.EndW
Invoke GetWindowLong,hList,GWL_STYLE
AND EAX,WS_VSCROLL
.If EAX==WS_VSCROLL
Invoke SendMessage,hList,LVM_SETCOLUMNWIDTH,2,150
.EndIf
.EndIf
Invoke SetWindowLong,hList,GWL_WNDPROC,Offset DummyListViewProc
Invoke SetWindowLong,hList,GWL_USERDATA,EAX
.ElseIf uMsg == WM_COMMAND
MOV EAX,wParam
MOV EDX,EAX
SHR EDX,16
AND EAX,0FFFFh
.If EDX==BN_CLICKED
PUSH EAX
Invoke GetDlgItem,hWnd,1
MOV hList,EAX
POP EAX
.If EAX==4 ;Add
MOV bResourcesModified,TRUE
Invoke SendMessage,hList,LVM_GETITEMCOUNT,0,0
MOV lvi.imask,LVIF_TEXT or LVIF_STATE
MOV lvi.cchTextMax,256
MOV lvi.iSubItem, 0
MOV lvi.iItem,EAX
MOV lvi.pszText,Offset szNULL
MOV lvi.state,LVIS_SELECTED or LVIS_FOCUSED
Invoke SendMessage,hList,LVM_INSERTITEM,0,ADDR lvi
Invoke SendMessage,hList,LVM_ENSUREVISIBLE,EAX,FALSE
Invoke SetFocus,hList
;So that Browse for file dialog is displayed automatically
Invoke SendMessage,hBrowseResourceButton,WM_LBUTTONUP,0,0
.ElseIf EAX== 5 ;Delete
Invoke SendMessage,hList,LVM_GETNEXTITEM,-1,LVNI_ALL or LVNI_SELECTED
.If EAX!=-1
MOV bResourcesModified,TRUE
MOV lvi.iItem,EAX
.If lvi.iItem
DEC lvi.iItem ;Because after deleting selection, we will select the previous one
.EndIf
Invoke SendMessage,hList,LVM_DELETEITEM,EAX,0
MOV lvi.imask,LVIF_STATE
MOV lvi.iSubItem, 0
MOV lvi.state,LVIS_SELECTED or LVIS_FOCUSED
MOV lvi.stateMask,LVIS_SELECTED
Invoke SendMessage,hList,LVM_SETITEM,0,ADDR lvi
Invoke SendMessage,hList,LVM_ENSUREVISIBLE,lvi.iItem,FALSE
Invoke SetFocus,hList
.EndIf
.ElseIf EAX==2 ;OK
.If !lpResourcesMem
Invoke HeapAlloc,hMainHeap,HEAP_ZERO_MEMORY,64*1024
MOV lpResourcesMem,EAX
MOV bResourcesModified,TRUE
.Else
MOV EDI,lpResourcesMem
;Delete all Resource defines
.While [EDI].RESOURCEMEM.szName || [EDI].RESOURCEMEM.Value
Invoke DeleteDefine,ADDR [EDI].RESOURCEMEM.szName
LEA EDI,[EDI+SizeOf RESOURCEMEM]
.EndW
Invoke RtlZeroMemory,lpResourcesMem,64*1024
.EndIf
MOV EDI,lpResourcesMem
Invoke SendMessage,hList,LVM_GETITEMCOUNT,0,0
.If EAX
MOV EBX,EAX
XOR ESI,ESI
.While ESI<EBX
Invoke GetItemText,hList,ESI,0,ADDR Buffer
Invoke GetItemText,hList,ESI,1,ADDR Buffer2
LEA ECX,Buffer
LEA EDX,Buffer2
PUSH EDX
.If BYTE PTR [ECX]!=0 && BYTE PTR [EDX]!=0
Invoke AddOrReplaceDefine,ECX,EDX
.EndIf
POP EDX
.If BYTE PTR [EDX]!=0
Invoke DecToBin,ADDR Buffer2
PUSH EAX
Invoke GetItemText,hList,ESI,2,ADDR Buffer2
POP EAX
LEA ECX,Buffer2
.If BYTE PTR [ECX]!=0
MOV [EDI].RESOURCEMEM.Value,EAX
Invoke GetItemParameter,hList,ESI
MOV [EDI].RESOURCEMEM.nType,EAX
Invoke lstrcpy,ADDR [EDI].RESOURCEMEM.szName,ADDR Buffer
Invoke lstrcpy,ADDR [EDI].RESOURCEMEM.szFile,ADDR Buffer2
LEA EDI,[EDI+SizeOf RESOURCEMEM]
.EndIf
.EndIf
INC ESI
.EndW
.EndIf
.If !hResourcesParentItem
Invoke AddToOthersTree,4,Offset szResources,EDI
MOV hResourcesParentItem,EAX
.EndIf
.If bResourcesModified
Invoke SetRCModified,TRUE
.EndIf
Invoke SendMessage,hWnd,WM_CLOSE,NULL,NULL
.ElseIf EAX== 3 ;Cancel
Invoke SendMessage,hWnd,WM_CLOSE,NULL,NULL
.EndIf
.EndIf
.ElseIf uMsg == WM_NOTIFY
MOV EDI,lParam
Invoke GetDlgItem,hWnd,1 ;ListView
MOV hList,EAX
.If [EDI].NMHDR.code==NM_DBLCLK
MOV EAX,[EDI].NMITEMACTIVATE.iItem
.If EAX!=-1
.If ([EDI].NMITEMACTIVATE.iSubItem==0 || [EDI].NMITEMACTIVATE.iSubItem==1)
Invoke ResourcesTableGiveCellFocus,hList,[EDI].NMITEMACTIVATE.iItem,[EDI].NMITEMACTIVATE.iSubItem
.Else ;[EDI].NMITEMACTIVATE.iSubItem==2 ;Simulate Browse button
Invoke PostMessage,hBrowseResourceButton,WM_LBUTTONUP,0,0
.EndIf
;.Else
;Invoke ShowWindow,hEditResourcesTable,SW_HIDE
.EndIf
.ElseIf [EDI].NMHDR.code==LVN_ITEMCHANGED || [EDI].NMHDR.code==0FFFFFFF4h
.If [EDI].NMHDR.code == LVN_ITEMCHANGED
MOV ECX,[EDI].NM_LISTVIEW.iItem
.Else
Invoke SendMessage,hList,LVM_GETNEXTITEM,-1,LVNI_ALL or LVNI_SELECTED
MOV ECX,EAX
.EndIf
.If ECX!=-1
MOV Rect.top,2
MOV Rect.left,LVIR_LABEL
Invoke SendMessage,hList,LVM_GETSUBITEMRECT,ECX,ADDR Rect
MOV ECX,Rect.bottom
SUB ECX,Rect.top
DEC ECX
MOV EAX,Rect.right
SUB EAX,ECX
Invoke SetWindowPos,hBrowseResourceButton,HWND_BOTTOM,EAX,Rect.top,ECX,ECX,SWP_SHOWWINDOW
Invoke UpdateWindow,hList
.Else
Invoke ShowWindow,hBrowseResourceButton,SW_HIDE
.EndIf
.ElseIf [EDI].NMHDR.code ==LVN_KEYDOWN
;MOV EAX,lParam
.If [EDI].LV_KEYDOWN.wVKey==VK_DELETE ;simulate delete button
Invoke SendMessage,hWnd,WM_COMMAND, (BN_CLICKED SHL 16) OR 5,0
.EndIf
.EndIf
.ElseIf uMsg == WM_CLOSE
Invoke EnableAllDockWindows,TRUE
Invoke EndDialog,hWnd,NULL
.EndIf
MOV EAX,FALSE
RET
ResourcesDialogProc EndP