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
|
#include "main.h"
#include "./api__ml_online.h"
#include "./resource.h"
#include <windows.h>
#include <strsafe.h>
typedef struct __MESSAGEBOX
{
HWND hParent;
LPCWSTR pszText;
LPCWSTR pszCaption;
UINT uType;
LPCWSTR pszCheck;
INT *checked;
} MESSAGEBOX;
static INT_PTR CALLBACK OmMessageBox_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
INT OmMessageBox(HWND hParent, LPCWSTR pszText, LPCWSTR pszCaption, UINT uType, LPCWSTR pszCheck, INT *checked)
{
MESSAGEBOX instance;
instance.hParent = hParent;
instance.pszText = pszText;
instance.pszCaption = pszCaption;
instance.uType = uType;
instance.pszCheck = pszCheck;
instance.checked = checked;
return (INT)WASABI_API_DIALOGBOXPARAMW(IDD_MESSAGEBOX, hParent, OmMessageBox_DialogProc, (LPARAM)&instance);
}
static void OmMessgageBox_CenterWindow(HWND hwnd, HWND hCenter)
{
if (NULL == hwnd || NULL == hCenter)
return;
RECT centerRect, windowRect;
if (!GetWindowRect(hwnd, &windowRect) || !GetWindowRect(hCenter, ¢erRect))
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 BOOL OmMessageBox_GetTextBox(HWND hwnd, LPCWSTR pszText, INT cchText, SIZE *sizeText)
{
HDC hdc = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_NORESETATTRS);
if (NULL == hdc) return FALSE;
HFONT font = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0L);
HFONT fontOrig = (HFONT)SelectObject(hdc, font);
if (cchText < 0)
cchText = lstrlen(pszText);
BOOL resultOk = GetTextExtentPoint32(hdc, pszText, cchText, sizeText);
SelectObject(hdc, fontOrig);
ReleaseDC(hwnd, hdc);
return resultOk;
}
static HICON OmMessageBox_GetIcon(UINT flags)
{
LPCWSTR iconName = NULL;
switch(0x000000F0 & flags)
{
case MB_ICONHAND: iconName = IDI_HAND; break;
case MB_ICONQUESTION: iconName = IDI_QUESTION; break;
case MB_ICONEXCLAMATION:iconName = IDI_EXCLAMATION; break;
case MB_ICONASTERISK: iconName = IDI_ASTERISK; break;
}
return (NULL != iconName) ? LoadIcon(NULL, iconName) : NULL;
}
static BOOL OmMessageBox_GetIconSize(UINT flags, SIZE *iconSize)
{
if (NULL == iconSize) return FALSE;
iconSize->cx = 0;
iconSize->cy = 0;
HICON hIcon = OmMessageBox_GetIcon(flags);
if (NULL == hIcon)
return TRUE;
ICONINFO iconInfo;
if (!GetIconInfo(hIcon, &iconInfo) || FALSE == iconInfo.fIcon)
return FALSE;
BITMAP bm;
if (NULL != iconInfo.hbmColor)
{
if (FALSE == GetObject(iconInfo.hbmColor, sizeof(BITMAP), &bm))
return FALSE;
iconSize->cx = bm.bmWidth;
iconSize->cy = bm.bmHeight;
}
else if (NULL != iconInfo.hbmMask)
{
if (FALSE == GetObject(iconInfo.hbmMask, sizeof(BITMAP), &bm))
return FALSE;
iconSize->cx = bm.bmWidth;
iconSize->cy = bm.bmHeight/2;
}
return TRUE;
}
static BOOL OmMessageBox_GetButtonSize(HWND hwnd, SIZE *buttonSize)
{
if (NULL == buttonSize)
return FALSE;
if (FALSE != SendMessage(hwnd, (0x1600 + 0x0001) /*BCM_GETIDEALSIZE*/, 0, (LPARAM)buttonSize))
return TRUE;
return FALSE;
}
static INT_PTR OmMessageBox_OnInitDialog(HWND hwnd, HWND hFocus, LPARAM lParam)
{
MESSAGEBOX *pmb = (MESSAGEBOX*)lParam;
SetWindowText(hwnd, pmb->pszCaption);
SIZE textSize;
SIZE maxSize;
MONITORINFO mi;
mi.cbSize = sizeof(MONITORINFO);
HMONITOR hMonitor = MonitorFromWindow(pmb->hParent, MONITOR_DEFAULTTONEAREST);
if (NULL != hMonitor &&
GetMonitorInfo(hMonitor, &mi))
{
RECT rcFrame;
SetRectEmpty(&rcFrame);
AdjustWindowRectEx(&rcFrame, GetWindowStyle(hwnd), FALSE, GetWindowStyleEx(hwnd));
maxSize.cx = mi.rcWork.right - mi.rcWork.left - (rcFrame.right - rcFrame.left) - 8*2;
maxSize.cy = mi.rcWork.bottom - mi.rcWork.top - (rcFrame.bottom - rcFrame.top) - 8*2;
}
else
{
maxSize.cx = 1200;
maxSize.cy = 800;
}
HWND hText = GetDlgItem(hwnd, IDC_TEXT);
if (NULL != hText)
{
if (!OmMessageBox_GetTextBox(hText, pmb->pszText, -1, &textSize))
ZeroMemory(&textSize, sizeof(SIZE));
SetWindowPos(hText, NULL, 0, 0, textSize.cx, textSize.cy, SWP_NOACTIVATE | SWP_NOZORDER);
}
else
ZeroMemory(&textSize, sizeof(SIZE));
OmMessgageBox_CenterWindow(hwnd, pmb->hParent);
SendMessage(hwnd, DM_REPOSITION, 0, 0L);
return FALSE;
}
static void OmMessageBox_OnDestroy(HWND hwnd)
{
}
static void OmMessageBox_OnCommand(HWND hwnd, INT commandId, INT eventId, HWND hControl)
{
switch(commandId)
{
case IDOK:
case IDCANCEL:
EndDialog(hwnd, commandId);
break;
}
}
static INT_PTR CALLBACK OmMessageBox_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG: return OmMessageBox_OnInitDialog(hwnd, (HWND)wParam, lParam);
case WM_DESTROY: OmMessageBox_OnDestroy(hwnd); break;
case WM_COMMAND: OmMessageBox_OnCommand(hwnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); break;
}
return 0;
}
|