1370b324cSopenharmony_ci// Windows/Control/Dialog.cpp
2370b324cSopenharmony_ci
3370b324cSopenharmony_ci#include "StdAfx.h"
4370b324cSopenharmony_ci
5370b324cSopenharmony_ci// #include "../../Windows/DLL.h"
6370b324cSopenharmony_ci
7370b324cSopenharmony_ci#ifndef _UNICODE
8370b324cSopenharmony_ci#include "../../Common/StringConvert.h"
9370b324cSopenharmony_ci#endif
10370b324cSopenharmony_ci
11370b324cSopenharmony_ci#include "Dialog.h"
12370b324cSopenharmony_ci
13370b324cSopenharmony_ciextern HINSTANCE g_hInstance;
14370b324cSopenharmony_ci#ifndef _UNICODE
15370b324cSopenharmony_ciextern bool g_IsNT;
16370b324cSopenharmony_ci#endif
17370b324cSopenharmony_ci
18370b324cSopenharmony_cinamespace NWindows {
19370b324cSopenharmony_cinamespace NControl {
20370b324cSopenharmony_ci
21370b324cSopenharmony_cistatic
22370b324cSopenharmony_ci#ifdef Z7_OLD_WIN_SDK
23370b324cSopenharmony_ci  BOOL
24370b324cSopenharmony_ci#else
25370b324cSopenharmony_ci  INT_PTR
26370b324cSopenharmony_ci#endif
27370b324cSopenharmony_ciAPIENTRY
28370b324cSopenharmony_ciDialogProcedure(HWND dialogHWND, UINT message, WPARAM wParam, LPARAM lParam)
29370b324cSopenharmony_ci{
30370b324cSopenharmony_ci  CWindow tempDialog(dialogHWND);
31370b324cSopenharmony_ci  if (message == WM_INITDIALOG)
32370b324cSopenharmony_ci    tempDialog.SetUserDataLongPtr(lParam);
33370b324cSopenharmony_ci  CDialog *dialog = (CDialog *)(tempDialog.GetUserDataLongPtr());
34370b324cSopenharmony_ci  if (dialog == NULL)
35370b324cSopenharmony_ci    return FALSE;
36370b324cSopenharmony_ci  if (message == WM_INITDIALOG)
37370b324cSopenharmony_ci    dialog->Attach(dialogHWND);
38370b324cSopenharmony_ci
39370b324cSopenharmony_ci  /* MSDN: The dialog box procedure should return
40370b324cSopenharmony_ci       TRUE  - if it processed the message
41370b324cSopenharmony_ci       FALSE - if it did not process the message
42370b324cSopenharmony_ci     If the dialog box procedure returns FALSE,
43370b324cSopenharmony_ci     the dialog manager performs the default dialog operation in response to the message.
44370b324cSopenharmony_ci  */
45370b324cSopenharmony_ci
46370b324cSopenharmony_ci  try { return BoolToBOOL(dialog->OnMessage(message, wParam, lParam)); }
47370b324cSopenharmony_ci  catch(...) { return TRUE; }
48370b324cSopenharmony_ci}
49370b324cSopenharmony_ci
50370b324cSopenharmony_cibool CDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
51370b324cSopenharmony_ci{
52370b324cSopenharmony_ci  switch (message)
53370b324cSopenharmony_ci  {
54370b324cSopenharmony_ci    case WM_INITDIALOG: return OnInit();
55370b324cSopenharmony_ci    case WM_COMMAND: return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam);
56370b324cSopenharmony_ci    case WM_NOTIFY: return OnNotify((UINT)wParam, (LPNMHDR) lParam);
57370b324cSopenharmony_ci    case WM_TIMER: return OnTimer(wParam, lParam);
58370b324cSopenharmony_ci    case WM_SIZE: return OnSize(wParam, LOWORD(lParam), HIWORD(lParam));
59370b324cSopenharmony_ci    case WM_DESTROY: return OnDestroy();
60370b324cSopenharmony_ci    case WM_HELP: OnHelp(); return true;
61370b324cSopenharmony_ci    /*
62370b324cSopenharmony_ci        OnHelp(
63370b324cSopenharmony_ci          #ifdef UNDER_CE
64370b324cSopenharmony_ci          (void *)
65370b324cSopenharmony_ci          #else
66370b324cSopenharmony_ci          (LPHELPINFO)
67370b324cSopenharmony_ci          #endif
68370b324cSopenharmony_ci          lParam);
69370b324cSopenharmony_ci        return true;
70370b324cSopenharmony_ci    */
71370b324cSopenharmony_ci    default: return false;
72370b324cSopenharmony_ci  }
73370b324cSopenharmony_ci}
74370b324cSopenharmony_ci
75370b324cSopenharmony_ci/*
76370b324cSopenharmony_cibool CDialog::OnCommand2(WPARAM wParam, LPARAM lParam)
77370b324cSopenharmony_ci{
78370b324cSopenharmony_ci  return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam);
79370b324cSopenharmony_ci}
80370b324cSopenharmony_ci*/
81370b324cSopenharmony_ci
82370b324cSopenharmony_cibool CDialog::OnCommand(unsigned code, unsigned itemID, LPARAM lParam)
83370b324cSopenharmony_ci{
84370b324cSopenharmony_ci  if (code == BN_CLICKED)
85370b324cSopenharmony_ci    return OnButtonClicked(itemID, (HWND)lParam);
86370b324cSopenharmony_ci  return false;
87370b324cSopenharmony_ci}
88370b324cSopenharmony_ci
89370b324cSopenharmony_cibool CDialog::OnButtonClicked(unsigned buttonID, HWND /* buttonHWND */)
90370b324cSopenharmony_ci{
91370b324cSopenharmony_ci  switch (buttonID)
92370b324cSopenharmony_ci  {
93370b324cSopenharmony_ci    case IDOK: OnOK(); break;
94370b324cSopenharmony_ci    case IDCANCEL: OnCancel(); break;
95370b324cSopenharmony_ci    case IDCLOSE: OnClose(); break;
96370b324cSopenharmony_ci    case IDHELP: OnHelp(); break;
97370b324cSopenharmony_ci    default: return false;
98370b324cSopenharmony_ci  }
99370b324cSopenharmony_ci  return true;
100370b324cSopenharmony_ci}
101370b324cSopenharmony_ci
102370b324cSopenharmony_ci#ifndef UNDER_CE
103370b324cSopenharmony_ci/* in win2000/win98 : monitor functions are supported.
104370b324cSopenharmony_ci   We need dynamic linking, if we want nt4/win95 support in program.
105370b324cSopenharmony_ci   Even if we compile the code with low (WINVER) value, we still
106370b324cSopenharmony_ci   want to use monitor functions. So we declare missing functions here */
107370b324cSopenharmony_ci// #if (WINVER < 0x0500)
108370b324cSopenharmony_ci#ifndef MONITOR_DEFAULTTOPRIMARY
109370b324cSopenharmony_ciextern "C" {
110370b324cSopenharmony_ciDECLARE_HANDLE(HMONITOR);
111370b324cSopenharmony_ci#define MONITOR_DEFAULTTOPRIMARY    0x00000001
112370b324cSopenharmony_citypedef struct tagMONITORINFO
113370b324cSopenharmony_ci{
114370b324cSopenharmony_ci    DWORD   cbSize;
115370b324cSopenharmony_ci    RECT    rcMonitor;
116370b324cSopenharmony_ci    RECT    rcWork;
117370b324cSopenharmony_ci    DWORD   dwFlags;
118370b324cSopenharmony_ci} MONITORINFO, *LPMONITORINFO;
119370b324cSopenharmony_ciWINUSERAPI HMONITOR WINAPI MonitorFromWindow(HWND hwnd, DWORD dwFlags);
120370b324cSopenharmony_ciWINUSERAPI BOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpmi);
121370b324cSopenharmony_ci}
122370b324cSopenharmony_ci#endif
123370b324cSopenharmony_ci#endif
124370b324cSopenharmony_ci
125370b324cSopenharmony_cistatic bool GetWorkAreaRect(RECT *rect, HWND hwnd)
126370b324cSopenharmony_ci{
127370b324cSopenharmony_ci  if (hwnd)
128370b324cSopenharmony_ci  {
129370b324cSopenharmony_ci    #ifndef UNDER_CE
130370b324cSopenharmony_ci    /* MonitorFromWindow() is supported in Win2000+
131370b324cSopenharmony_ci       MonitorFromWindow() : retrieves a handle to the display monitor that has the
132370b324cSopenharmony_ci         largest area of intersection with the bounding rectangle of a specified window.
133370b324cSopenharmony_ci       dwFlags: Determines the function's return value if the window does not intersect any display monitor.
134370b324cSopenharmony_ci         MONITOR_DEFAULTTONEAREST : Returns display that is nearest to the window.
135370b324cSopenharmony_ci         MONITOR_DEFAULTTONULL    : Returns NULL.
136370b324cSopenharmony_ci         MONITOR_DEFAULTTOPRIMARY : Returns the primary display monitor.
137370b324cSopenharmony_ci    */
138370b324cSopenharmony_ci    const HMONITOR hmon = MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY);
139370b324cSopenharmony_ci    if (hmon)
140370b324cSopenharmony_ci    {
141370b324cSopenharmony_ci      MONITORINFO mi;
142370b324cSopenharmony_ci      memset(&mi, 0, sizeof(mi));
143370b324cSopenharmony_ci      mi.cbSize = sizeof(mi);
144370b324cSopenharmony_ci      if (GetMonitorInfoA(hmon, &mi))
145370b324cSopenharmony_ci      {
146370b324cSopenharmony_ci        *rect = mi.rcWork;
147370b324cSopenharmony_ci        return true;
148370b324cSopenharmony_ci      }
149370b324cSopenharmony_ci    }
150370b324cSopenharmony_ci    #endif
151370b324cSopenharmony_ci  }
152370b324cSopenharmony_ci
153370b324cSopenharmony_ci  /* Retrieves the size of the work area on the primary display monitor.
154370b324cSopenharmony_ci     The work area is the portion of the screen not obscured
155370b324cSopenharmony_ci     by the system taskbar or by application desktop toolbars.
156370b324cSopenharmony_ci     Any DPI virtualization mode of the caller has no effect on this output. */
157370b324cSopenharmony_ci
158370b324cSopenharmony_ci  return BOOLToBool(::SystemParametersInfo(SPI_GETWORKAREA, 0, rect, 0));
159370b324cSopenharmony_ci}
160370b324cSopenharmony_ci
161370b324cSopenharmony_ci
162370b324cSopenharmony_cibool IsDialogSizeOK(int xSize, int ySize, HWND hwnd)
163370b324cSopenharmony_ci{
164370b324cSopenharmony_ci  // it returns for system font. Real font uses another values
165370b324cSopenharmony_ci  const LONG v = GetDialogBaseUnits();
166370b324cSopenharmony_ci  const int x = LOWORD(v);
167370b324cSopenharmony_ci  const int y = HIWORD(v);
168370b324cSopenharmony_ci
169370b324cSopenharmony_ci  RECT rect;
170370b324cSopenharmony_ci  GetWorkAreaRect(&rect, hwnd);
171370b324cSopenharmony_ci  const int wx = RECT_SIZE_X(rect);
172370b324cSopenharmony_ci  const int wy = RECT_SIZE_Y(rect);
173370b324cSopenharmony_ci  return
174370b324cSopenharmony_ci    xSize / 4 * x <= wx &&
175370b324cSopenharmony_ci    ySize / 8 * y <= wy;
176370b324cSopenharmony_ci}
177370b324cSopenharmony_ci
178370b324cSopenharmony_cibool CDialog::GetMargins(int margin, int &x, int &y)
179370b324cSopenharmony_ci{
180370b324cSopenharmony_ci  x = margin;
181370b324cSopenharmony_ci  y = margin;
182370b324cSopenharmony_ci  RECT rect;
183370b324cSopenharmony_ci  rect.left = 0;
184370b324cSopenharmony_ci  rect.top = 0;
185370b324cSopenharmony_ci  rect.right = margin;
186370b324cSopenharmony_ci  rect.bottom = margin;
187370b324cSopenharmony_ci  if (!MapRect(&rect))
188370b324cSopenharmony_ci    return false;
189370b324cSopenharmony_ci  x = rect.right - rect.left;
190370b324cSopenharmony_ci  y = rect.bottom - rect.top;
191370b324cSopenharmony_ci  return true;
192370b324cSopenharmony_ci}
193370b324cSopenharmony_ci
194370b324cSopenharmony_ciint CDialog::Units_To_Pixels_X(int units)
195370b324cSopenharmony_ci{
196370b324cSopenharmony_ci  RECT rect;
197370b324cSopenharmony_ci  rect.left = 0;
198370b324cSopenharmony_ci  rect.top = 0;
199370b324cSopenharmony_ci  rect.right = units;
200370b324cSopenharmony_ci  rect.bottom = units;
201370b324cSopenharmony_ci  if (!MapRect(&rect))
202370b324cSopenharmony_ci    return units * 3 / 2;
203370b324cSopenharmony_ci  return rect.right - rect.left;
204370b324cSopenharmony_ci}
205370b324cSopenharmony_ci
206370b324cSopenharmony_cibool CDialog::GetItemSizes(unsigned id, int &x, int &y)
207370b324cSopenharmony_ci{
208370b324cSopenharmony_ci  RECT rect;
209370b324cSopenharmony_ci  if (!::GetWindowRect(GetItem(id), &rect))
210370b324cSopenharmony_ci    return false;
211370b324cSopenharmony_ci  x = RECT_SIZE_X(rect);
212370b324cSopenharmony_ci  y = RECT_SIZE_Y(rect);
213370b324cSopenharmony_ci  return true;
214370b324cSopenharmony_ci}
215370b324cSopenharmony_ci
216370b324cSopenharmony_civoid CDialog::GetClientRectOfItem(unsigned id, RECT &rect)
217370b324cSopenharmony_ci{
218370b324cSopenharmony_ci  ::GetWindowRect(GetItem(id), &rect);
219370b324cSopenharmony_ci  ScreenToClient(&rect);
220370b324cSopenharmony_ci}
221370b324cSopenharmony_ci
222370b324cSopenharmony_cibool CDialog::MoveItem(unsigned id, int x, int y, int width, int height, bool repaint)
223370b324cSopenharmony_ci{
224370b324cSopenharmony_ci  return BOOLToBool(::MoveWindow(GetItem(id), x, y, width, height, BoolToBOOL(repaint)));
225370b324cSopenharmony_ci}
226370b324cSopenharmony_ci
227370b324cSopenharmony_ci
228370b324cSopenharmony_ci/*
229370b324cSopenharmony_citypedef BOOL (WINAPI * Func_DwmGetWindowAttribute)(
230370b324cSopenharmony_ci    HWND hwnd, DWORD dwAttribute, PVOID pvAttribute, DWORD cbAttribute);
231370b324cSopenharmony_ci
232370b324cSopenharmony_cistatic bool GetWindowsRect_DWM(HWND hwnd, RECT *rect)
233370b324cSopenharmony_ci{
234370b324cSopenharmony_ci  // dll load and free is too slow : 300 calls in second.
235370b324cSopenharmony_ci  NDLL::CLibrary dll;
236370b324cSopenharmony_ci  if (!dll.Load(FTEXT("dwmapi.dll")))
237370b324cSopenharmony_ci    return false;
238370b324cSopenharmony_ci  Func_DwmGetWindowAttribute f = (Func_DwmGetWindowAttribute)dll.GetProc("DwmGetWindowAttribute" );
239370b324cSopenharmony_ci  if (f)
240370b324cSopenharmony_ci  {
241370b324cSopenharmony_ci    #define MY__DWMWA_EXTENDED_FRAME_BOUNDS 9
242370b324cSopenharmony_ci    // 30000 per second
243370b324cSopenharmony_ci    RECT r;
244370b324cSopenharmony_ci    if (f(hwnd, MY__DWMWA_EXTENDED_FRAME_BOUNDS, &r, sizeof(RECT)) == S_OK)
245370b324cSopenharmony_ci    {
246370b324cSopenharmony_ci      *rect = r;
247370b324cSopenharmony_ci      return true;
248370b324cSopenharmony_ci    }
249370b324cSopenharmony_ci  }
250370b324cSopenharmony_ci  return false;
251370b324cSopenharmony_ci}
252370b324cSopenharmony_ci*/
253370b324cSopenharmony_ci
254370b324cSopenharmony_ci
255370b324cSopenharmony_cistatic bool IsRect_Small_Inside_Big(const RECT &sm, const RECT &big)
256370b324cSopenharmony_ci{
257370b324cSopenharmony_ci  return sm.left   >= big.left
258370b324cSopenharmony_ci      && sm.right  <= big.right
259370b324cSopenharmony_ci      && sm.top    >= big.top
260370b324cSopenharmony_ci      && sm.bottom <= big.bottom;
261370b324cSopenharmony_ci}
262370b324cSopenharmony_ci
263370b324cSopenharmony_ci
264370b324cSopenharmony_cistatic bool AreRectsOverlapped(const RECT &r1, const RECT &r2)
265370b324cSopenharmony_ci{
266370b324cSopenharmony_ci  return r1.left   < r2.right
267370b324cSopenharmony_ci      && r1.right  > r2.left
268370b324cSopenharmony_ci      && r1.top    < r2.bottom
269370b324cSopenharmony_ci      && r1.bottom > r2.top;
270370b324cSopenharmony_ci}
271370b324cSopenharmony_ci
272370b324cSopenharmony_ci
273370b324cSopenharmony_cistatic bool AreRectsEqual(const RECT &r1, const RECT &r2)
274370b324cSopenharmony_ci{
275370b324cSopenharmony_ci  return r1.left   == r2.left
276370b324cSopenharmony_ci      && r1.right  == r2.right
277370b324cSopenharmony_ci      && r1.top    == r2.top
278370b324cSopenharmony_ci      && r1.bottom == r2.bottom;
279370b324cSopenharmony_ci}
280370b324cSopenharmony_ci
281370b324cSopenharmony_ci
282370b324cSopenharmony_civoid CDialog::NormalizeSize(bool fullNormalize)
283370b324cSopenharmony_ci{
284370b324cSopenharmony_ci  RECT workRect;
285370b324cSopenharmony_ci  if (!GetWorkAreaRect(&workRect, *this))
286370b324cSopenharmony_ci    return;
287370b324cSopenharmony_ci  RECT rect;
288370b324cSopenharmony_ci  if (!GetWindowRect(&rect))
289370b324cSopenharmony_ci    return;
290370b324cSopenharmony_ci  int xs = RECT_SIZE_X(rect);
291370b324cSopenharmony_ci  int ys = RECT_SIZE_Y(rect);
292370b324cSopenharmony_ci
293370b324cSopenharmony_ci  // we don't want to change size using workRect, if window is outside of WorkArea
294370b324cSopenharmony_ci  if (!AreRectsOverlapped(rect, workRect))
295370b324cSopenharmony_ci    return;
296370b324cSopenharmony_ci
297370b324cSopenharmony_ci  /* here rect and workRect are overlapped, but it can be false
298370b324cSopenharmony_ci     overlapping of small shadow when window in another display. */
299370b324cSopenharmony_ci
300370b324cSopenharmony_ci  const int xsW = RECT_SIZE_X(workRect);
301370b324cSopenharmony_ci  const int ysW = RECT_SIZE_Y(workRect);
302370b324cSopenharmony_ci  if (xs <= xsW && ys <= ysW)
303370b324cSopenharmony_ci    return; // size of window is OK
304370b324cSopenharmony_ci  if (fullNormalize)
305370b324cSopenharmony_ci  {
306370b324cSopenharmony_ci    Show(SW_SHOWMAXIMIZED);
307370b324cSopenharmony_ci    return;
308370b324cSopenharmony_ci  }
309370b324cSopenharmony_ci  int x = workRect.left;
310370b324cSopenharmony_ci  int y = workRect.top;
311370b324cSopenharmony_ci  if (xs < xsW)  x += (xsW - xs) / 2;  else xs = xsW;
312370b324cSopenharmony_ci  if (ys < ysW)  y += (ysW - ys) / 2;  else ys = ysW;
313370b324cSopenharmony_ci  Move(x, y, xs, ys, true);
314370b324cSopenharmony_ci}
315370b324cSopenharmony_ci
316370b324cSopenharmony_ci
317370b324cSopenharmony_civoid CDialog::NormalizePosition()
318370b324cSopenharmony_ci{
319370b324cSopenharmony_ci  RECT workRect;
320370b324cSopenharmony_ci  if (!GetWorkAreaRect(&workRect, *this))
321370b324cSopenharmony_ci    return;
322370b324cSopenharmony_ci
323370b324cSopenharmony_ci  RECT rect2 = workRect;
324370b324cSopenharmony_ci  bool useWorkArea = true;
325370b324cSopenharmony_ci  const HWND parentHWND = GetParent();
326370b324cSopenharmony_ci
327370b324cSopenharmony_ci  if (parentHWND)
328370b324cSopenharmony_ci  {
329370b324cSopenharmony_ci    RECT workRectParent;
330370b324cSopenharmony_ci    if (!GetWorkAreaRect(&workRectParent, parentHWND))
331370b324cSopenharmony_ci      return;
332370b324cSopenharmony_ci
333370b324cSopenharmony_ci    // if windows are in different monitors, we use only workArea of current window
334370b324cSopenharmony_ci
335370b324cSopenharmony_ci    if (AreRectsEqual(workRectParent, workRect))
336370b324cSopenharmony_ci    {
337370b324cSopenharmony_ci      // RECT rect3; if (GetWindowsRect_DWM(parentHWND, &rect3)) {}
338370b324cSopenharmony_ci      CWindow wnd(parentHWND);
339370b324cSopenharmony_ci      if (wnd.GetWindowRect(&rect2))
340370b324cSopenharmony_ci      {
341370b324cSopenharmony_ci        // it's same monitor. So we try to use parentHWND rect.
342370b324cSopenharmony_ci        /* we don't want to change position, if parent window is not inside work area.
343370b324cSopenharmony_ci           In Win10 : parent window rect is 8 pixels larger for each corner than window size for shadow.
344370b324cSopenharmony_ci           In maximize mode : window is outside of workRect.
345370b324cSopenharmony_ci           if parent window is inside workRect, we will use parent window instead of workRect */
346370b324cSopenharmony_ci        if (IsRect_Small_Inside_Big(rect2, workRect))
347370b324cSopenharmony_ci          useWorkArea = false;
348370b324cSopenharmony_ci      }
349370b324cSopenharmony_ci    }
350370b324cSopenharmony_ci  }
351370b324cSopenharmony_ci
352370b324cSopenharmony_ci  RECT rect;
353370b324cSopenharmony_ci  if (!GetWindowRect(&rect))
354370b324cSopenharmony_ci    return;
355370b324cSopenharmony_ci
356370b324cSopenharmony_ci  if (useWorkArea)
357370b324cSopenharmony_ci  {
358370b324cSopenharmony_ci    // we don't want to move window, if it's already inside.
359370b324cSopenharmony_ci    if (IsRect_Small_Inside_Big(rect, workRect))
360370b324cSopenharmony_ci      return;
361370b324cSopenharmony_ci    // we don't want to move window, if it's outside of workArea
362370b324cSopenharmony_ci    if (!AreRectsOverlapped(rect, workRect))
363370b324cSopenharmony_ci      return;
364370b324cSopenharmony_ci    rect2 = workRect;
365370b324cSopenharmony_ci  }
366370b324cSopenharmony_ci
367370b324cSopenharmony_ci  {
368370b324cSopenharmony_ci    const int xs = RECT_SIZE_X(rect);
369370b324cSopenharmony_ci    const int ys = RECT_SIZE_Y(rect);
370370b324cSopenharmony_ci    const int xs2 = RECT_SIZE_X(rect2);
371370b324cSopenharmony_ci    const int ys2 = RECT_SIZE_Y(rect2);
372370b324cSopenharmony_ci    // we don't want to change position if parent is smaller.
373370b324cSopenharmony_ci    if (xs <= xs2 && ys <= ys2)
374370b324cSopenharmony_ci    {
375370b324cSopenharmony_ci      const int x = rect2.left + (xs2 - xs) / 2;
376370b324cSopenharmony_ci      const int y = rect2.top  + (ys2 - ys) / 2;
377370b324cSopenharmony_ci
378370b324cSopenharmony_ci      if (x != rect.left || y != rect.top)
379370b324cSopenharmony_ci        Move(x, y, xs, ys, true);
380370b324cSopenharmony_ci      // SetWindowPos(*this, HWND_TOP, x, y, 0, 0, SWP_NOSIZE);
381370b324cSopenharmony_ci      return;
382370b324cSopenharmony_ci    }
383370b324cSopenharmony_ci  }
384370b324cSopenharmony_ci}
385370b324cSopenharmony_ci
386370b324cSopenharmony_ci
387370b324cSopenharmony_ci
388370b324cSopenharmony_cibool CModelessDialog::Create(LPCTSTR templateName, HWND parentWindow)
389370b324cSopenharmony_ci{
390370b324cSopenharmony_ci  const HWND aHWND = CreateDialogParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
391370b324cSopenharmony_ci  if (!aHWND)
392370b324cSopenharmony_ci    return false;
393370b324cSopenharmony_ci  Attach(aHWND);
394370b324cSopenharmony_ci  return true;
395370b324cSopenharmony_ci}
396370b324cSopenharmony_ci
397370b324cSopenharmony_ciINT_PTR CModalDialog::Create(LPCTSTR templateName, HWND parentWindow)
398370b324cSopenharmony_ci{
399370b324cSopenharmony_ci  return DialogBoxParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
400370b324cSopenharmony_ci}
401370b324cSopenharmony_ci
402370b324cSopenharmony_ci#ifndef _UNICODE
403370b324cSopenharmony_ci
404370b324cSopenharmony_cibool CModelessDialog::Create(LPCWSTR templateName, HWND parentWindow)
405370b324cSopenharmony_ci{
406370b324cSopenharmony_ci  HWND aHWND;
407370b324cSopenharmony_ci  if (g_IsNT)
408370b324cSopenharmony_ci    aHWND = CreateDialogParamW(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
409370b324cSopenharmony_ci  else
410370b324cSopenharmony_ci  {
411370b324cSopenharmony_ci    AString name;
412370b324cSopenharmony_ci    LPCSTR templateNameA;
413370b324cSopenharmony_ci    if (IS_INTRESOURCE(templateName))
414370b324cSopenharmony_ci      templateNameA = (LPCSTR)templateName;
415370b324cSopenharmony_ci    else
416370b324cSopenharmony_ci    {
417370b324cSopenharmony_ci      name = GetSystemString(templateName);
418370b324cSopenharmony_ci      templateNameA = name;
419370b324cSopenharmony_ci    }
420370b324cSopenharmony_ci    aHWND = CreateDialogParamA(g_hInstance, templateNameA, parentWindow, DialogProcedure, (LPARAM)this);
421370b324cSopenharmony_ci  }
422370b324cSopenharmony_ci  if (aHWND == 0)
423370b324cSopenharmony_ci    return false;
424370b324cSopenharmony_ci  Attach(aHWND);
425370b324cSopenharmony_ci  return true;
426370b324cSopenharmony_ci}
427370b324cSopenharmony_ci
428370b324cSopenharmony_ciINT_PTR CModalDialog::Create(LPCWSTR templateName, HWND parentWindow)
429370b324cSopenharmony_ci{
430370b324cSopenharmony_ci  if (g_IsNT)
431370b324cSopenharmony_ci    return DialogBoxParamW(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
432370b324cSopenharmony_ci  AString name;
433370b324cSopenharmony_ci  LPCSTR templateNameA;
434370b324cSopenharmony_ci  if (IS_INTRESOURCE(templateName))
435370b324cSopenharmony_ci    templateNameA = (LPCSTR)templateName;
436370b324cSopenharmony_ci  else
437370b324cSopenharmony_ci  {
438370b324cSopenharmony_ci    name = GetSystemString(templateName);
439370b324cSopenharmony_ci    templateNameA = name;
440370b324cSopenharmony_ci  }
441370b324cSopenharmony_ci  return DialogBoxParamA(g_hInstance, templateNameA, parentWindow, DialogProcedure, (LPARAM)this);
442370b324cSopenharmony_ci}
443370b324cSopenharmony_ci#endif
444370b324cSopenharmony_ci
445370b324cSopenharmony_ci}}
446