-
Notifications
You must be signed in to change notification settings - Fork 3
/
RCMenus.asm
1396 lines (1242 loc) · 36.1 KB
/
RCMenus.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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
IDB_ARROWLT EQU 113
IDB_ARROWRT EQU 114
IDC_EDTMENUNAME EQU 4
IDC_EDTMENUID EQU 5
IDC_EDTSTARTID EQU 6
IDC_EDTITEMCAPTION EQU 7
IDC_EDTITEMNAME EQU 8
IDC_EDTITEMID EQU 9
IDC_BTNINSERT EQU 10
IDC_BTNDELETE EQU 11
IDC_BTNL EQU 12
IDC_BTNR EQU 13
IDC_BTNU EQU 14
IDC_BTND EQU 15
IDC_CHKCHECKED EQU 16
IDC_CHKGRAYED EQU 17
IDC_CHKDISABLED EQU 18
IDC_RBNSTRING EQU 19
IDC_RBNBITMAP EQU 20
IDC_RBNOWNERDRAW EQU 21
IDC_LSTMNU EQU 22
IDC_HOTMENU EQU 23
MenuTypeDefinition DD MFT_STRING
DB 'MFT_STRING',0
DD MFT_BITMAP
DB 'MFT_BITMAP',0
DD MFT_MENUBARBREAK
DB 'MFT_MENUBARBREAK',0
DD MFT_MENUBREAK
DB 'MFT_MENUBREAK',0
DD MFT_OWNERDRAW
DB 'MFT_OWNERDRAW',0
DD MFT_RADIOCHECK
DB 'MFT_RADIOCHECK',0
DD MFT_SEPARATOR
DB 'MFT_SEPARATOR',0
DD MFT_RIGHTORDER
DB 'MFT_RIGHTORDER',0
DD MFT_RIGHTJUSTIFY
DB 'MFT_RIGHTJUSTIFY',0
DD 0,0
MenuStateDefinition DD MFS_GRAYED
DB 'MFS_GRAYED',0
DD MFS_DISABLED
DB 'MFS_DISABLED',0
DD MFS_CHECKED
DB 'MFS_CHECKED',0
DD MFS_HILITE
DB 'MFS_HILITE',0
DD MFS_ENABLED
DB 'MFS_ENABLED',0
DD MFS_UNCHECKED
DB 'MFS_UNCHECKED',0
DD MFS_UNHILITE
DB 'MFS_UNHILITE',0
DD MFS_DEFAULT
DB 'MFS_DEFAULT',0
DD MFS_HOTTRACKDRAWN
DB 'MFS_HOTTRACKDRAWN',0
DD MFS_CACHEDBMP
DB 'MFS_CACHEDBMP',0
DD MFS_BOTTOMGAPDROP
DB 'MFS_BOTTOMGAPDROP',0
DD MFS_TOPGAPDROP
DB 'MFS_TOPGAPDROP',0
DD MFS_GAPDROP
DB 'MFS_GAPDROP',0
DD 0,0
.DATA
szIDM_ DB 'IDM_',0
szPOPUP DB 'POPUP',0
szMENUITEM DB 'MENUITEM',0
szSEPARATOR DB 'SEPARATOR',0
szCHECKED DB 'CHECKED',0
szGRAYED DB 'GRAYED',0
szINACTIVE DB 'INACTIVE',0
szMENUBARBREAK DB 'MENUBARBREAK',0
szMENUBREAK DB 'MENUBREAK',0
szShiftPlus DB 'Shift+',0
szCtrlPlus DB 'Ctrl+',0
szAltPlus DB 'Alt+',0
.CODE
;MakeMnuPopup Proc Uses EBX ESI,lpDlgMem:DWORD,nInx:DWORD
; Local hMnu[8]:DWORD
; Local buffer[512]:BYTE
; Local buffer1[32]:BYTE
;
; MOV hMnu,0
; MOV ESI,lpDlgMem
; MOV ESI,[ESI].DLGHEAD.lpmnu
; add ESI,sizeof MNUHEAD
; MOV EDX,nInx
; INC EDX
; @@:
; MOV EAX,(MNUITEM PTR [ESI]).itemflag
; .If EAX
; .If EAX!=-1
; MOV EAX,(MNUITEM PTR [ESI]).level
; .If !EAX
; DEC EDX
; .If !EDX
; Nx:
; add ESI,sizeof MNUITEM
; MOV EAX,(MNUITEM PTR [ESI]).level
; .If EAX
; DEC EAX
; lea EBX,[hMnu+EAX*4]
; MOV EAX,[EBX]
; .If !EAX
; Invoke CreatePopupMenu
; MOV [EBX],EAX
; .EndIf
; MOV AL,(MNUITEM PTR [ESI]).itemcaption
; .If AL=='-'
; Invoke AppendMenu,[EBX],MF_SEPARATOR,0,0
; .Else
; MOV buffer1,VK_TAB
; Invoke MnuSaveAccel,[ESI].MNUITEM.shortcut,addr buffer1[1]
; Invoke lstrcpy,addr buffer,addr (MNUITEM PTR [ESI]).itemcaption
; .If buffer1[1]
; Invoke lstrcat,addr buffer,addr buffer1
; .EndIf
; PUSH ESI
; CALL GetNextLevel
; POP ESI
; MOV EDX,(MNUITEM PTR [ESI]).level
; MOV ECX,(MNUITEM PTR [ESI]).nstate
; or ECX,MF_STRING
; .If EAX>EDX
; PUSH ECX
; Invoke CreatePopupMenu
; MOV [EBX+4],EAX
; POP ECX
; or ECX,MF_POPUP
; Invoke AppendMenu,[EBX],ECX,[EBX+4],addr buffer
; .ElseIf EAX==EDX
; Invoke AppendMenu,[EBX],ECX,(MNUITEM PTR [ESI]).itemid,addr buffer
; .ElseIf EAX
; Invoke AppendMenu,[EBX],ECX,(MNUITEM PTR [ESI]).itemid,addr buffer
; MOV dword PTR [EBX],0
; .Else
; Invoke AppendMenu,[EBX],ECX,(MNUITEM PTR [ESI]).itemid,addr buffer
; .EndIf
; .EndIf
; JMP Nx
; .EndIf
; .EndIf
; .EndIf
; .EndIf
; add ESI,sizeof MNUITEM
; JMP @b
; .EndIf
; MOV EAX,hMnu
; RET
;
;GetNextLevel:
; add ESI,sizeof MNUITEM
; .If [ESI].MNUITEM.itemflag==-1
; JMP GetNextLevel
; .EndIf
; MOV EAX,(MNUITEM PTR [ESI]).level
; RETN
;
;MakeMnuPopup EndP
;MakeMnuBar Proc Uses EBX ESI EDI,lpDlgMem:DWORD
; Local nInx:DWORD
; Local mii:MENUITEMINFO
;
; Invoke CreateMenu
; MOV hDlgMnu,EAX
; MOV ESI,lpDlgMem
; MOV ESI,[ESI].DLGHEAD.lpmnu
; add ESI,sizeof MNUHEAD
; MOV nInx,0
; @@:
; MOV EAX,(MNUITEM PTR [ESI]).itemflag
; .If EAX
; .If EAX!=-1
; MOV EAX,(MNUITEM PTR [ESI]).level
; .If !EAX
; MOV EDX,(MNUITEM PTR [ESI]).ntype
; AND EDX,MFT_RIGHTJUSTIFY
; or EDX,MF_STRING
; Invoke AppendMenu,hDlgMnu,EDX,(MNUITEM PTR [ESI]).itemid,addr [ESI].MNUITEM.itemcaption
; Invoke MakeMnuPopup,lpDlgMem,nInx
; .If EAX
; MOV mii.hSubMenu,EAX
; MOV mii.cbSize,sizeof MENUITEMINFO
; MOV mii.fMask,MIIM_SUBMENU
; Invoke SetMenuItemInfo,hDlgMnu,nInx,TRUE,addr mii
; .EndIf
; INC nInx
; .EndIf
; .EndIf
; add ESI,sizeof MNUITEM
; JMP @b
; .EndIf
; RET
;
;MakeMnuBar EndP
ExtractMenu Proc Uses EBX ESI EDI,lpRCMem:DWORD,lpProMem:DWORD
Local nNest :DWORD
;Local hMem :DWORD
Local Buffer[256] :BYTE
Local MaxID :DWORD
MOV MaxID,0
Invoke HeapAlloc,hMainHeap,HEAP_ZERO_MEMORY,64*1024
MOV EDI,EAX
PUSH EDI
;Name / ID
Invoke GetName,lpProMem,Offset NameBuffer,ADDR [EDI].MNUHEAD.szMenuName,ADDR [EDI].MNUHEAD.MenuID
MOV EAX,[EDI].MNUHEAD.MenuID
INC EAX
MOV MaxID,EAX
ADD EDI,SizeOf MNUHEAD
MOV nNest,0
MOV ESI,lpRCMem
Invoke GetLoadOptions,ESI
ADD ESI,EAX
@@:
;-
Invoke GetWord,Offset ThisWord,ESI
ADD ESI,EAX
MOV EBX,EAX
Invoke lstrcmpi,Offset ThisWord,Offset szCHARACTERISTICS
.If !EAX
Invoke GetNum,lpProMem
JMP @B
.EndIf
Invoke lstrcmpi,Offset ThisWord,Offset szVERSION
.If !EAX
Invoke GetNum,lpProMem
JMP @B
.EndIf
Invoke lstrcmpi,Offset ThisWord,Offset szLANGUAGE
.If !EAX
Invoke GetWord,Offset ThisWord,ESI
ADD ESI,EAX
Invoke GetWord,Offset ThisWord,ESI
ADD ESI,EAX
JMP @B
.EndIf
SUB ESI,EBX
@@:
Invoke GetWord,Offset ThisWord,ESI
ADD ESI,EAX
Invoke lstrcmpi,Offset ThisWord,Offset szBEGIN
.If EAX
Invoke lstrcmpi,Offset ThisWord,Offset szBEGINSHORT
.EndIf
.If !EAX
INC nNest
JMP @B
.EndIf
Invoke lstrcmpi,Offset ThisWord,Offset szPOPUP
.If !EAX
MOV [EDI].MNUITEM.Flag,TRUE
MOV EAX,nNest
DEC EAX
MOV [EDI].MNUITEM.Level,EAX
Invoke GetWord,Offset ThisWord,ESI
ADD ESI,EAX
Invoke UnQuoteWord,Offset ThisWord
Invoke lstrcpy,ADDR [EDI].MNUITEM.szCaption,Offset ThisWord
CALL SetOptions
ADD EDI,SizeOf MNUITEM
JMP @B
.EndIf
Invoke lstrcmpi,Offset ThisWord,Offset szMENUITEM
.If !EAX
MOV [EDI].MNUITEM.Flag,TRUE
MOV EAX,nNest
DEC EAX
MOV [EDI].MNUITEM.Level,EAX
Invoke GetWord,Offset ThisWord,ESI
ADD ESI,EAX
Invoke lstrcmpi,Offset ThisWord,Offset szSEPARATOR
.If !EAX
MOV WORD PTR [EDI].MNUITEM.szCaption,'-'
ADD EDI,SizeOf MNUITEM
JMP @B
.EndIf
; Invoke lstrcmpi,Offset ThisWord,Offset szMENUBREAK
; .If !EAX
; ;MOV WORD PTR [EDI].MNUITEM.szCaption,'|'
; ADD EDI,SizeOf MNUITEM
; JMP @B
; .EndIf
Invoke UnQuoteWord,Offset ThisWord
MOV EBX,Offset ThisWord
.While WORD PTR [EBX]!='t\' && BYTE PTR [EBX]
INC EBX
.EndW
.If WORD PTR [EBX]=='t\'
PUSH EBX
ADD EBX,2
NxtKey:
XOR EAX,EAX
.If DWORD PTR [EBX]=='fihS'
ADD EBX,6
OR [EDI].MNUITEM.Shortcut,100h
JMP NxtKey
.ElseIf DWORD PTR [EBX]=='lrtC'
ADD EBX,5
OR [EDI].MNUITEM.Shortcut,200h
JMP NxtKey
.ElseIf DWORD PTR [EBX]=='+tlA'
ADD EBX,4
OR [EDI].MNUITEM.Shortcut,400h
JMP NxtKey
.ElseIf WORD PTR [EBX]>='A' && WORD PTR [EBX]<='Z'
MOVZX EAX,BYTE PTR [EBX]
OR [EDI].MNUITEM.Shortcut,EAX
.ElseIf BYTE PTR [EBX]=='F'
Invoke DecToBin,ADDR [EBX+1]
ADD EAX,6Fh
OR [EDI].MNUITEM.Shortcut,EAX
.EndIf
POP EBX
.If EAX
MOV BYTE PTR [EBX],0
.Else
MOV [EDI].MNUITEM.Shortcut,EAX
.EndIf
.EndIf
Invoke lstrcpy,ADDR [EDI].MNUITEM.szCaption,Offset ThisWord
Invoke GetWord,Offset ThisWord,ESI
ADD ESI,EAX
;Name / ID
Invoke GetName,lpProMem,Offset ThisWord,ADDR [EDI].MNUITEM.szName,ADDR [EDI].MNUITEM.ID
MOV ECX,[EDI].MNUITEM.ID
.If ECX>=MaxID
INC ECX
MOV MaxID,ECX
.EndIf
CALL SetOptions
ADD EDI,SizeOf MNUITEM
JMP @B
.EndIf
Invoke lstrcmpi,Offset ThisWord,Offset szEND
.If EAX
Invoke lstrcmpi,Offset ThisWord,Offset szENDSHORT
.EndIf
.If !EAX
DEC nNest
JE Ex
JMP @B
.EndIf
Ex:
POP EDI
MOV EAX,MaxID
MOV [EDI].MNUHEAD.NextMenuItemID,EAX
LEA EAX,[EDI].MNUHEAD.szMenuName
.If BYTE PTR [EAX]==0
Invoke BinToDec,[EDI].MNUHEAD.MenuID,ADDR Buffer
LEA EAX,Buffer
.EndIf
Invoke AddToOthersTree,6,EAX,EDI
MOV [EDI].MNUHEAD.hTreeItem,EAX
MOV EAX,ESI
SUB EAX,lpRCMem
RET
SetOptions:
;---------
XOR EBX,EBX
.While BYTE PTR [ESI] && BYTE PTR [ESI]!=0Dh
Invoke GetWord,Offset ThisWord,ESI
ADD ESI,EAX
Invoke lstrcmpi,Offset ThisWord,Offset szCHECKED
.If !EAX
OR EBX,MFS_CHECKED
.EndIf
Invoke lstrcmpi,Offset ThisWord,Offset szGRAYED
.If !EAX
OR EBX,MFS_GRAYED
.EndIf
Invoke lstrcmpi,Offset ThisWord,Offset szINACTIVE
.If !EAX
.EndIf
Invoke lstrcmpi,Offset ThisWord,Offset szMENUBARBREAK
.If !EAX
.EndIf
Invoke lstrcmpi,Offset ThisWord,Offset szMENUBREAK
.If !EAX
MOV [EDI].MNUITEM.nType,MFT_MENUBREAK
.EndIf
.EndW
MOV [EDI].MNUITEM.nState,EBX
RETN
ExtractMenu EndP
ExtractMenuEx Proc Uses EBX ESI EDI,lpRCMem:DWORD,lpProMem:DWORD
Local nNest :DWORD
Local hMem :DWORD
Local Buffer[256] :BYTE
Local MaxID :DWORD
MOV MaxID,0
Invoke HeapAlloc,hMainHeap,HEAP_ZERO_MEMORY,64*1024
MOV EDI,EAX
PUSH EDI
;Name / ID
Invoke GetName,lpProMem,Offset NameBuffer,ADDR [EDI].MNUHEAD.szMenuName,ADDR [EDI].MNUHEAD.MenuID
MOV EAX,[EDI].MNUHEAD.MenuID
INC EAX
MOV MaxID,EAX
;PrintDec EaX
ADD EDI,SizeOf MNUHEAD
MOV nNest,0
MOV ESI,lpRCMem
Invoke GetLoadOptions,ESI
ADD ESI,EAX
@@:
;-
Invoke GetWord,Offset ThisWord,ESI
ADD ESI,EAX
MOV EBX,EAX
Invoke lstrcmpi,Offset ThisWord,Offset szCHARACTERISTICS
.If !EAX
Invoke GetNum,lpProMem
JMP @B
.EndIf
Invoke lstrcmpi,Offset ThisWord,Offset szVERSION
.If !EAX
Invoke GetNum,lpProMem
JMP @B
.EndIf
Invoke lstrcmpi,Offset ThisWord,Offset szLANGUAGE
.If !EAX
Invoke GetWord,Offset ThisWord,ESI
ADD ESI,EAX
Invoke GetWord,Offset ThisWord,ESI
ADD ESI,EAX
JMP @B
.EndIf
SUB ESI,EBX
@@:
Invoke GetWord,Offset ThisWord,ESI
ADD ESI,EAX
Invoke lstrcmpi,Offset ThisWord,Offset szBEGIN
.If EAX
Invoke lstrcmpi,Offset ThisWord,Offset szBEGINSHORT
.EndIf
.If !EAX
INC nNest
JMP @B
.EndIf
Invoke lstrcmpi,Offset ThisWord,Offset szMENUITEM
.If EAX
Invoke lstrcmpi,Offset ThisWord,Offset szPOPUP
.EndIf
.If !EAX
MOV [EDI].MNUITEM.Flag,TRUE
MOV EAX,nNest
DEC EAX
MOV [EDI].MNUITEM.Level,EAX
Invoke GetWord,Offset ThisWord,ESI
ADD ESI,EAX
Invoke UnQuoteWord,Offset ThisWord
MOV EBX,Offset ThisWord
.While WORD PTR [EBX]!='t\' && BYTE PTR [EBX]
INC EBX
.EndW
.If WORD PTR [EBX]=='t\'
PUSH EBX
ADD EBX,2
;PrintStringByAddr EBX
NxtKey:
;------
XOR EAX,EAX
.If dword PTR [EBX]=='fihS'
ADD EBX,6
OR [EDI].MNUITEM.Shortcut,100h
JMP NxtKey
.ElseIf dword PTR [EBX]=='lrtC'
ADD EBX,5
OR [EDI].MNUITEM.Shortcut,200h
JMP NxtKey
.ElseIf dword PTR [EBX]=='+tlA'
ADD EBX,4
OR [EDI].MNUITEM.Shortcut,400h
JMP NxtKey
.ElseIf (WORD PTR [EBX]>='A' && WORD PTR [EBX]<='Z')
MOVZX EAX,BYTE PTR [EBX]
OR [EDI].MNUITEM.Shortcut,EAX
;V5.0.1.6
.ElseIf BYTE PTR [EBX]=='T' && BYTE PTR [EBX+1]=='A' && BYTE PTR [EBX+2]=='B'
XOR EAX,EAX
MOV AL,VK_TAB
OR [EDI].MNUITEM.Shortcut,EAX
.ElseIf BYTE PTR [EBX]=='F'
Invoke DecToBin,ADDR [EBX+1]
ADD EAX,6Fh
OR [EDI].MNUITEM.Shortcut,EAX
.EndIf
POP EBX
.If EAX
MOV BYTE PTR [EBX],0
.Else
MOV [EDI].MNUITEM.Shortcut,EAX
.EndIf
;MOV EAX,[EDI].MNUITEM.Shortcut
;PrintHex EAX
.EndIf
Invoke lstrcpy,ADDR [EDI].MNUITEM.szCaption,Offset ThisWord
.If BYTE PTR [ESI] && BYTE PTR [ESI]!=0Dh
Invoke GetWord,Offset ThisWord,ESI
ADD ESI,EAX
;Name / ID
Invoke GetName,lpProMem,Offset ThisWord,ADDR [EDI].MNUITEM.szName,ADDR [EDI].MNUITEM.ID
MOV ECX,[EDI].MNUITEM.ID
.If ECX>=MaxID
INC ECX
MOV MaxID,ECX
.EndIf
CALL SetOptions
.EndIf
ADD EDI,SizeOf MNUITEM
JMP @B
.EndIf
Invoke lstrcmpi,Offset ThisWord,Offset szEND
.If EAX
Invoke lstrcmpi,Offset ThisWord,Offset szENDSHORT
.EndIf
.If !EAX
DEC nNest
JE Ex
JMP @B
.EndIf
Ex:
;-
POP EDI
MOV EAX,MaxID
MOV [EDI].MNUHEAD.NextMenuItemID,EAX
LEA EAX,[EDI].MNUHEAD.szMenuName
.If BYTE PTR [EAX]==0
Invoke BinToDec,[EDI].MNUHEAD.MenuID,ADDR Buffer
LEA EAX,Buffer
.EndIf
Invoke AddToOthersTree,6,EAX,EDI
MOV [EDI].MNUHEAD.hTreeItem,EAX
MOV EAX,ESI
SUB EAX,lpRCMem
RET
SetOptions:
;---------
.If BYTE PTR [ESI] && BYTE PTR [ESI]!=0Dh
;Type
Invoke GetStyle,ESI,Offset MenuTypeDefinition
.If EDX
TEST EDX,MFT_SEPARATOR
.If !ZERO?
XOR EDX,MFT_SEPARATOR
MOV WORD PTR [EDI].MNUITEM.szCaption,'-'
.EndIf
.Else ;String (NOT Numerical)
Invoke GetWord,Offset ThisWord,ESI
PUSH EAX
Invoke lstrcmpi,Offset ThisWord,Offset szSEPARATOR
.If !EAX
MOV EDX,MFT_SEPARATOR
MOV WORD PTR [EDI].MNUITEM.szCaption,'-'
.Else
Invoke lstrcmpi,Offset ThisWord,Offset szMENUBREAK
.If !EAX
MOV EDX,MFT_MENUBREAK
;MOV WORD PTR [EDI].MNUITEM.szCaption,'|'
.Else
XOR EDX,EDX
.EndIf
.EndIf
POP EAX
.EndIf
MOV [EDI].MNUITEM.nType,EDX
ADD ESI,EAX
.EndIf
.If BYTE PTR [ESI] && BYTE PTR [ESI]!=0Dh
;State
Invoke GetStyle,ESI,Offset MenuStateDefinition
MOV [EDI].MNUITEM.nState,EDX
ADD ESI,EAX
.EndIf
.If BYTE PTR [ESI] && BYTE PTR [ESI]!=0Dh
;HelpID
Invoke GetNum,lpProMem
.EndIf
RETN
ExtractMenuEx EndP
MakeMenuItemCaption Proc Uses ESI EDI lpMenuItem:DWORD, lpBuffer:DWORD
Invoke RtlZeroMemory,lpBuffer,256
MOV EDI,lpMenuItem
MOV ESI,[EDI].MNUITEM.Level
.If ESI
Invoke lstrcpy,lpBuffer,Offset szThreeDots
DEC ESI
@@:
.If ESI
Invoke lstrcat,lpBuffer,Offset szThreeDots
DEC ESI
JMP @B
.EndIf
.EndIf
Invoke lstrcat,lpBuffer,ADDR [EDI].MNUITEM.szCaption
RET
MakeMenuItemCaption EndP
SaveString Proc Uses ECX ESI EDI,lpDest:DWORD,lpSrc:DWORD
MOV ESI,lpSrc
MOV EDI,lpDest
DEC ESI
DEC EDI
MOV ECX,-1
@@:
INC ECX
INC ESI
INC EDI
MOV AL,[ESI]
MOV [EDI],AL
OR AL,AL
JNE @B
MOV EAX,ECX
RET
SaveString EndP
GetStringFromAccel Proc Uses ESI EDI,nAccel:DWORD,lpDest:DWORD
MOV ESI,nAccel
MOV EDI,lpDest
TEST ESI,200h
.If !ZERO?
Invoke SaveString,EDI,Offset szCtrlPlus
ADD EDI,EAX
.EndIf
TEST ESI,100h
.If !ZERO?
Invoke SaveString,EDI,Offset szShiftPlus
ADD EDI,EAX
.EndIf
TEST ESI,400h
.If !ZERO?
Invoke SaveString,EDI,Offset szAltPlus
ADD EDI,EAX
.EndIf
; SHR ESI,9
; .If CARRY?
; Invoke SaveString,EDI,Offset szShiftPlus
; ADD EDI,EAX
; .EndIf
; SHR ESI,1
; .If CARRY?
; Invoke SaveString,EDI,Offset szCtrlPlus
; ADD EDI,EAX
; .EndIf
; SHR ESI,1
; .If CARRY?
; Invoke SaveString,EDI,Offset szAltPlus
; ADD EDI,EAX
; .EndIf
; PrintHex nAccel
MOV EAX,nAccel
MOVZX EAX,AL
.If EAX==VK_TAB
MOV BYTE PTR [EDI],'T'
MOV BYTE PTR [EDI+1],'A'
MOV BYTE PTR [EDI+2],'B'
ADD EDI,3
.ElseIf EAX>='A' && EAX<='Z'
STOSB
.ElseIf EAX>=VK_F1 && EAX<=VK_F12
MOV BYTE PTR [EDI],'F'
INC EDI
SUB EAX,VK_F1-1
Invoke BinToDec,EAX,EDI
Invoke lstrlen,EDI
LEA EDI,[EDI+EAX]
.EndIf
; .If EAX>=VK_F1 && EAX<=VK_F12
; MOV BYTE PTR [EDI],'F'
; INC EDI
; SUB EAX,VK_F1-1
; Invoke BinToDec,EAX,EDI
; Invoke lstrlen,EDI
; LEA EDI,[EDI+EAX]
; .Else
; STOSB
; .EndIf
MOV BYTE PTR [EDI],0
MOV EAX,EDI
SUB EAX,lpDest
RET
GetStringFromAccel EndP
SetColumnsWidth Proc hList:DWORD
Local Rect :RECT
Invoke SendMessage, hList, LVM_SETCOLUMNWIDTH, 1, LVSCW_AUTOSIZE
Invoke SendMessage, hList, LVM_GETCOLUMNWIDTH, 1, 0
PUSH EAX
Invoke GetWindowRect,hList,ADDR Rect
Invoke GetSystemMetrics,SM_CXBORDER
MOV EDX,EAX
SHL EDX,1 ;Twice
PUSH EDX
Invoke GetWindowLong,hList,GWL_STYLE
AND EAX,WS_VSCROLL
.If EAX ;i.e. If VSCROLL is present, take its width into account
Invoke GetSystemMetrics,SM_CXVSCROLL
.Else
XOR EAX,EAX
.EndIf
POP EDX
ADD EDX,EAX
ADD EDX,4 ;Emperical
MOV ECX,Rect.right
SUB ECX,Rect.left
POP EAX
SUB ECX,EAX
SUB ECX,EDX
Invoke SendMessage, hList, LVM_SETCOLUMNWIDTH, 0, ECX
RET
SetColumnsWidth EndP
InsertNewMenuItem Proc Uses EDI EBX hList:DWORD, lpItem:DWORD, iItem:DWORD
Local lvi :LVITEM
Local Buffer[256] :BYTE
MOV EDI,lpItem
MOV [EDI].MNUITEM.Flag,TRUE
MOV EBX,iItem
MOV lvi.imask,LVIF_TEXT OR LVIF_PARAM; OR LVIF_STATE
MOV lvi.cchTextMax,256
Invoke MakeMenuItemCaption,EDI,ADDR Buffer
MOV lvi.lParam,EDI
MOV lvi.iSubItem,0
MOV lvi.iItem,EBX
LEA EAX,Buffer
MOV lvi.pszText,EAX
Invoke SendMessage,hList,LVM_INSERTITEM,0,ADDR lvi
Invoke GetStringFromAccel,[EDI].MNUITEM.Shortcut,ADDR Buffer
Invoke SetItemText,hList,EBX,1,ADDR Buffer
RET
InsertNewMenuItem EndP
DeleteMenuDefines Proc Uses EDI lpMenuData:DWORD
MOV EDI,lpMenuData
Invoke DeleteDefine,ADDR [EDI].MNUHEAD.szMenuName
ADD EDI,SizeOf MNUHEAD
.While [EDI].MNUITEM.Flag
Invoke DeleteDefine,ADDR [EDI].MNUITEM.szName
ADD EDI,SizeOf MNUITEM
.EndW
RET
DeleteMenuDefines EndP
MenuEditDialogProc Proc Uses EBX EDI ESI hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
Local Buffer[256] :BYTE
Local tvi :TVITEM
Local lvc :LV_COLUMN
Local hList :DWORD
Local MaxID :DWORD
.If uMsg == WM_INITDIALOG
Invoke SendDlgItemMessage,hWnd,IDC_EDTMENUNAME,EM_LIMITTEXT,31,0
Invoke SendDlgItemMessage,hWnd,IDC_EDTITEMCAPTION,EM_LIMITTEXT,31,0
Invoke SendDlgItemMessage,hWnd,IDC_EDTITEMNAME,EM_LIMITTEXT,31,0
Invoke LoadImage,hInstance,IDB_ARROWUP,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE + LR_LOADMAP3DCOLORS
MOV hArrowUp,EAX
Invoke SendDlgItemMessage,hWnd,IDC_BTNU,BM_SETIMAGE,IMAGE_BITMAP,EAX
Invoke LoadImage,hInstance,IDB_ARROWDN,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE + LR_LOADMAP3DCOLORS
MOV hArrowUp,EAX
Invoke SendDlgItemMessage,hWnd,IDC_BTND,BM_SETIMAGE,IMAGE_BITMAP,EAX
Invoke LoadImage,hInstance,IDB_ARROWLT,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE + LR_LOADMAP3DCOLORS
MOV hArrowLt,EAX
Invoke SendDlgItemMessage,hWnd,IDC_BTNL,BM_SETIMAGE,IMAGE_BITMAP,EAX
Invoke LoadImage,hInstance,IDB_ARROWRT,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE + LR_LOADMAP3DCOLORS
MOV hArrowRt,EAX
Invoke SendDlgItemMessage,hWnd,IDC_BTNR,BM_SETIMAGE,IMAGE_BITMAP,EAX
.If lParam ;Existing Menu
;MOV EDI,lParam
;Let's allocate some temporary memory
Invoke HeapAlloc,hMainHeap,HEAP_ZERO_MEMORY,64*1024
MOV EDI,EAX
;Let's copy from Real Menu memory to temporary
Invoke RtlMoveMemory,EDI, lParam,64*1024
Invoke SetWindowLong,hWnd,GWL_USERDATA,EDI
MOV EDX,Offset szMenu
.Else ;New Menu
Invoke HeapAlloc,hMainHeap,HEAP_ZERO_MEMORY,64*1024
MOV EDI,EAX
Invoke SetWindowLong,hWnd,GWL_USERDATA,EDI
Invoke lstrcpy,ADDR [EDI].MNUHEAD.szMenuName,CTEXT("IDM_MNU")
MOV [EDI].MNUHEAD.MenuID,1000
MOV [EDI].MNUHEAD.NextMenuItemID,1001
MOV EDX,Offset szNewMenu
.EndIf
Invoke SetWindowText,hWnd,EDX
PUSH EDI
Invoke GetDlgItem,hWnd,IDC_LSTMNU
MOV ESI,EAX
Invoke SendMessage,ESI,LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT
MOV lvc.imask,LVCF_WIDTH OR LVCF_FMT
MOV lvc.fmt,LVCFMT_LEFT
MOV lvc.cchTextMax,MAX_PATH
MOV lvc.lx,180
Invoke SendMessage, ESI, LVM_INSERTCOLUMN, 0, ADDR lvc
MOV lvc.fmt,LVCFMT_RIGHT
MOV lvc.lx,80
Invoke SendMessage, ESI, LVM_INSERTCOLUMN, 1, ADDR lvc
Invoke SetDlgItemText,hWnd,IDC_EDTMENUNAME,ADDR [EDI].MNUHEAD.szMenuName
Invoke BinToDec,[EDI].MNUHEAD.MenuID,ADDR Buffer
Invoke SetDlgItemText,hWnd,IDC_EDTMENUID,ADDR Buffer
;Invoke BinToDec,[EDI].MNUHEAD.StartID,ADDR Buffer
;Invoke SetDlgItemText,hWnd,IDC_EDTSTARTID,ADDR Buffer
ADD EDI,SizeOf MNUHEAD
XOR EBX,EBX
.While [EDI].MNUITEM.Flag
Invoke InsertNewMenuItem,ESI,EDI,EBX
ADD EDI,SizeOf MNUITEM
INC EBX
.EndW
Invoke lstrcpy,ADDR [EDI].MNUITEM.szName,Offset szIDM_
POP EAX
MOV ECX,[EAX].MNUHEAD.NextMenuItemID
MOV [EDI].MNUITEM.ID,ECX
INC [EAX].MNUHEAD.NextMenuItemID
Invoke InsertNewMenuItem,ESI,EDI,EBX
Invoke SetColumnsWidth,ESI
Invoke SelectListItem,ESI,0
.ElseIf uMsg == WM_COMMAND
MOV EAX,wParam
MOV EDX,EAX
SHR EDX,16
AND EAX,0FFFFh
.If EDX==BN_CLICKED
.If EAX==2 ;OK
MOV MaxID,0
Invoke GetDlgItem,hWnd,IDC_LSTMNU
MOV hList,EAX
;Let's make some checks
;a)Check menu item levels
Invoke SendMessage,hList,LVM_GETITEMCOUNT,0,0
MOV EBX,EAX
XOR ESI,ESI
.While TRUE
.If ESI==EBX
.Break
.EndIf
Invoke GetItemParameter,hList,ESI;,0
MOV EDX,EAX
.If ESI==0 ;i.e this is the first menu item
.If [EDX].MNUITEM.Level!=0
MOV ESI,-1
JMP MenuItemLevelError
.EndIf
.EndIf
MOV ECX,[EDX].MNUITEM.Level
INC ECX
.If [EDX+SizeOf MNUITEM].MNUITEM.Level>ECX
JMP MenuItemLevelError
.EndIf
ADD EDI,SizeOf MNUITEM
INC ESI
.EndW
;End Of Tests
;Let's delete all definitions related to this menu if it is NOT a new menu
Invoke GetWindowText,hWnd,ADDR Buffer,256
Invoke lstrcmp,ADDR Buffer,Offset szNewMenu
.If EAX ;i.e. This is NOT a new menu
Invoke SendMessage, hOthersTree, TVM_GETNEXTITEM,TVGN_CARET,0
Invoke GetTreeItemParameter,hOthersTree,EAX
Invoke DeleteMenuDefines,EAX
.EndIf
;New Memory (The third one)
Invoke HeapAlloc,hMainHeap,HEAP_ZERO_MEMORY,64*1024
MOV EDI,EAX
;Get The Second temp memory (The one we used so far)
Invoke GetWindowLong,hWnd,GWL_USERDATA
Invoke RtlMoveMemory,EDI,EAX,SizeOf MNUHEAD
Invoke GetDlgItemText,hWnd,IDC_EDTMENUNAME,ADDR [EDI].MNUHEAD.szMenuName,32
Invoke GetDlgItemText,hWnd,IDC_EDTMENUID,ADDR Buffer,256
.If Buffer[0]!="0" ;Points to a null-terminated string that contains the name of the menu resource
;LoadMenu,hInstance,lpMenuName
;lpMenuName:Points to a null-terminated string that contains the ****NAME**** of the menu resource. Alternatively, this parameter can consist of the resource identifier in the low-order word and zero in the high-order word. To create this value, use the MAKEINTRESOURCE macro.
;Therefore if it is '0' #define should not exist in the script
Invoke AddOrReplaceDefine,ADDR [EDI].MNUHEAD.szMenuName,ADDR Buffer
.EndIf
Invoke DecToBin,ADDR Buffer
MOV [EDI].MNUHEAD.MenuID,EAX
INC EAX
MOV MaxID,EAX
Invoke GetWindowText,hWnd,ADDR Buffer,256
Invoke lstrcmp,ADDR Buffer,Offset szNewMenu
.If !EAX ;i.e. This is a new menu
LEA EBX,[EDI].MNUHEAD.szMenuName
.If BYTE PTR [EBX]==0
Invoke BinToDec,[EDI].MNUHEAD.MenuID,ADDR Buffer
LEA EBX,Buffer
.EndIf
Invoke AddToOthersTree,6,EBX,EDI
MOV [EDI].MNUHEAD.hTreeItem,EAX
.Else
MOV tvi._mask,TVIF_TEXT
MOV tvi.cchTextMax,256
LEA EBX,[EDI].MNUHEAD.szMenuName
.If BYTE PTR [EBX]==0
Invoke BinToDec,[EDI].MNUHEAD.MenuID,ADDR Buffer
LEA EBX,Buffer
.EndIf
MOV tvi.pszText,EBX