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
|
#include "main.h"
#include "./resource.h"
#include "./api.h"
#include "./language.h"
#include "./jsapi2_svc_apicreator.h"
#include "./commandLink.h"
#include <strsafe.h>
#ifndef LONGX86
#ifdef _WIN64
#define LONGX86 LONG_PTR
#else /*_WIN64*/
#define LONGX86 LONG
#endif /*_WIN64*/
#endif // LONGX86
#ifdef WIN64
#define MSGRESULT(__hwnd, __result) { SetWindowLongPtrW((__hwnd), DWLP_MSGRESULT, ((LONGX86)(LONG_PTR)(__result))); return TRUE; }
#else
#define MSGRESULT(__hwnd, __result) { SetWindowLongPtrW((__hwnd), DWL_MSGRESULT, ((LONGX86)(LONG_PTR)(__result))); return TRUE; }
#endif
#ifdef __cplusplus
#define SENDMSG(__hwnd, __msgId, __wParam, __lParam) ::SendMessageW((__hwnd), (__msgId), (__wParam), (__lParam))
#else
#define SENDMSG(__hwnd, __msgId, __wParam, __lParam) SendMessageW((__hwnd), (__msgId), (__wParam), (__lParam))
#endif // __cplusplus
#define SENDWAIPC(__ipcMsgId, __param) SENDMSG(hMainWindow, WM_WA_IPC, (WPARAM)(__param), (LPARAM)(__ipcMsgId))
#ifndef OIC_WARNING
#define OIC_WARNING 32515
#endif
#define SECDLG_PROP L"SecurityPromptProp"
#ifndef IDC_HELPLINK
#define IDC_HELPLINK 10000
#endif
typedef struct __SECDLGCREATEPARAM
{
HWND hCenter;
LPCWSTR pszCaption;
LPCWSTR pszTitle;
LPCWSTR pszMessage;
UINT flags;
} SECDLGCREATEPARAM;
typedef struct __SECDLG
{
HFONT titleFont;
SIZE minSize;
SIZE maxSize;
} SECDLG;
#define GetDialog(__hwnd) ((SECDLG*)GetPropW((__hwnd), SECDLG_PROP))
static INT_PTR CALLBACK SecurityPrompt_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static HWND SecurityPrompt_GetPlayerWindow()
{
return (NULL != g_dialog_box_parent) ? g_dialog_box_parent : hMainWindow;
}
INT_PTR JSAPI2_SecurityPrompt(HWND hParent, LPCWSTR pszCaption, LPCWSTR pszTitle, LPCWSTR pszMessage, UINT flags)
{
SECDLGCREATEPARAM param;
ZeroMemory(¶m, sizeof(SECDLGCREATEPARAM));
param.hCenter = hParent;
param.flags = flags;
param.pszCaption = pszCaption;
param.pszTitle = pszTitle;
param.pszMessage = pszMessage;
if (NULL == hParent)
hParent = SecurityPrompt_GetPlayerWindow();
return LPDialogBoxParamW(IDD_JSAPI2_AUTHORIZATION2, hParent, SecurityPrompt_DialogProc, (LPARAM)¶m);
}
static BOOL SecurityPrompt_GetCenterRect(HWND hCenter, RECT *centerRect, BOOL fUseMonitor)
{
if (NULL == centerRect)
return FALSE;
HWND hDesktop = GetDesktopWindow();
HWND hTest = hCenter;
while(NULL != hTest)
{
DWORD windowStyle = GetWindowLongPtrW(hTest, GWL_STYLE);
if (WS_VISIBLE != ((WS_VISIBLE | WS_MINIMIZE) & windowStyle))
{
hTest = NULL;
hCenter = NULL;
}
else
{
hTest = GetParent(hTest);
}
}
if (FALSE != fUseMonitor || NULL == hCenter || !GetWindowRect(hCenter, centerRect))
{
MONITORINFO mi;
mi.cbSize = sizeof(MONITORINFO);
if (NULL == hCenter)
{
hCenter = SecurityPrompt_GetPlayerWindow();
if (NULL != hCenter)
{
DWORD windowStyle = GetWindowLongPtrW(hCenter, GWL_STYLE);
if (WS_VISIBLE != ((WS_VISIBLE | WS_MINIMIZE) & windowStyle))
hCenter = NULL;
}
}
HMONITOR hMonitor = MonitorFromWindow(hCenter,
(NULL != hCenter) ? MONITOR_DEFAULTTONEAREST : MONITOR_DEFAULTTOPRIMARY);
if (NULL != hMonitor && GetMonitorInfo(hMonitor, &mi))
{
CopyRect(centerRect, &mi.rcWork);
}
else
{
if (NULL == hDesktop || !GetWindowRect(hDesktop, centerRect))
return FALSE;
}
}
return TRUE;
}
static void SecurityPrompt_CenterDialog(HWND hwnd, HWND hCenter)
{
if (NULL == hwnd)
return;
RECT centerRect, windowRect;
if (!GetWindowRect(hwnd, &windowRect) ||
!SecurityPrompt_GetCenterRect(hCenter, ¢erRect, FALSE))
{
return;
}
windowRect.left = centerRect.left + ((centerRect.right - centerRect.left) - (windowRect.right - windowRect.left))/2;
windowRect.top = centerRect.top + ((centerRect.bottom - centerRect.top) - (windowRect.bottom - windowRect.top))/2;
SetWindowPos(hwnd, NULL, windowRect.left, windowRect.top, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
}
static void SecurityPrompt_CalculateMinMax(HWND hwnd, HWND hCenter)
{
SECDLG *psd = GetDialog(hwnd);
if (NULL == hwnd || NULL == psd) return;
RECT centerRect, windowRect;
if (GetWindowRect(hwnd, &windowRect))
{
psd->minSize.cx = windowRect.right - windowRect.left;
psd->minSize.cy = windowRect.bottom - windowRect.top;
}
if (SecurityPrompt_GetCenterRect(hCenter, ¢erRect, TRUE))
{
InflateRect(¢erRect, -16, -16);
psd->maxSize.cx = centerRect.right - centerRect.left;
psd->maxSize.cy = centerRect.bottom - centerRect.top;
if (psd->maxSize.cx > 360)
psd->maxSize.cx = 360;
}
}
static void SecurityPrompt_LoadIcon(HWND hwnd, HINSTANCE hInstance, LPCWSTR pszIcon)
{
HWND hControl = GetDlgItem(hwnd, IDC_MESSAGEICON);
if (NULL == hControl) return;
SendMessageW(hControl, WM_SETREDRAW, FALSE, 0L);
HICON hIcon = (HICON)LoadImageW(hInstance, pszIcon, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_SHARED | LR_DEFAULTSIZE);
HICON hPrevious = (HICON)SendMessageW(hControl, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
if (NULL != hPrevious)
DeleteObject(hPrevious);
if (NULL != hIcon)
{
hPrevious = (HICON)SendMessageW(hControl, STM_GETIMAGE, IMAGE_ICON, 0L);
if (hPrevious != hIcon)
DeleteObject(hIcon);
}
SendMessageW(hControl, WM_SETREDRAW, TRUE, 0L);
if (0 != ShowWindow(hControl, (NULL != hIcon) ? SW_SHOWNA : SW_HIDE))
InvalidateRect(hControl, NULL, TRUE);
}
static BOOL SecurityPrompt_GetWindowTextSize(HWND hwnd, SIZE *pSize, BOOL fMultiline, LONG lineWidth)
{
if (NULL == pSize) return FALSE;
INT cchLen = GetWindowTextLengthW(hwnd);
if (0 == cchLen)
{
ZeroMemory(pSize, sizeof(SIZE));
return TRUE;
}
cchLen++;
LPWSTR pszText = NULL;
WCHAR szBuffer[1024] = {0};
if (cchLen > ARRAYSIZE(szBuffer))
{
pszText = (LPWSTR)calloc(cchLen, sizeof(WCHAR));
if (NULL == pszText) return FALSE;
}
else
{
pszText = szBuffer;
cchLen = ARRAYSIZE(szBuffer);
}
BOOL resultOk = FALSE;
cchLen = GetWindowTextW(hwnd, pszText, cchLen);
if (0 != cchLen)
{
HDC hdc = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_NORESETATTRS);
if (NULL != hdc)
{
HFONT hf = (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0L);
HFONT originalFont = (HFONT)SelectObject(hdc, hf);
if (FALSE == fMultiline)
{
resultOk = GetTextExtentPoint32W(hdc, pszText, cchLen, pSize);
}
else
{
RECT textRect;
SetRect(&textRect, 0, 0, lineWidth, 0);
INT h = DrawTextW(hdc, pszText, cchLen, &textRect, DT_CALCRECT | DT_NOPREFIX | DT_NOCLIP | DT_WORDBREAK);
resultOk = (0 != h);
if (resultOk)
{
pSize->cx = textRect.right - textRect.left;
pSize->cy = textRect.bottom - textRect.top;
}
}
SelectObject(hdc, originalFont);
ReleaseDC(hwnd, hdc);
}
}
if (pszText != szBuffer)
free(pszText);
return resultOk;
}
static LONG SecurityPrompt_CalculateFooterHeight(HWND hwnd, LONG marginCY)
{
RECT rect;
HWND hControl;
LONG height = 0;
if (NULL != (hControl = GetDlgItem(hwnd, IDC_BUTTON_ALLOW)) &&
0 != (WS_VISIBLE & GetWindowLongPtrW(hControl, GWL_STYLE)) &&
GetWindowRect(hControl, &rect))
{
height += (rect.bottom - rect.top);
}
if (0 == height &&
NULL != (hControl = GetDlgItem(hwnd, IDC_BUTTON_DENY)) &&
0 != (WS_VISIBLE & GetWindowLongPtrW(hControl, GWL_STYLE)) &&
GetWindowRect(hControl, &rect))
{
height += (rect.bottom - rect.top);
}
INT szCtrl[] = {IDC_APPLYTOALL, IDC_SEPARATOR, IDC_HELPTEXT, };
for (INT i = 0; i < ARRAYSIZE(szCtrl); i++)
{
if (NULL != (hControl = GetDlgItem(hwnd, szCtrl[i])) &&
0 != (WS_VISIBLE & GetWindowLongPtrW(hControl, GWL_STYLE)) &&
GetWindowRect(hControl, &rect))
{
LONG h = (rect.bottom - rect.top);
if (h > 0)
{
if (height > 0) height += marginCY;
height += h;
}
}
}
if (0 != height)
height += 2*marginCY;
return height;
}
static void SecurityPrompt_UpdateLayout(HWND hwnd, BOOL fRedraw)
{
SECDLG *psd = GetDialog(hwnd);
if (NULL == hwnd || NULL == psd) return;
HWND hControl;
RECT rect;
LONG marginCX, marginCY;
SIZE clientSize, iconSize, titleSize, messageSize;
ZeroMemory(&clientSize, sizeof(SIZE));
SetRect(&rect, 6, 6, 6, 6);
if (MapDialogRect(hwnd, &rect))
{
marginCX = rect.left;
marginCY = rect.top;
}
else
{
marginCX = 12;
marginCY = 12;
}
if (NULL != (hControl = GetDlgItem(hwnd, IDC_MESSAGEICON)) &&
0 != (WS_VISIBLE & GetWindowLongPtrW(hControl, GWL_STYLE)) &&
GetWindowRect(hControl, &rect))
{
MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&rect, 2);
iconSize.cx = rect.right - rect.left;
iconSize.cy = rect.bottom - rect.top;
}
else
{
ZeroMemory(&iconSize, sizeof(SIZE));
}
if (NULL == (hControl = GetDlgItem(hwnd, IDC_TITLE)) ||
0 == (WS_VISIBLE & GetWindowLongPtrW(hControl, GWL_STYLE)) ||
FALSE == SecurityPrompt_GetWindowTextSize(hControl, &titleSize, FALSE, 0))
{
ZeroMemory(&titleSize, sizeof(SIZE));
}
if (NULL == (hControl = GetDlgItem(hwnd, IDC_MESSAGE)) ||
0 == (WS_VISIBLE & GetWindowLongPtrW(hControl, GWL_STYLE)) ||
FALSE == SecurityPrompt_GetWindowTextSize(hControl, &messageSize, TRUE, psd->maxSize.cx - (iconSize.cx + marginCX * 3)))
{
ZeroMemory(&messageSize, sizeof(SIZE));
}
clientSize.cx = iconSize.cx;
if (messageSize.cx > 0)
{
clientSize.cx += messageSize.cx;
if (iconSize.cx > 0) clientSize.cx += marginCX;
}
if (titleSize.cx > clientSize.cx)
titleSize.cx = clientSize.cx;
clientSize.cx += 2*marginCX;
clientSize.cy = titleSize.cy;
LONG h1 = messageSize.cy;
if (h1 > 0) h1 += 2 * marginCY;
LONG h2 = iconSize.cy;
if (h2 > 0) h2 += marginCY;
clientSize.cy += (h1 > h2) ? h1 : h2;
if (clientSize.cy > 0)
{
if (clientSize.cy != titleSize.cy && 0 != titleSize.cy)
clientSize.cy += marginCY;
}
clientSize.cy += SecurityPrompt_CalculateFooterHeight(hwnd, marginCY);
DWORD windowStyle = GetWindowLongPtrW(hwnd, GWL_STYLE);
DWORD windowExStyle = GetWindowLongPtrW(hwnd, GWL_EXSTYLE);
SetRect(&rect, 0, 0, clientSize.cx, clientSize.cy);
if (AdjustWindowRectEx(&rect, windowStyle, FALSE, windowExStyle))
{
clientSize.cx = rect.right - rect.left;
clientSize.cy = rect.bottom - rect.top;
}
if (clientSize.cx < psd->minSize.cx) clientSize.cx = psd->minSize.cx;
if (clientSize.cy < psd->minSize.cy) clientSize.cy = psd->minSize.cy;
SetWindowPos(hwnd, NULL, 0, 0, clientSize.cx, clientSize.cy, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
RECT clientRect;
if (!GetClientRect(hwnd, &clientRect))
SetRectEmpty(&clientRect);
else
InflateRect(&clientRect, -marginCX, -marginCY);
if (NULL != (hControl = GetDlgItem(hwnd, IDC_TITLE)))
{
SetWindowPos(hControl, NULL, clientRect.left, clientRect.top, clientRect.right - clientRect.left, titleSize.cy, SWP_NOZORDER | SWP_NOACTIVATE);
}
if (NULL != (hControl = GetDlgItem(hwnd, IDC_MESSAGEICON)))
{
LONG y = clientRect.top;
if (titleSize.cy > 0) y += (titleSize.cy + marginCY);
SetWindowPos(hControl, NULL, clientRect.left, y, iconSize.cx, iconSize.cy, SWP_NOZORDER | SWP_NOACTIVATE);
}
if (NULL != (hControl = GetDlgItem(hwnd, IDC_MESSAGE)))
{
LONG x = clientRect.left;
if (iconSize.cx > 0) x += (iconSize.cx + marginCX);
LONG y = clientRect.top;
if (titleSize.cy > 0) y += (titleSize.cy + marginCY);
SetWindowPos(hControl, NULL, x, y, clientRect.right - x, messageSize.cy, SWP_NOZORDER | SWP_NOACTIVATE);
}
HWND hHelp;
hHelp = GetDlgItem(hwnd, IDC_HELPTEXT);
if (NULL == hHelp || !GetWindowRect(hHelp, &rect))
SetRectEmpty(&rect);
else
MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&rect, 2);
SIZE linkSize;
LONG bottomLine = clientRect.bottom;
if (NULL != (hControl = GetDlgItem(hwnd, IDC_HELPLINK)) &&
CommandLink_GetIdealSize(hControl, &linkSize))
{
RECT margins;
if (!CommandLink_GetMargins(hControl, &margins))
SetRectEmpty(&margins);
if (linkSize.cy > 0)
{
bottomLine -= (linkSize.cy - margins.bottom);
}
SetWindowPos(hControl, NULL, clientRect.left - margins.left, bottomLine, linkSize.cx, linkSize.cy, SWP_NOACTIVATE | SWP_NOZORDER);
if (NULL != hHelp)
{
LONG x = clientRect.left + linkSize.cx - margins.right;
LONG cy = rect.bottom - rect.top;
SetWindowPos(hHelp, NULL, x, clientRect.bottom - cy, clientRect.right - x, cy, SWP_NOZORDER | SWP_NOACTIVATE);
}
}
if (NULL != (hControl = GetDlgItem(hwnd, IDC_SEPARATOR)) &&
0 != (WS_VISIBLE & GetWindowLongPtrW(hControl, GWL_STYLE)) &&
GetWindowRect(hControl, &rect))
{
bottomLine -= (marginCY + (rect.bottom - rect.top));
SetWindowPos(hControl, NULL, 0, bottomLine, clientRect.right - clientRect.left + 2*marginCX + 2, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOACTIVATE);
}
if (NULL != (hControl = GetDlgItem(hwnd, IDC_APPLYTOALL)) &&
0 != (WS_VISIBLE & GetWindowLongPtrW(hControl, GWL_STYLE)) &&
GetWindowRect(hControl, &rect))
{
bottomLine -= (marginCY + (rect.bottom - rect.top));
SetWindowPos(hControl, NULL, clientRect.left, bottomLine, clientRect.right - clientRect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOACTIVATE);
}
LONG buttonRight = clientRect.right;
if (NULL != (hControl = GetDlgItem(hwnd, IDC_BUTTON_DENY)) &&
0 != (WS_VISIBLE & GetWindowLongPtrW(hControl, GWL_STYLE)) &&
GetWindowRect(hControl, &rect))
{
SetWindowPos(hControl, NULL, buttonRight - (rect.right - rect.left), bottomLine - (marginCY + (rect.bottom - rect.top)),
rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOACTIVATE);
if (rect.right > rect.left)
{
buttonRight -= ((rect.right - rect.left) + marginCX);
}
}
if (NULL != (hControl = GetDlgItem(hwnd, IDC_BUTTON_ALLOW)) &&
0 != (WS_VISIBLE & GetWindowLongPtrW(hControl, GWL_STYLE)) &&
GetWindowRect(hControl, &rect))
{
SetWindowPos(hControl, NULL, buttonRight - (rect.right - rect.left), bottomLine - (marginCY + (rect.bottom - rect.top)),
rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOACTIVATE);
}
}
static HFONT SecurityPrompt_GetTitleFont(HWND hwnd)
{
SECDLG *psd = GetDialog(hwnd);
if (NULL == psd)
return (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0L);
if (NULL != psd->titleFont)
return psd->titleFont;
LOGFONTW lf;
ZeroMemory(&lf, sizeof(LOGFONTW));
HFONT hf = (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0L);
if (NULL != hf)
GetObjectW(hf, sizeof(LOGFONTW), &lf);
if (L'\0' == lf.lfFaceName[0])
{
if (!SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(LOGFONTW), &lf, 0) ||
FAILED(StringCchCopyW(lf.lfFaceName, ARRAYSIZE(lf.lfFaceName), L"MS Shell Dlg 2")))
{
lf.lfFaceName[0] = L'\0';
}
}
if (L'\0' != lf.lfFaceName[0])
{
lf.lfWeight = FW_SEMIBOLD;
psd->titleFont = CreateFontIndirectW(&lf);
}
return psd->titleFont;
}
static BOOL SecurityPrompt_ShowHelp(HWND hwnd)
{
INT result = (INT)(INT_PTR)ShellExecuteW(hwnd, L"open",
L"https://help.winamp.com/hc/articles/8112753225364-Online-Services-Security",
NULL, NULL, SW_SHOWNORMAL);
return (result > 32);
}
static INT_PTR SecurityPrompt_OnInitDialog(HWND hwnd, HWND hFocus, LPARAM param)
{
SECDLGCREATEPARAM *createParam = (SECDLGCREATEPARAM*)param;
if (NULL == createParam) return 0;
SECDLG *psd = (SECDLG*)calloc(1, sizeof(SECDLG));
if (NULL != psd)
{
if (!SetPropW(hwnd, SECDLG_PROP, psd))
{
free(psd);
psd = NULL;
}
}
HMENU hMenu = GetSystemMenu(hwnd, FALSE);
if (NULL != hMenu)
{
EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND|MF_DISABLED);
DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
DeleteMenu(hMenu, SC_SIZE, MF_BYCOMMAND);
}
SecurityPrompt_LoadIcon(hwnd, NULL, MAKEINTRESOURCEW(OIC_WARNING));
WCHAR szBuffer[4096] = {0};
LPCWSTR pszText;
HWND hControl;
SecurityPrompt_CalculateMinMax(hwnd, createParam->hCenter);
if (NULL != (pszText = createParam->pszCaption) && IS_INTRESOURCE(pszText))
pszText = getStringW((INT)(INT_PTR)pszText, szBuffer, ARRAYSIZE(szBuffer));
if (NULL != pszText && L'\0' != *pszText)
SetWindowTextW(hwnd, pszText);
if (NULL != (hControl = GetDlgItem(hwnd, IDC_TITLE)))
{
if (NULL != (pszText = createParam->pszTitle) && IS_INTRESOURCE(pszText))
pszText = getStringW((INT)(INT_PTR)pszText, szBuffer, ARRAYSIZE(szBuffer));
HFONT hf = SecurityPrompt_GetTitleFont(hwnd);
if (NULL != hf) SendMessageW(hControl, WM_SETFONT, (WPARAM)hf, 0L);
SetWindowTextW(hControl, pszText);
ShowWindow(hControl, (NULL != pszText && L'\0' != *pszText) ? SW_SHOWNA : SW_HIDE);
}
if (NULL != (hControl = GetDlgItem(hwnd, IDC_MESSAGE)))
{
if (NULL != (pszText = createParam->pszMessage) && IS_INTRESOURCE(pszText))
pszText = getStringW((INT)(INT_PTR)pszText, szBuffer, ARRAYSIZE(szBuffer));
SetWindowTextW(hControl, pszText);
ShowWindow(hControl, (NULL != pszText && L'\0' != *pszText) ? SW_SHOWNA : SW_HIDE);
}
getStringW(IDS_CLICKHERE, szBuffer, ARRAYSIZE(szBuffer));
HWND hLink = CreateWindowExW(WS_EX_NOPARENTNOTIFY, NWC_COMMANDLINKW, szBuffer,
WS_VISIBLE | WS_CHILD | WS_TABSTOP | /*CLS_HOTTRACK | */CLS_DEFAULTCOLORS | CLS_ALWAYSUNDERLINE,
0, 0, 0, 0, hwnd, (HMENU)IDC_HELPLINK, hMainInstance, NULL);
if (NULL != hLink)
{
if (NULL != (hControl = GetDlgItem(hwnd, IDC_APPLYTOALL)))
SetWindowPos(hLink, hControl, 0, 0, 0, 0, SWP_NOACTIVATE |SWP_NOSIZE | SWP_NOMOVE);
SendMessageW(hLink, WM_SETFONT, (WPARAM)SendMessageW(hwnd, WM_GETFONT, 0, 0L), 0L);
}
CheckDlgButton(hwnd, IDC_APPLYTOALL,
(0 != (JSAPI2::svc_apicreator::AUTHORIZATION_FLAG_ALWAYS_FOR_SERVICE &createParam->flags)) ?
BST_CHECKED : BST_UNCHECKED);
SecurityPrompt_UpdateLayout(hwnd, FALSE);
SecurityPrompt_CenterDialog(hwnd, createParam->hCenter);
SendMessageW(hwnd, DM_REPOSITION, 0, 0L);
DWORD dialogThread = GetWindowThreadProcessId(hwnd, NULL);
DWORD parentThread = GetWindowThreadProcessId(GetParent(hwnd), NULL);
if (dialogThread != parentThread)
{
AttachThreadInput(parentThread, dialogThread, TRUE);
SetForegroundWindow(hwnd);
}
if (NULL != (hControl = GetDlgItem(hwnd, IDC_BUTTON_DENY)) &&
WS_VISIBLE == ((WS_VISIBLE | WS_DISABLED) & GetWindowLongPtrW(hControl, GWL_STYLE)) &&
PostMessageW(hwnd, WM_NEXTDLGCTL, (WPARAM)hControl, TRUE))
{
return TRUE;
}
return FALSE;
}
static void SecurityPrompt_OnDestroy(HWND hwnd)
{
SECDLG *psd = GetDialog(hwnd);
RemovePropW(hwnd, SECDLG_PROP);
DWORD dialogThread = GetWindowThreadProcessId(hwnd, NULL);
DWORD parentThread = GetWindowThreadProcessId(GetParent(hwnd), NULL);
if (dialogThread != parentThread)
{
AttachThreadInput(parentThread, dialogThread, FALSE);
}
if (NULL == psd) return;
if (NULL != psd->titleFont)
DeleteObject(psd->titleFont);
free(psd);
}
static void SecurityPrompt_OnCommand(HWND hwnd, INT commandId, INT eventId, HWND hControl)
{
switch(commandId)
{
case IDC_BUTTON_ALLOW:
case IDC_BUTTON_DENY:
if(BN_CLICKED == eventId)
{
INT_PTR result = (IDC_BUTTON_ALLOW == commandId) ?
JSAPI2::svc_apicreator::AUTHORIZATION_ALLOW :
JSAPI2::svc_apicreator::AUTHORIZATION_DENY;
result |= (BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_APPLYTOALL)) ?
JSAPI2::svc_apicreator::AUTHORIZATION_FLAG_ALWAYS_FOR_SERVICE :
JSAPI2::svc_apicreator::AUTHORIZATION_FLAG_ALWAYS;
EndDialog(hwnd, result);
}
break;
}
}
static LRESULT SecurityPrompt_OnNotify(HWND hwnd, INT controlId, NMHDR *pnmh)
{
switch(controlId)
{
case IDC_HELPLINK:
if (NM_CLICK == pnmh->code)
SecurityPrompt_ShowHelp(hwnd);
return TRUE;
}
return 0;
}
static INT_PTR CALLBACK SecurityPrompt_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG: return SecurityPrompt_OnInitDialog(hwnd, (HWND)wParam, lParam);
case WM_DESTROY: SecurityPrompt_OnDestroy(hwnd); break;
case WM_COMMAND: SecurityPrompt_OnCommand(hwnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); break;
case WM_NOTIFY: MSGRESULT(hwnd, SecurityPrompt_OnNotify(hwnd, (INT)wParam, (NMHDR*)lParam));
}
return 0;
}
|