forked from rizonesoft/Notepad3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dialogs.c
7227 lines (5962 loc) · 242 KB
/
Dialogs.c
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
// encoding: UTF-8
/******************************************************************************
* *
* *
* Notepad3 *
* *
* Dialogs.c *
* Notepad3 dialog boxes implementation *
* Based on code from Notepad2, (c) Florian Balmer 1996-2011 *
* *
* (c) Rizonesoft 2008-2024 *
* https://rizonesoft.com *
* *
* *
*******************************************************************************/
#include "Helpers.h"
#include <windowsx.h>
#include <commctrl.h>
#include <process.h>
#include <shlobj.h>
#include <shellapi.h>
#include <shlwapi.h>
#include <commdlg.h>
#include <shellscalingapi.h>
#include <string.h>
#pragma warning( push )
#pragma warning( disable : 4201) // union/struct w/o name
#include <richedit.h>
#pragma warning( pop )
#include "VersionEx.h"
#include "PathLib.h"
#include "Edit.h"
#include "Dlapi.h"
#include "Encoding.h"
#include "Styles.h"
#include "MuiLanguage.h"
#include "Notepad3.h"
#include "Config/Config.h"
#include "DarkMode/DarkMode.h"
#include "tinyexpr/tinyexpr.h"
//#include "tinyexprcpp/tinyexpr_cif.h"
#include "Resample.h"
#include "PathLib.h"
#include "SciCall.h"
#include "Dialogs.h"
//=============================================================================
#define OIC_SAMPLE 32512
#define OIC_HAND 32513
#define OIC_QUES 32514
#define OIC_BANG 32515
#define OIC_NOTE 32516
#if(WINVER >= 0x0400)
#define OIC_WINLOGO 32517
#define OIC_WARNING OIC_BANG
#define OIC_ERROR OIC_HAND
#define OIC_INFORMATION OIC_NOTE
#endif /* WINVER >= 0x0400 */
#if(WINVER >= 0x0600)
#define OIC_SHIELD 32518
#endif /* WINVER >= 0x0600 */
#ifndef TMT_MSGBOXFONT
#define TMT_MSGBOXFONT 805
#endif
//=============================================================================
//
// MessageBoxLng()
//
static HHOOK s_hCBThook = NULL;
static LRESULT CALLBACK SetPosRelatedToParent_Hook(INT nCode, WPARAM wParam, LPARAM lParam)
{
// notification that a window is about to be activated
if (nCode == HCBT_CREATEWND) {
HWND const hThisWnd = (HWND)wParam;
if (hThisWnd) {
SetDialogIconNP3(hThisWnd);
InitWindowCommon(hThisWnd, true);
// get window handles
LPCREATESTRUCT const pCreateStruct = ((LPCBT_CREATEWND)lParam)->lpcs;
HWND const hParentWnd = pCreateStruct->hwndParent ? pCreateStruct->hwndParent : GetParentOrDesktop(hThisWnd);
if (hParentWnd) {
// set new coordinates
RECT rcDlg = { 0, 0, 0, 0 };
rcDlg.left = pCreateStruct->x;
rcDlg.top = pCreateStruct->y;
rcDlg.right = pCreateStruct->x + pCreateStruct->cx;
rcDlg.bottom = pCreateStruct->y + pCreateStruct->cy;
POINT const ptTopLeft = GetCenterOfDlgInParent(&rcDlg, hParentWnd);
pCreateStruct->x = ptTopLeft.x;
pCreateStruct->y = ptTopLeft.y;
}
// we are done
if (s_hCBThook) {
UnhookWindowsHookEx(s_hCBThook);
s_hCBThook = NULL;
}
} else if (s_hCBThook) {
// continue with any possible chained hooks
return CallNextHookEx(s_hCBThook, nCode, wParam, lParam);
}
}
return (LRESULT)0;
}
// -----------------------------------------------------------------------------
int MessageBoxLng(UINT uType, UINT uidMsg, ...)
{
HSTRINGW hfmt_str = StrgCreate(NULL);
LPWSTR const fmt_buf = StrgWriteAccessBuf(hfmt_str, XXXL_BUFFER);
if (!GetLngString(uidMsg, fmt_buf, (int)StrgGetAllocLength(hfmt_str))) {
StrgDestroy(hfmt_str);
return -1;
}
StrgSanitize(hfmt_str);
HSTRINGW htxt_str = StrgCreate(NULL);
const PUINT_PTR argp = (PUINT_PTR)&uidMsg + 1;
bool const bHasArgs = (argp && *argp);
if (bHasArgs) {
LPWSTR const txt_buf = StrgWriteAccessBuf(htxt_str, XXXL_BUFFER);
StringCchVPrintfW(txt_buf, StrgGetAllocLength(htxt_str), StrgGet(hfmt_str), (LPVOID)argp);
StrgSanitize(htxt_str);
}
uType |= MB_SETFOREGROUND; //~ MB_TOPMOST
if (Settings.DialogsLayoutRTL) {
uType |= MB_RTLREADING;
}
// center message box to focus or main
HWND const focus = GetFocus();
HWND const hwnd = focus ? focus : Globals.hwndMain;
s_hCBThook = SetWindowsHookEx(WH_CBT, &SetPosRelatedToParent_Hook, 0, GetCurrentThreadId());
int const res = MessageBoxEx(hwnd, bHasArgs ? StrgGet(htxt_str) : StrgGet(hfmt_str),
_W(SAPPNAME), uType, GetLangIdByLocaleName(Globals.CurrentLngLocaleName));
StrgDestroy(htxt_str);
StrgDestroy(hfmt_str);
return res;
}
//=============================================================================
//
// MsgBoxLastError()
//
DWORD MsgBoxLastError(LPCWSTR lpszMessage, DWORD dwErrID)
{
// Retrieve the system error message for the last-error code
if (!dwErrID) {
dwErrID = GetLastError();
}
LPVOID lpMsgBuf = NULL;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dwErrID,
GetLangIdByLocaleName(Globals.CurrentLngLocaleName),
(LPWSTR)&lpMsgBuf,
0, NULL);
if (lpMsgBuf) {
// Display the error message and exit the process
size_t const len = StringCchLen((LPCWSTR)lpMsgBuf, 0) + StringCchLen(lpszMessage, 0) + 160;
LPWSTR const lpDisplayBuf = (LPWSTR)AllocMem(len * sizeof(WCHAR), HEAP_ZERO_MEMORY);
if (lpDisplayBuf) {
WCHAR msgFormat[128] = { L'\0' };
GetLngString(IDS_MUI_ERR_DLG_FORMAT, msgFormat, COUNTOF(msgFormat));
StringCchPrintf(lpDisplayBuf, len, msgFormat, lpszMessage, (LPCWSTR)lpMsgBuf, dwErrID);
// center message box to main
HWND const focus = GetFocus();
HWND const hwnd = focus ? focus : Globals.hwndMain;
s_hCBThook = SetWindowsHookEx(WH_CBT, &SetPosRelatedToParent_Hook, 0, GetCurrentThreadId());
UINT uType = MB_ICONERROR | MB_TOPMOST | (Settings.DialogsLayoutRTL ? MB_RTLREADING : 0);
MessageBoxEx(hwnd, lpDisplayBuf, _W(SAPPNAME) L" - ERROR", uType, GetLangIdByLocaleName(Globals.CurrentLngLocaleName));
FreeMem(lpDisplayBuf);
}
LocalFree(lpMsgBuf); // LocalAlloc()
lpMsgBuf = NULL;
}
return dwErrID;
}
//=============================================================================
//
// _InfoBoxLngDlgProc()
//
//
typedef struct _infbox {
UINT uType;
LPWSTR lpstrMessage;
LPWSTR lpstrSetting;
bool bDisableCheckBox;
} INFOBOXLNG, *LPINFOBOXLNG;
static INT_PTR CALLBACK _InfoBoxLngDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
{
static HBITMAP hIconBmp = NULL;
static HICON hBoxIcon = NULL;
static UINT dpi = USER_DEFAULT_SCREEN_DPI;
switch (umsg) {
case WM_INITDIALOG: {
SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lParam);
LPINFOBOXLNG const lpMsgBox = (LPINFOBOXLNG)lParam;
SetDialogIconNP3(hwnd);
InitWindowCommon(hwnd, true);
#ifdef D_NP3_WIN10_DARK_MODE
if (UseDarkMode()) {
for (int btn = IDOK; btn <= IDCONTINUE; ++btn) {
HWND const hBtn = GetDlgItem(hwnd, btn);
if (hBtn) {
SetExplorerTheme(hBtn);
}
}
SetWindowTheme(GetDlgItem(hwnd, IDC_INFOBOXCHECK), L"", L"");
}
#endif
switch (lpMsgBox->uType & MB_ICONMASK) {
case MB_ICONQUESTION:
hBoxIcon = Globals.hIconMsgQuest;
break;
case MB_ICONWARNING: // = MB_ICONEXCLAMATION
hBoxIcon = Globals.hIconMsgWarn;
break;
case MB_ICONERROR: // = MB_ICONSTOP, MB_ICONHAND
hBoxIcon = Globals.hIconMsgError;
break;
case MB_ICONSHIELD:
hBoxIcon = Globals.hIconMsgShield;
break;
case MB_USERICON:
hBoxIcon = Globals.hIconMsgUser;
break;
case MB_ICONINFORMATION: // = MB_ICONASTERISK
default:
hBoxIcon = Globals.hIconMsgInfo;
break;
}
dpi = Scintilla_GetWindowDPI(hwnd);
int const scxb = Scintilla_GetSystemMetricsForDpi(SM_CXICON, dpi);
int const scyb = Scintilla_GetSystemMetricsForDpi(SM_CYICON, dpi);
hIconBmp = ResampleIconToBitmap(hwnd, hIconBmp, hBoxIcon, scxb, scyb);
if (hIconBmp) {
SetBitmapControl(hwnd, IDC_INFOBOXICON, hIconBmp);
}
//UINT const tabStopDist[3] = { 4, 4, 8 };
//SendMessage(GetDlgItem(hwnd, IDC_INFOBOXTEXT), EM_SETTABSTOPS, 3, (LPARAM)tabStopDist);
#if 0
// Resize dialog to fit text - TODO: move buttons dynamically too
HWND const hWndText = GetDlgItem(hwnd, IDC_INFOBOXTEXT);
RECT rectText = { 0 };
GetWindowRectEx(hWndText, &rectText);
RECT rectNew = { 0 };
rectNew.left = 0;
rectNew.top = 0;
rectNew.right = rectText.right - rectText.left; // max as specified
rectNew.bottom = rectNew.right; // max quadratic size
HDC hdc = GetDC(hWndText);
DrawText(hdc, lpMsgBox->lpstrMessage, -1, &rectNew, DT_CALCRECT | DT_WORDBREAK); // calc size
ReleaseDC(hWndText, hdc);
// Change size of text field
SetWindowPos(hWndText, NULL, 0, 0, rectNew.right - rectNew.left, rectNew.bottom - rectNew.top, SWP_NOMOVE | SWP_NOZORDER);
//GetWindowRect(hWndText, &rectText);
int const width = (rectNew.right - rectNew.left) + 100;
int const height = (rectNew.bottom - rectNew.top) + 200;
SetWindowPos(hwnd, NULL, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER);
#endif
SetDlgItemText(hwnd, IDC_INFOBOXTEXT, lpMsgBox->lpstrMessage);
if (lpMsgBox->bDisableCheckBox) {
DialogEnableControl(hwnd, IDC_INFOBOXCHECK, false);
DialogHideControl(hwnd, IDC_INFOBOXCHECK, true);
}
FreeMem(lpMsgBox->lpstrMessage);
lpMsgBox->lpstrMessage = NULL;
CenterDlgInParent(hwnd, NULL, true);
AttentionBeep(lpMsgBox->uType);
}
return TRUE;
case WM_DPICHANGED: {
dpi = LOWORD(wParam);
int const scxb = Scintilla_GetSystemMetricsForDpi(SM_CXICON, dpi);
int const scyb = Scintilla_GetSystemMetricsForDpi(SM_CYICON, dpi);
hIconBmp = ResampleIconToBitmap(hwnd, hIconBmp, hBoxIcon, scxb, scyb);
if (hIconBmp) {
SetBitmapControl(hwnd, IDC_INFOBOXICON, hIconBmp);
}
UpdateWindowLayoutForDPI(hwnd, (RECT*)lParam, LOWORD(wParam));
}
return TRUE;
case WM_CLOSE:
EndDialog(hwnd, LOWORD(IDCLOSE));
break;
case WM_DESTROY:
if (hIconBmp) {
DeleteObject(hIconBmp);
}
return TRUE;
#ifdef D_NP3_WIN10_DARK_MODE
CASE_WM_CTLCOLOR_SET:
return SetDarkModeCtlColors((HDC)wParam, UseDarkMode());
break;
case WM_SETTINGCHANGE:
if (IsDarkModeSupported() && IsColorSchemeChangeMessage(lParam)) {
SendMessage(hwnd, WM_THEMECHANGED, 0, 0);
}
break;
case WM_THEMECHANGED:
if (IsDarkModeSupported()) {
bool const darkModeEnabled = CheckDarkModeEnabled();
AllowDarkModeForWindowEx(hwnd, darkModeEnabled);
RefreshTitleBarThemeColor(hwnd);
for (int btn = IDOK; btn <= IDCONTINUE; ++btn) {
HWND const hBtn = GetDlgItem(hwnd, btn);
if (hBtn) {
AllowDarkModeForWindowEx(hBtn, darkModeEnabled);
SendMessage(hBtn, WM_THEMECHANGED, 0, 0);
}
}
UpdateWindowEx(hwnd);
}
break;
#endif
case WM_COMMAND: {
LPINFOBOXLNG const lpMsgBox = (LPINFOBOXLNG)GetWindowLongPtr(hwnd, DWLP_USER);
switch (LOWORD(wParam)) {
case IDOK:
case IDYES:
case IDRETRY:
case IDIGNORE:
case IDTRYAGAIN:
case IDCONTINUE:
if (IsButtonChecked(hwnd, IDC_INFOBOXCHECK) && StrIsNotEmpty(lpMsgBox->lpstrSetting) && Globals.bCanSaveIniFile) {
IniFileSetLong(Paths.IniFile, Constants.SectionSuppressedMessages, lpMsgBox->lpstrSetting, LOWORD(wParam));
}
//[FallThrough]
case IDNO:
case IDABORT:
case IDCLOSE:
case IDCANCEL:
EndDialog(hwnd, LOWORD(wParam));
break;
case IDC_INFOBOXCHECK: {
bool const isChecked = IsButtonChecked(hwnd, IDC_INFOBOXCHECK);
DialogEnableControl(hwnd, IDNO, !isChecked);
DialogEnableControl(hwnd, IDABORT, !isChecked);
DialogEnableControl(hwnd, IDIGNORE, !isChecked);
DialogEnableControl(hwnd, IDCONTINUE, !isChecked);
DialogEnableControl(hwnd, IDCLOSE, !isChecked);
DialogEnableControl(hwnd, IDCANCEL, !isChecked);
SendMessage(hwnd, WM_NEXTDLGCTL, 0, FALSE);
}
break;
default:
break;
}
}
return TRUE;
}
return FALSE;
}
//=============================================================================
//
// InfoBoxLng()
//
//
LONG InfoBoxLng(UINT uType, LPCWSTR lpstrSetting, UINT uidMsg, ...)
{
int const iMode = StrIsEmpty(lpstrSetting) ? 0 : IniFileGetLong(Paths.IniFile, Constants.SectionSuppressedMessages, lpstrSetting, 0);
if (Settings.DialogsLayoutRTL) {
uType |= MB_RTLREADING;
}
switch (iMode) {
case IDOK:
case IDYES:
case IDCONTINUE:
return MAKELONG(iMode, iMode);
case 0:
// no entry found
case -1:
// disable "Don't display again" check-box
break;
default:
if (Globals.bCanSaveIniFile) {
IniFileDelete(Paths.IniFile, Constants.SectionSuppressedMessages, lpstrSetting, false);
}
break;
}
WCHAR wchMessage[LARGE_BUFFER];
if (!GetLngString(uidMsg, wchMessage, COUNTOF(wchMessage))) {
return MAKELONG(0, iMode);
}
INFOBOXLNG msgBox = { 0 };
msgBox.uType = uType;
msgBox.lpstrMessage = AllocMem((COUNTOF(wchMessage)+1) * sizeof(WCHAR), HEAP_ZERO_MEMORY);
const PUINT_PTR argp = (PUINT_PTR)& uidMsg + 1;
if (argp && *argp) {
StringCchVPrintfW(msgBox.lpstrMessage, COUNTOF(wchMessage), wchMessage, (LPVOID)argp);
} else {
StringCchCopy(msgBox.lpstrMessage, COUNTOF(wchMessage), wchMessage);
}
bool bLastError = false;
switch (uidMsg) {
case IDS_MUI_ERR_LOADFILE:
case IDS_MUI_ERR_SAVEFILE:
case IDS_MUI_CREATEINI_FAIL:
case IDS_MUI_WRITEINI_FAIL:
case IDS_MUI_EXPORT_FAIL:
case IDS_MUI_ERR_ELEVATED_RIGHTS:
case IDS_MUI_FILELOCK_ERROR:
bLastError = true;
break;
default:
//bLastError = false;
break;
}
if (bLastError) {
LPVOID lpMsgBuf = NULL;
if (Globals.dwLastError != ERROR_SUCCESS) {
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
Globals.dwLastError,
GetLangIdByLocaleName(Globals.CurrentLngLocaleName),
(LPWSTR)&lpMsgBuf, 0,
NULL);
Globals.dwLastError = ERROR_SUCCESS; // reset;
}
if (lpMsgBuf) {
StringCchCat(msgBox.lpstrMessage, COUNTOF(wchMessage), L"\n\n");
StringCchCat(msgBox.lpstrMessage, COUNTOF(wchMessage), lpMsgBuf);
LocalFree(lpMsgBuf);
lpMsgBuf = NULL;
}
WCHAR wcht = *CharPrev(msgBox.lpstrMessage, StrEnd(msgBox.lpstrMessage, COUNTOF(wchMessage)));
if (IsCharAlphaNumeric(wcht) || wcht == '"' || wcht == '\'') {
StringCchCat(msgBox.lpstrMessage, COUNTOF(wchMessage), L".");
}
}
msgBox.lpstrSetting = (LPWSTR)lpstrSetting;
msgBox.bDisableCheckBox = (!Globals.bCanSaveIniFile || StrIsEmpty(lpstrSetting) || (iMode < 0)) ? true : false;
int idDlg;
switch (uType & MB_TYPEMASK) {
case MB_OK: // one push button : OK. This is the default.
idDlg = IDD_MUI_INFOBOX;
break;
case MB_YESNO: // contains two push buttons : Yes and No.
idDlg = IDD_MUI_INFOBOX2;
break;
case MB_OKCANCEL: // contains two push buttons : OK and Cancel.
idDlg = IDD_MUI_INFOBOX3;
break;
case MB_YESNOCANCEL: // contains three push buttons : Yes, No, and Cancel.
idDlg = IDD_MUI_INFOBOX4;
break;
case MB_RETRYCANCEL: // contains two push buttons : Retry and Cancel.
idDlg = IDD_MUI_INFOBOX5;
break;
case MB_ABORTRETRYIGNORE: // three push buttons : Abort, Retry, and Ignore.
idDlg = IDD_MUI_INFOBOX6;
break;
// Use this message box type instead of MB_ABORTRETRYIGNORE.
case MB_CANCELTRYCONTINUE: // three push buttons : Cancel, Try Again, Continue.
idDlg = IDD_MUI_INFOBOX7;
break;
case MB_FILECHANGEDNOTIFY:
idDlg = IDD_MUI_INFOBOX_FILECHANGED;
break;
default:
idDlg = IDD_MUI_INFOBOX;
break;
}
HWND focus = GetFocus();
HWND hwnd = focus ? focus : Globals.hwndMain;
INT_PTR const answer = ThemedDialogBoxParam(Globals.hLngResContainer, MAKEINTRESOURCE(idDlg), hwnd, _InfoBoxLngDlgProc, (LPARAM)&msgBox);
if (msgBox.lpstrMessage) {
FreeMem(msgBox.lpstrMessage);
}
return MAKELONG(answer, iMode);
}
/*
MinimizeToTray - Copyright 2000 Matthew Ellis <[email protected]>
Changes made by flo:
- Commented out: #include "stdafx.h"
- Moved variable declaration: APPBARDATA appBarData;
*/
// MinimizeToTray
//
// A couple of routines to show how to make it produce a custom caption
// animation to make it look like we are minimizing to and maximizing
// from the system tray
//
// These routines are public domain, but it would be nice if you dropped
// me a line if you use them!
//
// 1.0 29.06.2000 Initial version
// 1.1 01.07.2000 The window retains it's place in the Z-order of windows
// when minimized/hidden. This means that when restored/shown, it doen't
// always appear as the foreground window unless we call SetForegroundWindow
//
// Copyright 2000 Matthew Ellis <[email protected]>
/*#include "stdafx.h"*/
// Odd. VC++6 winuser.h has IDANI_CAPTION defined (as well as IDANI_OPEN and
// IDANI_CLOSE), but the Platform SDK only has IDANI_OPEN...
// I don't know what IDANI_OPEN or IDANI_CLOSE do. Trying them in this code
// produces nothing. Perhaps they were intended for window opening and closing
// like the MAC provides...
#ifndef IDANI_OPEN
#define IDANI_OPEN 1
#endif
#ifndef IDANI_CLOSE
#define IDANI_CLOSE 2
#endif
#ifndef IDANI_CAPTION
#define IDANI_CAPTION 3
#endif
#define DEFAULT_RECT_WIDTH 150
#define DEFAULT_RECT_HEIGHT 30
// Returns the rect of where we think the system tray is. This will work for
// all current versions of the shell. If explorer isn't running, we try our
// best to work with a 3rd party shell. If we still can't find anything, we
// return a rect in the lower right hand corner of the screen
static bool GetTrayWndRect(LPRECT lpTrayRect) {
APPBARDATA appBarData;
// First, we'll use a quick hack method. We know that the taskbar is a window
// of class Shell_TrayWnd, and the status tray is a child of this of class
// TrayNotifyWnd. This provides us a window rect to minimize to. Note, however,
// that this is not guaranteed to work on future versions of the shell. If we
// use this method, make sure we have a backup!
HWND hShellTrayWnd = FindWindowEx(NULL, NULL, TEXT("Shell_TrayWnd"), NULL);
if (hShellTrayWnd) {
HWND hTrayNotifyWnd = FindWindowEx(hShellTrayWnd, NULL, TEXT("TrayNotifyWnd"), NULL);
if (hTrayNotifyWnd) {
GetWindowRect(hTrayNotifyWnd, lpTrayRect);
return true;
}
}
// OK, we failed to get the rect from the quick hack. Either explorer isn't
// running or it's a new version of the shell with the window class names
// changed (how dare Microsoft change these undocumented class names!) So, we
// try to find out what side of the screen the taskbar is connected to. We
// know that the system tray is either on the right or the bottom of the
// taskbar, so we can make a good guess at where to minimize to
/*APPBARDATA appBarData;*/
appBarData.cbSize = sizeof(appBarData);
if (SHAppBarMessage(ABM_GETTASKBARPOS, &appBarData)) {
// We know the edge the taskbar is connected to, so guess the rect of the
// system tray. Use various fudge factor to make it look good
switch (appBarData.uEdge) {
case ABE_LEFT:
case ABE_RIGHT:
// We want to minimize to the bottom of the taskbar
lpTrayRect->top = appBarData.rc.bottom - 100;
lpTrayRect->bottom = appBarData.rc.bottom - 16;
lpTrayRect->left = appBarData.rc.left;
lpTrayRect->right = appBarData.rc.right;
break;
case ABE_TOP:
case ABE_BOTTOM:
// We want to minimize to the right of the taskbar
lpTrayRect->top = appBarData.rc.top;
lpTrayRect->bottom = appBarData.rc.bottom;
lpTrayRect->left = appBarData.rc.right - 100;
lpTrayRect->right = appBarData.rc.right - 16;
break;
}
return true;
}
// Blimey, we really aren't in luck. It's possible that a third party shell
// is running instead of explorer. This shell might provide support for the
// system tray, by providing a Shell_TrayWnd window (which receives the
// messages for the icons) So, look for a Shell_TrayWnd window and work out
// the rect from that. Remember that explorer's taskbar is the Shell_TrayWnd,
// and stretches either the width or the height of the screen. We can't rely
// on the 3rd party shell's Shell_TrayWnd doing the same, in fact, we can't
// rely on it being any size. The best we can do is just blindly use the
// window rect, perhaps limiting the width and height to, say 150 square.
// Note that if the 3rd party shell supports the same configuraion as
// explorer (the icons hosted in NotifyTrayWnd, which is a child window of
// Shell_TrayWnd), we would already have caught it above
hShellTrayWnd = FindWindowEx(NULL, NULL, TEXT("Shell_TrayWnd"), NULL);
if (hShellTrayWnd) {
GetWindowRect(hShellTrayWnd, lpTrayRect);
if (lpTrayRect->right - lpTrayRect->left > DEFAULT_RECT_WIDTH) {
lpTrayRect->left = lpTrayRect->right - DEFAULT_RECT_WIDTH;
}
if (lpTrayRect->bottom - lpTrayRect->top > DEFAULT_RECT_HEIGHT) {
lpTrayRect->top = lpTrayRect->bottom - DEFAULT_RECT_HEIGHT;
}
return true;
}
// OK. Haven't found a thing. Provide a default rect based on the current work area
SystemParametersInfo(SPI_GETWORKAREA, 0, lpTrayRect, 0);
lpTrayRect->left = lpTrayRect->right - DEFAULT_RECT_WIDTH;
lpTrayRect->top = lpTrayRect->bottom - DEFAULT_RECT_HEIGHT;
return false;
}
// Check to see if the system animation has been enabled/disabled
bool HasDrawAnimation()
{
ANIMATIONINFO ai = { sizeof(ANIMATIONINFO), 0 };
SystemParametersInfo(SPI_GETANIMATION, sizeof(ai), &ai, 0);
return ai.iMinAnimate;
}
void MinimizeWndToTaskbar(HWND hWnd)
{
ShowWindow(hWnd, SW_MINIMIZE);
}
void MinimizeWndToTray(HWND hWnd)
{
MinimizeWndToTaskbar(hWnd);
if (HasDrawAnimation()) {
// Get the rect of the window. It is safe to use the rect of the whole
// window - DrawAnimatedRects will only draw the caption
RECT rcMiniMized;
GetTrayWndRect(&rcMiniMized);
WINDOWPLACEMENT wp = { sizeof(WINDOWPLACEMENT) };
GetWindowPlacement(hWnd, &wp);
// Get the system to draw our animation for us
Sleep(100); // but give SW_MINIMIZE some time to do its stuff
DrawAnimatedRects(hWnd, IDANI_CAPTION, &wp.rcNormalPosition, &rcMiniMized);
}
// Add the tray icon. If we add it before the call to DrawAnimatedRects,
// the taskbar gets erased, but doesn't get redrawn until DAR finishes.
// This looks untidy, so call the functions in this order
ShowNotifyIcon(hWnd, true);
SetNotifyIconTitle(hWnd);
// Hide the window
ShowWindow(hWnd, SW_HIDE);
Globals.bMinimizedToTray = true;
}
void RestoreWndFromTaskbar(HWND hWnd)
{
ShowWindow(hWnd, SW_RESTORE);
SetActiveWindow(hWnd);
SetForegroundWindow(hWnd);
}
void RestoreWndFromTray(HWND hWnd)
{
ShowWindow(hWnd, SW_SHOW);
if (HasDrawAnimation()) {
// Get the rect of the tray and the window. Note that the window rect
// is still valid even though the window is hidden
RECT rcMiniMized;
GetTrayWndRect(&rcMiniMized);
WINDOWPLACEMENT wp = { sizeof(WINDOWPLACEMENT) };
GetWindowPlacement(hWnd, &wp);
DrawAnimatedRects(hWnd, IDANI_CAPTION, &rcMiniMized, &wp.rcNormalPosition);
}
// Show the window, and make sure we're the foreground window
RestoreWndFromTaskbar(hWnd);
// Remove the tray icon. As described above, remove the icon after the
// call to DrawAnimatedRects, or the taskbar will not refresh itself
// properly until DAR finished
ShowNotifyIcon(hWnd, false);
Globals.bMinimizedToTray = false;
}
//=============================================================================
//
// DisplayCmdLineHelp()
//
#if 0
void DisplayCmdLineHelp(HWND hwnd)
{
WCHAR szText[2048] = { L'\0' };
GetLngString(IDS_MUI_CMDLINEHELP,szText,COUNTOF(szText));
MSGBOXPARAMS mbp = { 0 };
mbp.cbSize = sizeof(MSGBOXPARAMS);
mbp.hwndOwner = hwnd;
mbp.hInstance = Globals.hInstance;
mbp.lpszText = szText;
mbp.lpszCaption = _W(SAPPNAME);
mbp.dwStyle = MB_OK | MB_USERICON | MB_SETFOREGROUND;
mbp.lpszIcon = MAKEINTRESOURCE(IDR_MAINWND);
mbp.dwContextHelpId = 0;
mbp.lpfnMsgBoxCallback = NULL;
mbp.dwLanguageId = GetLangIdByLocaleName(Globals.CurrentLngLocaleName);
hhkMsgBox = SetWindowsHookEx(WH_CBT, &_MsgBoxProc, 0, GetCurrentThreadId());
MessageBoxIndirect(&mbp);
//MsgBoxLng(MBINFO, IDS_MUI_CMDLINEHELP);
}
#else
static INT_PTR CALLBACK CmdLineHelpProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (umsg) {
case WM_INITDIALOG: {
SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lParam);
SetDialogIconNP3(hwnd);
InitWindowCommon(hwnd, true);
#ifdef D_NP3_WIN10_DARK_MODE
if (UseDarkMode()) {
SetExplorerTheme(GetDlgItem(hwnd, IDOK));
}
#endif
WCHAR szText[4096] = { L'\0' };
GetLngString(IDS_MUI_CMDLINEHELP, szText, COUNTOF(szText));
SetDlgItemText(hwnd, IDC_CMDLINEHELP, szText);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;
case WM_DPICHANGED:
UpdateWindowLayoutForDPI(hwnd, (RECT*)lParam, LOWORD(wParam));
return TRUE;
#ifdef D_NP3_WIN10_DARK_MODE
CASE_WM_CTLCOLOR_SET:
return SetDarkModeCtlColors((HDC)wParam, UseDarkMode());
break;
case WM_SETTINGCHANGE:
if (IsDarkModeSupported() && IsColorSchemeChangeMessage(lParam)) {
SendMessage(hwnd, WM_THEMECHANGED, 0, 0);
}
break;
case WM_THEMECHANGED:
if (IsDarkModeSupported()) {
bool const darkModeEnabled = CheckDarkModeEnabled();
AllowDarkModeForWindowEx(hwnd, darkModeEnabled);
RefreshTitleBarThemeColor(hwnd);
for (int btn = IDOK; btn <= IDCONTINUE; ++btn) {
HWND const hBtn = GetDlgItem(hwnd, btn);
if (hBtn) {
AllowDarkModeForWindowEx(hBtn, darkModeEnabled);
SendMessage(hBtn, WM_THEMECHANGED, 0, 0);
}
}
UpdateWindowEx(hwnd);
}
break;
#endif
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
case IDCANCEL:
case IDYES:
case IDNO:
EndDialog(hwnd, LOWORD(wParam));
break;
}
return TRUE;
default:
break;
}
return FALSE;
}
INT_PTR DisplayCmdLineHelp(HWND hwnd)
{
return ThemedDialogBoxParam(Globals.hLngResContainer, MAKEINTRESOURCE(IDD_MUI_CMDLINEHELP), hwnd, CmdLineHelpProc, (LPARAM)L"");
}
#endif
/*
//=============================================================================
//
// _LoadStringEx()
//
static DWORD _LoadStringEx(UINT nResId, LPCTSTR pszRsType, LPSTR strOut)
{
LPTSTR pszResId = MAKEINTRESOURCE(nResId);
if (Globals.hInstance == NULL)
return FALSEL;
HRSRC hRsrc = FindResource(Globals.hInstance, pszResId, pszRsType);
if (hRsrc == NULL) {
return FALSEL;
}
HGLOBAL hGlobal = LoadResource(Globals.hInstance, hRsrc);
if (hGlobal == NULL) {
return FALSEL;
}
const BYTE* pData = (const BYTE*)LockResource(hGlobal);
if (pData == NULL) {
FreeResource(hGlobal);
return FALSEL;
}
DWORD dwSize = SizeofResource(Globals.hInstance, hRsrc);
if (strOut) {
memcpy(strOut, (LPCSTR)pData, dwSize);
}
UnlockResource(hGlobal);
FreeResource(hGlobal);
return dwSize;
}
*/
//=============================================================================
//
// (EditStreamCallback)
// _LoadRtfCallback() RTF edit control StreamIn's callback function
//
static DWORD CALLBACK _LoadRtfCallback(
DWORD_PTR dwCookie, // (in) pointer to the string
LPBYTE pbBuff, // (in) pointer to the destination buffer
LONG cb, // (in) size in bytes of the destination buffer
LONG FAR* pcb // (out) number of bytes transfered
)
{
LPSTR* pstr = (LPSTR*)dwCookie;
LONG const len = (LONG)StringCchLenA(*pstr,0);
if (len < cb) {
*pcb = len;
memcpy_s(pbBuff, cb, (LPCSTR)*pstr, *pcb);
*pstr += len;
//*pstr = '\0';
} else {
*pcb = cb;
memcpy_s(pbBuff, cb, (LPCSTR)*pstr, *pcb);
*pstr += cb;
}
return FALSE;
}
// ----------------------------------------------------------------------------
//=============================================================================
//
// AboutDlgProc()
//
INT_PTR CALLBACK AboutDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
{
static HFONT hVersionFont = NULL;
static char pAboutResource[8192] = { '\0' };
static char* pAboutInfo = NULL;
static UINT dpi = USER_DEFAULT_SCREEN_DPI;
static HBRUSH hbrBkgnd = NULL;
switch (umsg) {
case WM_INITDIALOG: {
SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lParam);
SetDialogIconNP3(hwnd);
//~InitWindowCommon(hwnd, true);
//~SetWindowLayoutRTL(hwnd, Settings.DialogsLayoutRTL);
SetExplorerTheme(hwnd);
#ifdef D_NP3_WIN10_DARK_MODE
if (UseDarkMode()) {
SetExplorerTheme(GetDlgItem(hwnd, IDOK));
SetExplorerTheme(GetDlgItem(hwnd, IDC_COPYVERSTRG));
}
#endif
dpi = Scintilla_GetWindowDPI(hwnd);
SetDlgItemText(hwnd, IDC_VERSION, _W(_STRG(VERSION_FILEVERSION_LONG)));
SetDlgItemText(hwnd, IDC_SCI_VERSION, VERSION_SCIVERSION L", " VERSION_LXIVERSION L", ID='" _W(_STRG(VERSION_COMMIT_ID)) L"'");
SetDlgItemText(hwnd, IDC_COPYRIGHT, _W(VERSION_LEGALCOPYRIGHT));
SetDlgItemText(hwnd, IDC_AUTHORNAME, _W(VERSION_AUTHORNAME));
SetDlgItemText(hwnd, IDC_COMPILER, VERSION_COMPILER);