|
1 // Windows/Control/Dialog.cpp |
|
2 |
|
3 #include "StdAfx.h" |
|
4 |
|
5 #ifndef _UNICODE |
|
6 #include "Common/StringConvert.h" |
|
7 #endif |
|
8 #include "Windows/Control/Dialog.h" |
|
9 |
|
10 extern HINSTANCE g_hInstance; |
|
11 #ifndef _UNICODE |
|
12 extern bool g_IsNT; |
|
13 #endif |
|
14 |
|
15 namespace NWindows { |
|
16 namespace NControl { |
|
17 |
|
18 static INT_PTR APIENTRY DialogProcedure(HWND dialogHWND, UINT message, |
|
19 WPARAM wParam, LPARAM lParam) |
|
20 { |
|
21 CWindow dialogTmp(dialogHWND); |
|
22 if (message == WM_INITDIALOG) |
|
23 dialogTmp.SetUserDataLongPtr(lParam); |
|
24 CDialog *dialog = (CDialog *)(dialogTmp.GetUserDataLongPtr()); |
|
25 if (dialog == NULL) |
|
26 return FALSE; |
|
27 if (message == WM_INITDIALOG) |
|
28 dialog->Attach(dialogHWND); |
|
29 |
|
30 return BoolToBOOL(dialog->OnMessage(message, wParam, lParam)); |
|
31 } |
|
32 |
|
33 bool CDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) |
|
34 { |
|
35 switch (message) |
|
36 { |
|
37 case WM_INITDIALOG: |
|
38 return OnInit(); |
|
39 case WM_COMMAND: |
|
40 return OnCommand(wParam, lParam); |
|
41 case WM_NOTIFY: |
|
42 return OnNotify(wParam, (LPNMHDR) lParam); |
|
43 case WM_HELP: |
|
44 { |
|
45 OnHelp((LPHELPINFO)lParam); |
|
46 return true; |
|
47 } |
|
48 case WM_TIMER: |
|
49 { |
|
50 return OnTimer(wParam, lParam); |
|
51 } |
|
52 default: |
|
53 return false; |
|
54 } |
|
55 } |
|
56 |
|
57 bool CDialog::OnCommand(WPARAM wParam, LPARAM lParam) |
|
58 { |
|
59 return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam); |
|
60 } |
|
61 |
|
62 bool CDialog::OnCommand(int code, int itemID, LPARAM lParam) |
|
63 { |
|
64 if (code == BN_CLICKED) |
|
65 return OnButtonClicked(itemID, (HWND)lParam); |
|
66 return false; |
|
67 } |
|
68 |
|
69 bool CDialog::OnButtonClicked(int buttonID, HWND buttonHWND) |
|
70 { |
|
71 switch(buttonID) |
|
72 { |
|
73 case IDOK: |
|
74 OnOK(); |
|
75 break; |
|
76 case IDCANCEL: |
|
77 OnCancel(); |
|
78 break; |
|
79 case IDHELP: |
|
80 OnHelp(); |
|
81 break; |
|
82 default: |
|
83 return false; |
|
84 } |
|
85 return true; |
|
86 } |
|
87 |
|
88 bool CModelessDialog::Create(LPCTSTR templateName, HWND parentWindow) |
|
89 { |
|
90 HWND aHWND = CreateDialogParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); |
|
91 if (aHWND == 0) |
|
92 return false; |
|
93 Attach(aHWND); |
|
94 return true; |
|
95 } |
|
96 |
|
97 INT_PTR CModalDialog::Create(LPCTSTR templateName, HWND parentWindow) |
|
98 { |
|
99 return DialogBoxParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); |
|
100 } |
|
101 |
|
102 #ifndef _UNICODE |
|
103 |
|
104 bool CModelessDialog::Create(LPCWSTR templateName, HWND parentWindow) |
|
105 { |
|
106 HWND aHWND; |
|
107 if (g_IsNT) |
|
108 aHWND = CreateDialogParamW(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); |
|
109 else |
|
110 { |
|
111 AString name; |
|
112 LPCSTR templateNameA; |
|
113 if (IS_INTRESOURCE(templateName)) |
|
114 templateNameA = (LPCSTR)templateName; |
|
115 else |
|
116 { |
|
117 name = GetSystemString(templateName); |
|
118 templateNameA = name; |
|
119 } |
|
120 aHWND = CreateDialogParamA(g_hInstance, templateNameA, parentWindow, DialogProcedure, (LPARAM)this); |
|
121 } |
|
122 if (aHWND == 0) |
|
123 return false; |
|
124 Attach(aHWND); |
|
125 return true; |
|
126 } |
|
127 |
|
128 INT_PTR CModalDialog::Create(LPCWSTR templateName, HWND parentWindow) |
|
129 { |
|
130 if (g_IsNT) |
|
131 return DialogBoxParamW(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); |
|
132 AString name; |
|
133 LPCSTR templateNameA; |
|
134 if (IS_INTRESOURCE(templateName)) |
|
135 templateNameA = (LPCSTR)templateName; |
|
136 else |
|
137 { |
|
138 name = GetSystemString(templateName); |
|
139 templateNameA = name; |
|
140 } |
|
141 return DialogBoxParamA(g_hInstance, templateNameA, parentWindow, DialogProcedure, (LPARAM)this); |
|
142 } |
|
143 #endif |
|
144 |
|
145 }} |