forked from OpenKotOR/mdledit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframe.cpp
More file actions
1184 lines (1090 loc) · 54.5 KB
/
Copy pathframe.cpp
File metadata and controls
1184 lines (1090 loc) · 54.5 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
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
#include "frame.h"
//#include "edits.h"
#include <windowsx.h>
#include <shlwapi.h>
#include "MDL.h"
char Frame::cClassName[] = "mdleditframe";
HINSTANCE Frame::hInstance = NULL;
HWND hFrame;
Edits Edit1;
HWND hTree;
HWND hStatusBar;
HWND hDisplayEdit;
HWND hTabs;
HWND hGame, hPlatform, hNeck;
MDL Model;
ReportObject ReportModel(Model);
bool bSaveReport = false;
bool bShowHex = false;
bool bShowDiff = true;
bool bShowGroup = false;
bool bShowDataStruct = false;
bool bHexLocation = false;
bool bAnalyze = false;
bool bModelHierarchy = false;
unsigned nEditSize = ME_DISPLAY_SIZE_Y;
const int nCompactOffsetTop = 1;
const int nCompactOffsetBottom = 1;
const int nCompactOffsetLeft = 1;
const int nCompactOffsetRight = 1;
std::wstring sExePath;
Version version (1,0,5, true);
WNDPROC MainTreeProc = NULL;
WNDPROC MainDisplayProc = NULL;
LRESULT APIENTRY TreeSubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT APIENTRY DisplaySubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
bool bEditDrag = false;
HHOOK hMessageHook = NULL;
namespace {
constexpr int WINDOW_NONHEX_WIDTH = 368;
constexpr int WINDOW_NONHEX_HEIGHT = 610;
constexpr int WINDOW_HEX_WIDTH = 980;
constexpr int WINDOW_HEX_HEIGHT = 610;
}
HFONT hMonospace = NULL, hShell = NULL, hTimes = NULL;
void FixHead(){
bool bLinkHead = Button_GetCheck(hNeck) == BST_CHECKED;
if(bLinkHead){
if(Model.LinkHead(bLinkHead)){
Edit1.UpdateEdit();
HTREEITEM hSel = TreeView_GetSelection(hTree);
if(hSel != NULL) ProcessTreeAction(hSel, ACTION_UPDATE_DISPLAY);
}
else std::cout << "neck_g was not found!\n";
}
}
Frame::Frame(HINSTANCE hInstanceCreate){
hInstance = hInstanceCreate; // Save Instance handle
/// Save executable path
DWORD nExePathSize = MAX_PATH;
for(;;){
sExePath.assign(nExePathSize, L'\0');
DWORD nChars = GetModuleFileNameW(hInstance, &sExePath.front(), nExePathSize);
if(nChars == 0){
sExePath.clear();
break;
}
if(nChars < nExePathSize - 1){
sExePath.resize(nChars);
break;
}
if(nExePathSize > 32768){
sExePath.resize(nChars);
break;
}
nExePathSize *= 2;
}
std::cout << "Running " << to_ansi(sExePath) << "\n";
// #1 Basics
WindowClass.cbSize = sizeof(WNDCLASSEX); // Must always be sizeof(WNDCLASSEX)
WindowClass.lpszClassName = cClassName; // Name of this class
WindowClass.hInstance = hInstance; // Instance of the application
WindowClass.lpfnWndProc = FrameProc; // Pointer to callback procedure
// #2 Class styles
WindowClass.style = CS_DBLCLKS; // Class styles
// #3 Background
WindowClass.hbrBackground = CreateSolidBrush(RGB(250, 250, 250)); //(HBRUSH) (COLOR_WINDOW); // Background brush
// #4 Cursor
WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW); // Class cursor
// #5 Icon
WindowClass.hIcon = /* */ LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON)); // /**/ LoadIcon (NULL, IDI_APPLICATION); //LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); // Class Icon
WindowClass.hIconSm = /* */ LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON2)); // /**/ LoadIcon(NULL, IDI_APPLICATION); //LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); // Small icon for this class
// #6 Menu
WindowClass.lpszMenuName = MAKEINTRESOURCE(IDM_MAIN); // Menu Resource
// #7 Other
WindowClass.cbClsExtra = 0; // Extra bytes to allocate following the wndclassex structure
WindowClass.cbWndExtra = 0; // Extra bytes to allocate following an instance of the structure
}
bool Frame::Run(int nCmdShow){
if(!RegisterClassEx(&WindowClass)) return false;
// Legacy common-control initialization alternatives retained for reference.
#if 0
INITCOMMONCONTROLSEX icc;
icc.dwSize = sizeof(icc);
icc.dwICC = ICC_BAR_CLASSES; // ICC_WIN95_CLASSES;
InitCommonControlsEx(&icc);
INITCOMMONCONTROLSEX icx;
icx.dwSize = sizeof(INITCOMMONCONTROLSEX);
icx.dwICC = ICC_BAR_CLASSES; // Specify BAR classes
InitCommonControlsEx(&icx); // Load the common control DLL
#endif
hFrame = CreateWindowEx(0, cClassName, std::string("MDLedit "+version.Print()).c_str(), WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_NONHEX_WIDTH, WINDOW_NONHEX_HEIGHT,
HWND_DESKTOP, nullptr, hInstance, nullptr);
hMe = hFrame;
if(!hMe) return false;
ShowWindow(hMe, nCmdShow);
return true;
}
LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam) {
if(nCode < 0) return CallNextHookEx(nullptr, nCode, wParam, lParam);
MSG & msg = * (MSG*) lParam;
POINT pt = msg.pt;
ScreenToClient(msg.hwnd, &pt);
RECT rcClient;
GetClientRect(msg.hwnd, &rcClient);
if(msg.hwnd == hTree){
if(pt.y < 5){
msg.hwnd = hFrame;
ScreenToClient(hFrame, &pt);
msg.lParam = MAKELPARAM((WORD) pt.x, (WORD) pt.y);
}
}
else if(msg.hwnd == hDisplayEdit){
if(rcClient.bottom - rcClient.top - pt.y < 5){
msg.hwnd = hFrame;
ScreenToClient(hFrame, &pt);
msg.lParam = MAKELPARAM((WORD) pt.x, (WORD) pt.y);
}
}
return CallNextHookEx(nullptr, nCode, wParam, lParam);
}
LRESULT CALLBACK Frame::FrameProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
static RECT rcClient;
//static char cFile[MAX_PATH];
static std::wstring sFile = std::wstring(1, '\0');
/* handle the messages */
static HWND hIntLabel;
static HWND hUIntLabel;
static HWND hFloatLabel;
switch(message){
case WM_CREATE:
{
GetClientRect(hwnd, &rcClient);
std::string sMonospace = "Consolas";
if(!Font_IsInstalled(sMonospace)){
std::cout << "Consolas font not installed! Switching to Courier New...\n";
sMonospace = "Courier New";
if(!Font_IsInstalled(sMonospace)){
std::cout << "Courier New font not installed! No further alternatives!\n";
}
}
hMonospace = CreateFont(
14, //Size
0, //??
0, //??
0, //??
FW_REGULAR, // font weight
FALSE, // italic attribute flag
FALSE, // underline attribute flag
FALSE, // strikeout attribute flag
DEFAULT_CHARSET, // character set identifier
OUT_DEFAULT_PRECIS , // output precision
CLIP_DEFAULT_PRECIS , // clipping precision
DEFAULT_QUALITY , // output quality
DEFAULT_PITCH | FF_MODERN , // pitch and family
sMonospace.c_str() // pointer to typeface name string
);
hShell = CreateFont(
14, //Height
0, //Width
0, //??
0, //??
FW_REGULAR, // font weight
FALSE, // italic attribute flag
FALSE, // underline attribute flag
FALSE, // strikeout attribute flag
DEFAULT_CHARSET, // character set identifier
OUT_DEFAULT_PRECIS , // output precision
CLIP_DEFAULT_PRECIS , // clipping precision
DEFAULT_QUALITY , // output quality
DEFAULT_PITCH | FF_DONTCARE , // pitch and family
"MS Shell Dlg" //"Segoe UI" // pointer to typeface name string
);
hTimes = CreateFont(
14, //Height
4, //Width
0, //??
0, //??
FW_REGULAR, // font weight
FALSE, // italic attribute flag
FALSE, // underline attribute flag
FALSE, // strikeout attribute flag
DEFAULT_CHARSET, // character set identifier
OUT_DEFAULT_PRECIS , // output precision
CLIP_DEFAULT_PRECIS , // clipping precision
DEFAULT_QUALITY , // output quality
DEFAULT_PITCH | FF_DONTCARE , // pitch and family
"Times New Roman" //"Segoe UI" //"MS Shell Dlg" // // pointer to typeface name string
);
int nLabelOffsetX = ME_HEX_WIN_OFFSET_X + ME_HEX_WIN_SIZE_X + ME_DATA_LABEL_OFFSET_X;
int nEditOffsetX = ME_HEX_WIN_OFFSET_X + ME_HEX_WIN_SIZE_X + ME_DATA_LABEL_OFFSET_X + ME_DATA_LABEL_SIZE_X + ME_DATA_EDIT_OFFSET_X;
int nDataOffsetY [5];
for(int n = 0; n < 5; n++) nDataOffsetY[n] = ME_BASIC_OFFSET_Y + n * ME_DATA_NEXT_ROW;
hIntLabel = CreateWindowEx(0, "STATIC", "Int:", WS_VISIBLE | WS_CHILD | SS_RIGHT,
nLabelOffsetX, nDataOffsetY[0] + ME_DATA_LABEL_ROW_OFFSET_Y, ME_DATA_LABEL_SIZE_X, ME_DATA_LABEL_SIZE_Y,
hwnd, (HMENU) IDC_LBL_INT, GetModuleHandle(nullptr), nullptr);
hUIntLabel = CreateWindowEx(0, "STATIC", "uInt:", WS_VISIBLE | WS_CHILD | SS_RIGHT,
nLabelOffsetX, nDataOffsetY[1] + ME_DATA_LABEL_ROW_OFFSET_Y, ME_DATA_LABEL_SIZE_X, ME_DATA_LABEL_SIZE_Y,
hwnd, (HMENU) IDC_LBL_UINT, GetModuleHandle(nullptr), nullptr);
hFloatLabel = CreateWindowEx(0, "STATIC", "Float:", WS_VISIBLE | WS_CHILD | SS_RIGHT,
nLabelOffsetX, nDataOffsetY[2] + ME_DATA_LABEL_ROW_OFFSET_Y, ME_DATA_LABEL_SIZE_X, ME_DATA_LABEL_SIZE_Y,
hwnd, (HMENU) IDC_LBL_FLOAT, GetModuleHandle(nullptr), nullptr);
SendMessage(hIntLabel, WM_SETFONT, (WPARAM) hShell, MAKELPARAM(TRUE, 0));
SendMessage(hUIntLabel, WM_SETFONT, (WPARAM) hShell, MAKELPARAM(TRUE, 0));
SendMessage(hFloatLabel, WM_SETFONT, (WPARAM) hShell, MAKELPARAM(TRUE, 0));
ShowWindow(hIntLabel, false);
ShowWindow(hUIntLabel, false);
ShowWindow(hFloatLabel, false);
Edits::hIntEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_VISIBLE | WS_CHILD | ES_READONLY, // | ES_RIGHT,
nEditOffsetX, nDataOffsetY[0], ME_DATA_EDIT_SIZE_X, ME_DATA_EDIT_SIZE_Y,
hwnd, (HMENU) IDC_EDIT_INT, GetModuleHandle(nullptr), nullptr);
Edits::hUIntEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_VISIBLE | WS_CHILD | ES_READONLY, // | ES_RIGHT,
nEditOffsetX, nDataOffsetY[1], ME_DATA_EDIT_SIZE_X, ME_DATA_EDIT_SIZE_Y,
hwnd, (HMENU) IDC_EDIT_UINT, GetModuleHandle(nullptr), nullptr);
Edits::hFloatEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_VISIBLE | WS_CHILD | ES_READONLY, // | ES_RIGHT,
nEditOffsetX, nDataOffsetY[2], ME_DATA_EDIT_SIZE_X, ME_DATA_EDIT_SIZE_Y,
hwnd, (HMENU) IDC_EDIT_FLOAT, GetModuleHandle(nullptr), nullptr);
SendMessage(Edits::hIntEdit, WM_SETFONT, (WPARAM) hMonospace, MAKELPARAM(TRUE, 0));
SendMessage(Edits::hUIntEdit, WM_SETFONT, (WPARAM) hMonospace, MAKELPARAM(TRUE, 0));
SendMessage(Edits::hFloatEdit, WM_SETFONT, (WPARAM) hMonospace, MAKELPARAM(TRUE, 0));
ShowWindow(Edits::hIntEdit, false);
ShowWindow(Edits::hUIntEdit, false);
ShowWindow(Edits::hFloatEdit, false);
int nButtonOffsetX [3];
int nButtonSizeX = (rcClient.right - rcClient.left - ME_TREE_OFFSET_X - 5 - 10) / 3;
for(int n = 0; n < 3; n++) nButtonOffsetX[n] = ME_TREE_OFFSET_X + n * (nButtonSizeX + 5);
hGame = CreateWindowEx(0, "BUTTON", "Game", WS_VISIBLE | WS_CHILD,
nButtonOffsetX[0], nDataOffsetY[3], nButtonSizeX, ME_DATA_EDIT_SIZE_Y,
hwnd, (HMENU) IDC_BTN_GAME, GetModuleHandle(nullptr), nullptr);
hPlatform = CreateWindowEx(0, "BUTTON", "Platform", WS_VISIBLE | WS_CHILD,
nButtonOffsetX[1], nDataOffsetY[3], nButtonSizeX, ME_DATA_EDIT_SIZE_Y,
hwnd, (HMENU) IDC_BTN_PLATFORM, GetModuleHandle(nullptr), nullptr);
hNeck = CreateWindowEx(0, "BUTTON", "Head Link", WS_VISIBLE | WS_CHILD | BS_CHECKBOX | BS_PUSHLIKE | WS_DISABLED,
nButtonOffsetX[2], nDataOffsetY[3], nButtonSizeX, ME_DATA_EDIT_SIZE_Y,
hwnd, (HMENU) IDC_BTN_NECK, GetModuleHandle(nullptr), nullptr);
SendMessage(hGame, WM_SETFONT, (WPARAM) hTimes, MAKELPARAM(TRUE, 0));
SendMessage(hPlatform, WM_SETFONT, (WPARAM) hTimes, MAKELPARAM(TRUE, 0));
SendMessage(hNeck, WM_SETFONT, (WPARAM) hTimes, MAKELPARAM(TRUE, 0));
hStatusBar = CreateStatusWindow(WS_CHILD | WS_VISIBLE, "", hwnd, IDC_STATUSBAR);
int nBorders [4];
nBorders[0] = ME_STATUSBAR_PART_X;
nBorders[1] = 2 * ME_STATUSBAR_PART_X;
nBorders[2] = 3 * ME_STATUSBAR_PART_X;
nBorders[3] = -1;
SendMessage(hStatusBar, SB_SETPARTS, (WPARAM) 4, (LPARAM) nBorders);
ShowWindow(hStatusBar, false);
hTree = CreateWindowEx(WS_EX_TOPMOST, WC_TREEVIEW, "Structure", WS_CHILD | WS_VISIBLE | WS_BORDER | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_SHOWSELALWAYS,
ME_TREE_OFFSET_X, ME_DISPLAY_OFFSET_Y + nEditSize + 1, ME_TREE_SIZE_X, rcClient.bottom - ME_DISPLAY_OFFSET_Y - 1 - nEditSize - ME_STATUSBAR_Y - ME_TREE_SIZE_DIFF_Y,//rcClient.bottom - ME_TREE_OFFSET_Y - ME_STATUSBAR_Y - ME_TREE_SIZE_DIFF_Y,
hwnd, (HMENU) IDC_TREEVIEW, GetModuleHandle(nullptr), nullptr);
hDisplayEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_VISIBLE | WS_CHILD | ES_READONLY | ES_AUTOVSCROLL | ES_MULTILINE | WS_VSCROLL,
ME_TREE_OFFSET_X, nDataOffsetY[4], ME_TREE_SIZE_X, nEditSize,
hwnd, (HMENU) IDC_EDIT_DISPLAY, GetModuleHandle(nullptr), nullptr);
SendMessage(hDisplayEdit, WM_SETFONT, (WPARAM) hMonospace, MAKELPARAM(TRUE, 0));
//MainTreeProc = (WNDPROC) SetWindowLong(hTree, GWLP_WNDPROC, (LONG) TreeSubclassProc);
//MainDisplayProc = (WNDPROC) SetWindowLong(hDisplayEdit, GWLP_WNDPROC, (LONG) DisplaySubclassProc);
hTabs = CreateWindowEx(0, WC_TABCONTROL, "", WS_VISIBLE | WS_CHILD | TCS_FOCUSNEVER | TCS_FIXEDWIDTH,
ME_HEX_WIN_OFFSET_X, 0, ME_HEX_WIN_OFFSET_X + ME_TABS_SIZE_X, rcClient.bottom - ME_STATUSBAR_Y,
hwnd, (HMENU) IDC_TABS, GetModuleHandle(nullptr), nullptr);
SendMessage(hTabs, WM_SETFONT, (WPARAM) hTimes, MAKELPARAM(TRUE, 0));
ShowWindow(hTabs, false);
if(!Edit1.Run(hwnd, IDC_MAIN_EDIT)){
std::cout << "Major error, creation of Edit1 window failed.\n";
}
//hMessageHook = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, NULL, GetCurrentThreadId());
ManageIni(INI_READ);
std::string sUpdate;
if(Model.bK2) sUpdate = "KOTOR2";
else sUpdate = "KOTOR1";
SetWindowText(hGame, sUpdate.c_str());
if(Model.bXbox) sUpdate = "XBOX";
else sUpdate = "PC";
SetWindowText(hPlatform, sUpdate.c_str());
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STATE;
if(bShowGroup) mii.fState = MFS_CHECKED;
else mii.fState = MFS_UNCHECKED;
SetMenuItemInfo(GetMenu(hwnd), IDM_SHOW_GROUP, false, &mii);
if(bShowDataStruct) mii.fState = MFS_CHECKED;
else mii.fState = MFS_UNCHECKED;
SetMenuItemInfo(GetMenu(hwnd), IDM_SHOW_DATASTRUCT, false, &mii);
if(bModelHierarchy) mii.fState = MFS_CHECKED;
else mii.fState = MFS_UNCHECKED;
SetMenuItemInfo(GetMenu(hwnd), IDM_TREE_SORT_HIE, false, &mii);
if(!bModelHierarchy) mii.fState = MFS_CHECKED;
else mii.fState = MFS_UNCHECKED;
SetMenuItemInfo(GetMenu(hwnd), IDM_TREE_SORT_LIN, false, &mii);
if(!bAnalyze) RemoveMenu(GetMenu(hwnd), IDM_MASS_ANALYZE, MF_BYCOMMAND);
}
break;
case WM_NOTIFY:
{
NMHDR * nmhdr = (NMHDR *) lParam;
int nID = nmhdr->idFrom;
UINT nNotification = nmhdr->code;
switch(nID){
case IDC_TREEVIEW:
{
if(nNotification == TVN_SELCHANGED){
NMTREEVIEW * nmtv = (NMTREEVIEW *) nmhdr;
ProcessTreeAction(nmtv->itemNew.hItem, ACTION_UPDATE_DISPLAY);
}
else if(nNotification == NM_RCLICK){
POINT pt;
GetCursorPos(&pt);
RECT rcItem;
HTREEITEM hSel = NULL;
HTREEITEM hSearch = TreeView_GetFirstVisible(hTree);
while(hSearch != NULL){
TreeView_GetItemRect(hTree, hSearch, &rcItem, true);
MapWindowPoints(hTree, HWND_DESKTOP, (LPPOINT) &rcItem, 2);
//std::cout << string_format("Point: (%i, %i), Rect: (%i, %i, %i, %i)\n", pt.x, pt.y, rcItem.left, rcItem.top, rcItem.right, rcItem.bottom);
if(PtInRect(&rcItem, pt)){
hSel = hSearch;
hSearch = NULL;
}
else{
hSearch = TreeView_GetNextVisible(hTree, hSearch);
}
}
if(hSel != NULL){
TreeView_SelectItem(hTree, hSel);
MenuLineAdder mla;
mla.hMenu = CreatePopupMenu();
mla.nIndex = 0;
ProcessTreeAction(hSel, ACTION_ADD_MENU_LINES, (void*) &mla);
bool bExpanded = (TreeView_GetItemState(hTree, hSel, TVIS_EXPANDED) & TVIS_EXPANDED);
bool bHasChild = (TreeView_GetChild(hTree, hSel) != NULL);
bool bExpandedChild = false;
bool bChildHasChild = false;
HTREEITEM hChild = TreeView_GetChild(hTree, hSel);
while(hChild != NULL && !bExpandedChild && bExpanded && bHasChild){
if(TreeView_GetChild(hTree, hChild) != NULL){
bChildHasChild = true;
}
if(TreeView_GetItemState(hTree, hChild, TVIS_EXPANDED) & TVIS_EXPANDED){
bExpandedChild = true;
}
else hChild = TreeView_GetNextSibling(hTree, hChild);
}
if(bHasChild && !bExpanded){
InsertMenu(mla.hMenu, mla.nIndex, MF_BYPOSITION | MF_STRING, IDPM_TV_EXPAND, "Expand");
mla.nIndex++;
}
else if(bHasChild){
InsertMenu(mla.hMenu, mla.nIndex, MF_BYPOSITION | MF_STRING, IDPM_TV_FOLD, "Collapse");
mla.nIndex++;
}
else if(mla.nIndex == 0){
InsertMenu(mla.hMenu, mla.nIndex, MF_BYPOSITION | MF_STRING, 0, "Nothing");
mla.nIndex++;
}
if(bHasChild){
InsertMenu(mla.hMenu, mla.nIndex, MF_BYPOSITION | MF_STRING, IDPM_TV_EXPAND_ALL, "Expand all");
mla.nIndex++;
if(bExpanded){
InsertMenu(mla.hMenu, mla.nIndex, MF_BYPOSITION | MF_STRING, IDPM_TV_FOLD_ALL, "Collapse all");
mla.nIndex++;
}
}
if(bExpandedChild && bExpanded){
InsertMenu(mla.hMenu, mla.nIndex, MF_BYPOSITION | MF_STRING, IDPM_TV_FOLD_CHILDREN, "Collapse children only");
mla.nIndex++;
}
else if(bChildHasChild && bExpanded){
InsertMenu(mla.hMenu, mla.nIndex, MF_BYPOSITION | MF_STRING, IDPM_TV_EXPAND_CHILDREN, "Expand children only");
mla.nIndex++;
}
TrackPopupMenu(mla.hMenu, TPM_LEFTALIGN, pt.x, pt.y, 0, hwnd, nullptr);
}
else{
//It seems like I'm not on an item at all.
}
}
}
break;
case IDC_TABS:
{
if(nNotification == TCN_SELCHANGE){
Edit1.LoadData();
}
}
break;
}
}
break;
case WM_COMMAND:
{
int nID = LOWORD(wParam);
switch(nID){
case IDM_FILE_EXIT:
{
SendMessage(hwnd, WM_DESTROY, 0, 0);
}
break;
case IDM_HELP:
{
OpenHelpDlg();
}
break;
case IDM_SHOW_REPORT:
{
OpenReportDlg(Model);
}
break;
case IDM_TREE_SORT_LIN:
{
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STATE;
GetMenuItemInfo(GetMenu(hwnd), IDM_TREE_SORT_LIN, false, &mii);
if(!(mii.fState & MFS_CHECKED)){
bModelHierarchy = false;
mii.fState = MFS_CHECKED;
SetMenuItemInfo(GetMenu(hwnd), IDM_TREE_SORT_LIN, false, &mii);
mii.fState = MFS_UNCHECKED;
SetMenuItemInfo(GetMenu(hwnd), IDM_TREE_SORT_HIE, false, &mii);
/// Update tree view
HTREEITEM htiRoot = TreeView_GetRoot(hTree);
HTREEITEM htiAnimations = TreeView_GetChildByText(hTree, htiRoot, "Animations");
if(htiAnimations != NULL){
BuildAnimationTree(htiAnimations, Model);
}
HTREEITEM htiGeometry = TreeView_GetChildByText(hTree, htiRoot, "Geometry");
if(htiGeometry != NULL){
BuildGeometryTree(htiGeometry, Model);
}
/// Update .ini
ManageIni(INI_WRITE);
}
}
break;
case IDM_TREE_SORT_HIE:
{
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STATE;
GetMenuItemInfo(GetMenu(hwnd), IDM_TREE_SORT_HIE, false, &mii);
if(!(mii.fState & MFS_CHECKED)){
bModelHierarchy = true;
mii.fState = MFS_CHECKED;
SetMenuItemInfo(GetMenu(hwnd), IDM_TREE_SORT_HIE, false, &mii);
mii.fState = MFS_UNCHECKED;
SetMenuItemInfo(GetMenu(hwnd), IDM_TREE_SORT_LIN, false, &mii);
/// Update tree view
HTREEITEM htiRoot = TreeView_GetRoot(hTree);
HTREEITEM htiAnimations = TreeView_GetChildByText(hTree, htiRoot, "Animations");
if(htiAnimations != NULL){
BuildAnimationTree(htiAnimations, Model);
}
HTREEITEM htiGeometry = TreeView_GetChildByText(hTree, htiRoot, "Geometry");
if(htiGeometry != NULL){
BuildGeometryTree(htiGeometry, Model);
}
/// Update .ini
ManageIni(INI_WRITE);
}
}
break;
case IDM_SHOW_GROUP:
{
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STATE;
GetMenuItemInfo(GetMenu(hwnd), IDM_SHOW_GROUP, false, &mii);
bShowGroup = !(mii.fState & MFS_CHECKED); //Revert it, because user just clicked it so we need to turn it off/on
if(bShowGroup) mii.fState = MFS_CHECKED;
else mii.fState = MFS_UNCHECKED;
SetMenuItemInfo(GetMenu(hwnd), IDM_SHOW_GROUP, false, &mii);
Edit1.UpdateEdit();
ManageIni(INI_WRITE);
}
break;
case IDM_SHOW_DATASTRUCT:
{
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STATE;
GetMenuItemInfo(GetMenu(hwnd), IDM_SHOW_DATASTRUCT, false, &mii);
bShowDataStruct = !(mii.fState & MFS_CHECKED); //Revert it, because user just clicked it so we need to turn it off/on
if(bShowDataStruct) mii.fState = MFS_CHECKED;
else mii.fState = MFS_UNCHECKED;
SetMenuItemInfo(GetMenu(hwnd), IDM_SHOW_DATASTRUCT, false, &mii);
Edit1.UpdateEdit();
ManageIni(INI_WRITE);
}
break;
break;
case IDM_MASS_TO_ASCII:
case IDM_MASS_TO_BIN:
case IDM_MASS_ANALYZE:
{
FileEditor(hwnd, nID, sFile);
}
break;
case IDM_MDL_OPEN:
{
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STATE;
std::string sUpdate;
bool bSuccess = FileEditor(hwnd, nID, sFile);
if(bSuccess){
if(!Model.NodeExists("neck_g")) Button_Enable(hNeck, false);
else Button_Enable(hNeck, true);
bool bLinkHead = Model.HeadLinked();
if(bLinkHead) Button_SetCheck(hNeck, BST_CHECKED);
else Button_SetCheck(hNeck, BST_UNCHECKED);
if(Model.bK2) sUpdate = "KOTOR2";
else sUpdate = "KOTOR1";
SetWindowText(hGame, sUpdate.c_str());
if(Model.bXbox) sUpdate = "XBOX";
else sUpdate = "PC";
SetWindowText(hPlatform, sUpdate.c_str());
if(!Model.empty()) mii.fState = MFS_ENABLED;
else mii.fState = MFS_GRAYED;
SetMenuItemInfo(GetSubMenu(GetMenu(hwnd), 0), 1, true, &mii);
SetMenuItemInfo(GetMenu(hwnd), IDM_BIN_COMPARE, false, &mii);
SetMenuItemInfo(GetMenu(hwnd), IDM_SHOW_REPORT, false, &mii);
GetMenuItemInfo(GetMenu(hwnd), IDM_SHOW_DIFF, false, &mii);
if(!Model.GetCompareData().empty()) mii.fState = MFS_ENABLED | (mii.fState & MFS_CHECKED ? MFS_CHECKED : MFS_UNCHECKED);
else mii.fState = MFS_GRAYED | (mii.fState & MFS_CHECKED ? MFS_CHECKED : MFS_UNCHECKED);
SetMenuItemInfo(GetMenu(hwnd), IDM_SHOW_DIFF, false, &mii);
ManageIni(INI_WRITE);
}
std::wstring sNewName = L"MDLedit " + to_wide(version.Print());
if(!Model.empty()) sNewName += L" (" + Model.GetFilename() + L")";
SetWindowTextW(hwnd, sNewName.c_str());
}
break;
case IDM_BIN_COMPARE:
{
FileEditor(hwnd, nID, sFile);
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STATE;
GetMenuItemInfo(GetMenu(hwnd), IDM_SHOW_DIFF, false, &mii);
if(!Model.GetCompareData().empty()) mii.fState = MFS_ENABLED | (mii.fState & MFS_CHECKED ? MFS_CHECKED : MFS_UNCHECKED);
else mii.fState = MFS_GRAYED | (mii.fState & MFS_CHECKED ? MFS_CHECKED : MFS_UNCHECKED);
SetMenuItemInfo(GetMenu(hwnd), IDM_SHOW_DIFF, false, &mii);
Edit1.UpdateEdit();
}
break;
case IDM_SHOW_DIFF:
{
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STATE;
GetMenuItemInfo(GetMenu(hwnd), IDM_SHOW_DIFF, false, &mii);
bShowDiff = !(mii.fState & MFS_CHECKED); //Revert it, because user just clicked it so we need to turn it off/on
if(bShowDiff) mii.fState = MFS_CHECKED;
else mii.fState = MFS_UNCHECKED;
SetMenuItemInfo(GetMenu(hwnd), IDM_SHOW_DIFF, false, &mii);
Edit1.UpdateEdit();
Edit1.PrintValues();
}
break;
case IDM_BIN_SAVE:
{
int nReturn = IDOK;
if(Model.GetBuffer().empty()) nReturn = IDCANCEL;
if(nReturn == IDOK) (void) FileEditor(hwnd, nID, sFile);
}
break;
case IDM_ASCII_SAVE:
{
int nReturn = IDOK;
if(!Model.GetFileData()) nReturn = IDCANCEL;
if(!Model.Mdx && nReturn == IDOK) nReturn = MessageBox(hwnd, "Warning! No MDX is loaded! MDLedit can still export without the MDX data, but this means exporting without weights, UVs, smoothing groups and for xbox binaries also vert coords.", "Warning!", MB_OKCANCEL | MB_ICONWARNING);
if(nReturn == IDOK) (void) FileEditor(hwnd, nID, sFile);
}
break;
case IDC_BTN_NECK:
{
if(!Model.empty()){
bool bLinkHead = !(Button_GetCheck(hNeck) == BST_CHECKED);
if(Model.LinkHead(bLinkHead)){
if(bLinkHead) Button_SetCheck(hNeck, BST_CHECKED);
else Button_SetCheck(hNeck, BST_UNCHECKED);
Edit1.UpdateEdit();
HTREEITEM hSel = TreeView_GetSelection(hTree);
if(hSel != NULL) ProcessTreeAction(hSel, ACTION_UPDATE_DISPLAY);
}
else std::cout << "neck_g was not found!\n";
}
}
break;
case IDC_BTN_GAME:
{
bool bConfirm = true;
if(Model.GetFileData()){
FileHeader & Data = *Model.GetFileData();
if(Data.MH.cSupermodelName.c_str() != std::string("NULL"))
bConfirm = IDYES == WarningYesNo("This model was loaded with a supermodel from the currently selected game. "
"Are you sure you want to change the target game?");
//if(Model.nSupermodel == 2 && Model.bK2 || Model.nSupermodel == 1 && !Model.bK2)
// bConfirm = IDYES == WarningYesNo("This model refers to a supermodel from the currently selected game. Are you sure you want to change the target game for this model?");
}
if(bConfirm){
Model.bK2 = !Model.bK2;
if(Model.GetFileData()){
Model.Compile();
FixHead();
Edit1.LoadData();
}
std::string sUpdate;
if(Model.bK2) sUpdate = "KOTOR2";
else sUpdate = "KOTOR1";
SetWindowText(hGame, sUpdate.c_str());
ManageIni(INI_WRITE);
}
}
break;
case IDC_BTN_PLATFORM:
{
Model.bXbox = !Model.bXbox;
if(Model.GetFileData()){
Model.Compile();
FixHead();
Edit1.LoadData();
}
std::string sUpdate;
if(Model.bXbox) sUpdate = "XBOX";
else sUpdate = "PC";
SetWindowText(hPlatform, sUpdate.c_str());
ManageIni(INI_WRITE);
}
break;
case IDD_EDITOR_DLG:
{
Edit1.UpdateEdit();
HTREEITEM hSel = TreeView_GetSelection(hTree);
if(hSel != NULL) ProcessTreeAction(hSel, ACTION_UPDATE_DISPLAY);
}
break;
case IDM_SETTINGS:
{
DialogBoxParam(NULL, MAKEINTRESOURCE(DLG_SETTINGS), hwnd, SettingsProc, (LPARAM) &Model);
}
break;
case IDM_EDIT_TEXTURES:
{
if(2 == DialogBoxParam(NULL, MAKEINTRESOURCE(DLG_EDIT_TEXTURES), hwnd, TexturesProc, (LPARAM) &Model)){
std::cout << "Cause model reprocessing!\n";
Model.Compile();
FixHead();
}
Edit1.UpdateEdit();
HTREEITEM hSel = TreeView_GetSelection(hTree);
if(hSel != NULL) ProcessTreeAction(hSel, ACTION_UPDATE_DISPLAY);
}
break;
case IDM_VIEW_HEX:
{
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STATE;
GetMenuItemInfo(GetMenu(hwnd), IDM_VIEW_HEX, false, &mii);
bShowHex = !(mii.fState & MFS_CHECKED); //Revert it, because user just clicked it so we need to turn it off/on
if(bShowHex) mii.fState = MFS_CHECKED;
else mii.fState = MFS_UNCHECKED;
SetMenuItemInfo(GetMenu(hwnd), IDM_VIEW_HEX, false, &mii);
Edit1.ShowHideEdit();
if(bShowHex){
ShowWindow(GetDlgItem(hwnd, IDC_LBL_INT), true);
ShowWindow(GetDlgItem(hwnd, IDC_LBL_UINT), true);
ShowWindow(GetDlgItem(hwnd, IDC_LBL_FLOAT), true);
ShowWindow(GetDlgItem(hwnd, IDC_EDIT_INT), true);
ShowWindow(GetDlgItem(hwnd, IDC_EDIT_UINT), true);
ShowWindow(GetDlgItem(hwnd, IDC_EDIT_FLOAT), true);
ShowWindow(hTabs, true);
ShowWindow(hStatusBar, true);
Edit1.UpdateEdit();
SetWindowPos(hwnd, nullptr, 0, 0, WINDOW_HEX_WIDTH, WINDOW_HEX_HEIGHT, SWP_NOMOVE | SWP_NOZORDER);
}
else{
ShowWindow(GetDlgItem(hwnd, IDC_LBL_INT), false);
ShowWindow(GetDlgItem(hwnd, IDC_LBL_UINT), false);
ShowWindow(GetDlgItem(hwnd, IDC_LBL_FLOAT), false);
ShowWindow(GetDlgItem(hwnd, IDC_EDIT_INT), false);
ShowWindow(GetDlgItem(hwnd, IDC_EDIT_UINT), false);
ShowWindow(GetDlgItem(hwnd, IDC_EDIT_FLOAT), false);
ShowWindow(hTabs, false);
ShowWindow(hStatusBar, false);
SetWindowPos(hwnd, nullptr, 0, 0, WINDOW_NONHEX_WIDTH, WINDOW_NONHEX_HEIGHT, SWP_NOMOVE | SWP_NOZORDER);
}
}
break;
case IDM_MDLEDIT:
{
DialogBox(NULL, MAKEINTRESOURCE(DLG_ABOUT), hwnd, AboutProc);
}
break;
case IDPM_TV_FOLD:
case IDPM_TV_EXPAND:
{
HTREEITEM hSel = TreeView_GetSelection(hTree);
TreeView_Expand(hTree, hSel, TVE_TOGGLE);
}
break;
case IDPM_TV_FOLD_ALL:
case IDPM_TV_EXPAND_ALL:
{
HTREEITEM hSel = TreeView_GetSelection(hTree);
if(!TreeView_ExpandAll(hTree, hSel, (IDPM_TV_FOLD_ALL == nID ? TVE_COLLAPSE : TVE_EXPAND))) std::cout << "Expand/Collapse All failed!\n";
}
break;
case IDPM_TV_FOLD_CHILDREN:
{
HTREEITEM hSel = TreeView_GetSelection(hTree);
HTREEITEM hChild = TreeView_GetChild(hTree, hSel);
while(hChild != NULL){
TreeView_Expand(hTree, hChild, TVE_COLLAPSE);
hChild = TreeView_GetNextSibling(hTree, hChild);
}
}
break;
case IDPM_TV_EXPAND_CHILDREN:
{
HTREEITEM hSel = TreeView_GetSelection(hTree);
HTREEITEM hChild = TreeView_GetChild(hTree, hSel);
while(hChild != NULL){
TreeView_Expand(hTree, hChild, TVE_EXPAND);
hChild = TreeView_GetNextSibling(hTree, hChild);
}
}
break;
case IDPM_VIEW_ASCII:
{
ProcessTreeAction(TreeView_GetSelection(hTree), ACTION_OPEN_VIEWER, NULL);
}
break;
case IDPM_OPEN_EDITOR:
{
ProcessTreeAction(TreeView_GetSelection(hTree), ACTION_OPEN_EDITOR, NULL);
}
break;
case IDPM_SCROLL:
{
ProcessTreeAction(TreeView_GetSelection(hTree), ACTION_SCROLL, NULL);
}
break;
}
}
break;
case WM_SIZE:
{
GetClientRect(hwnd, &rcClient);
if(bShowHex){
SetWindowPos(hDisplayEdit, nullptr,
ME_TREE_OFFSET_X,
ME_DISPLAY_OFFSET_Y,
(rcClient.right - rcClient.left) - ME_HEX_WIN_OFFSET_X - ME_TREE_OFFSET_X - 5,
nEditSize,
0);
SetWindowPos(hTree, nullptr,
ME_TREE_OFFSET_X,
ME_DISPLAY_OFFSET_Y + nEditSize + 2, //ME_TREE_OFFSET_Y,
(rcClient.right - rcClient.left) - ME_HEX_WIN_OFFSET_X - ME_TREE_OFFSET_X - 5,
rcClient.bottom - (ME_DISPLAY_OFFSET_Y + nEditSize + 2) - ME_STATUSBAR_Y - ME_TREE_SIZE_DIFF_Y + 5,
0);
int nEditOffsetX = ME_HEX_WIN_OFFSET_X + ME_HEX_WIN_SIZE_X + ME_DATA_LABEL_OFFSET_X + ME_DATA_LABEL_SIZE_X + ME_DATA_EDIT_OFFSET_X;
SetWindowPos(Edits::hIntEdit, nullptr,
0,
0,
(rcClient.right - rcClient.left) - nEditOffsetX - 5,
ME_DATA_EDIT_SIZE_Y,
SWP_NOMOVE);
SetWindowPos(Edits::hUIntEdit, nullptr,
0,
0,
(rcClient.right - rcClient.left) - nEditOffsetX - 5,
ME_DATA_EDIT_SIZE_Y,
SWP_NOMOVE);
SetWindowPos(Edits::hFloatEdit, nullptr,
0,
0,
(rcClient.right - rcClient.left) - nEditOffsetX - 5,
ME_DATA_EDIT_SIZE_Y,
SWP_NOMOVE);
int nButtonSizeX = (rcClient.right - rcClient.left - ME_TREE_OFFSET_X + 1 - 4) / 3;
int nDataOffsetY [5];
for(int n = 0; n < 5; n++) nDataOffsetY[n] = ME_BASIC_OFFSET_Y + n * ME_DATA_NEXT_ROW;
SetWindowPos(hGame, nullptr,
ME_TREE_OFFSET_X - 1,
nDataOffsetY[3],
nButtonSizeX,
ME_DATA_EDIT_SIZE_Y,
0);
SetWindowPos(hPlatform, nullptr,
ME_TREE_OFFSET_X - 1 + nButtonSizeX,
nDataOffsetY[3],
rcClient.right - rcClient.left - 4 - nButtonSizeX - ME_TREE_OFFSET_X + 1 - nButtonSizeX,
ME_DATA_EDIT_SIZE_Y,
0);
SetWindowPos(hNeck, nullptr,
rcClient.right - rcClient.left - 4 - nButtonSizeX,
nDataOffsetY[3],
nButtonSizeX,
ME_DATA_EDIT_SIZE_Y,
0);
}
else{
SetWindowPos(hDisplayEdit, nullptr,
nCompactOffsetLeft,
ME_DATA_EDIT_SIZE_Y,
(rcClient.right - rcClient.left) - nCompactOffsetLeft - nCompactOffsetRight,
nEditSize,
0);
SetWindowPos(hTree, nullptr,
nCompactOffsetLeft,
nCompactOffsetTop + nEditSize + ME_DATA_EDIT_SIZE_Y,
(rcClient.right - rcClient.left) - nCompactOffsetLeft - nCompactOffsetRight,
rcClient.bottom - (nCompactOffsetTop + nEditSize + ME_DATA_EDIT_SIZE_Y + nCompactOffsetBottom),
0);
int nButtonSizeX = (rcClient.right - rcClient.left - nCompactOffsetRight - nCompactOffsetLeft) / 3;
SetWindowPos(hGame, nullptr,
0, //nCompactOffsetLeft,
0, //nCompactOffsetTop,
nButtonSizeX,
ME_DATA_EDIT_SIZE_Y,
0);
SetWindowPos(hPlatform, nullptr,
nButtonSizeX, //nCompactOffsetLeft + nButtonSizeX + 1,
0, //nCompactOffsetTop,
rcClient.right - rcClient.left - 2*nButtonSizeX, //rcClient.right - rcClient.left - nCompactOffsetRight - nCompactOffsetLeft - 2*nButtonSizeX - 2,
ME_DATA_EDIT_SIZE_Y,
0);
SetWindowPos(hNeck, nullptr,
rcClient.right - rcClient.left - nButtonSizeX, //rcClient.right - rcClient.left - nCompactOffsetRight - nButtonSizeX,
0, //nCompactOffsetTop,
nButtonSizeX,
ME_DATA_EDIT_SIZE_Y,
0);
}
if(bShowHex) SetWindowPos(hTabs, nullptr, ME_HEX_WIN_OFFSET_X, 0, ME_HEX_WIN_OFFSET_X + ME_TABS_SIZE_X, rcClient.bottom - ME_STATUSBAR_Y, 0);
if(bShowHex) Edit1.Resize();
// Resize the statusbar;
RECT rcStatus;
GetClientRect(hStatusBar, &rcStatus);
SendMessage(hStatusBar,message,wParam,lParam);
InvalidateRect(hStatusBar, &rcStatus, false);
}
break;
case WM_CTLCOLORSTATIC:
{
HDC hdcStatic = (HDC) wParam;
HWND hControl = (HWND) lParam;
if(hControl == Edits::hIntEdit ||
hControl == Edits::hUIntEdit ||
hControl == Edits::hFloatEdit ||
hControl == hDisplayEdit ){
SetBkColor(hdcStatic, RGB(255, 255, 255));
return (INT_PTR) CreateSolidBrush(RGB(255, 255, 255));
}
else{
SetBkColor(hdcStatic, RGB(250, 250, 250));
return (INT_PTR) CreateSolidBrush(RGB(250, 250, 250));
}
}
case WM_DESTROY:
{
if(!Model.empty()){
TreeView_DeleteAllItems(hTree);
Model.FlushAll();
}
if(hMessageHook != NULL) UnhookWindowsHookEx(hMessageHook);
PostQuitMessage(0); /* send a WM_QUIT to the message queue */
}
break;
/* for messages that we don't deal with */
default:
{
return DefWindowProc (hwnd, message, wParam, lParam);
}
}
return 0;
}
LRESULT APIENTRY TreeSubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
switch(message){
case WM_NCMOUSEMOVE:
case WM_NCLBUTTONDOWN:
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
{
if(message == WM_NCMOUSEMOVE) message = WM_MOUSEMOVE;
if(message == WM_NCLBUTTONDOWN) message = WM_LBUTTONDOWN;
RECT rcClient;
GetClientRect(hwnd, &rcClient);
POINT pt;
pt.x = GET_X_LPARAM(lParam);
pt.y = GET_Y_LPARAM(lParam);
if(pt.y < 5){
MapWindowPoints(hwnd, hFrame, &pt, 1);
return CallWindowProc(Frame::FrameProc, hFrame, message, wParam, MAKELPARAM((WORD) pt.x, (WORD) pt.y));
}
}
break;
}
return CallWindowProc(MainTreeProc, hwnd, message, wParam, lParam);
}
LRESULT APIENTRY DisplaySubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
//std::cout << "Display Subclass Callback Fired!\n";
switch(message){
case WM_NCMOUSEMOVE:
case WM_NCLBUTTONDOWN: