Merge branch 'master' of git.ucc.asn.au:/matches/honours
[matches/honours.git] / research / transmission_spectroscopy / TOF / Win32++ / include / taskdialog.h
1 // Win32++   Version 7.3\r
2 // Released: 30th November 2011\r
3 //\r
4 //      David Nash\r
5 //      email: [email protected]\r
6 //      url: https://sourceforge.net/projects/win32-framework\r
7 //\r
8 //\r
9 // Copyright (c) 2005-2011  David Nash\r
10 //\r
11 // Permission is hereby granted, free of charge, to\r
12 // any person obtaining a copy of this software and\r
13 // associated documentation files (the "Software"),\r
14 // to deal in the Software without restriction, including\r
15 // without limitation the rights to use, copy, modify,\r
16 // merge, publish, distribute, sublicense, and/or sell\r
17 // copies of the Software, and to permit persons to whom\r
18 // the Software is furnished to do so, subject to the\r
19 // following conditions:\r
20 //\r
21 // The above copyright notice and this permission notice\r
22 // shall be included in all copies or substantial portions\r
23 // of the Software.\r
24 //\r
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF\r
26 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED\r
27 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A\r
28 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT\r
29 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR\r
30 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
31 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
32 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE\r
33 // OR OTHER DEALINGS IN THE SOFTWARE.\r
34 //\r
35 ////////////////////////////////////////////////////////\r
36 \r
37 \r
38 ////////////////////////////////////////////////////////\r
39 // taskdialog.h\r
40 //  Declaration of the CTaskDialog class\r
41 \r
42 // A task dialog is a dialog box that can be used to display information \r
43 // and receive simple input from the user. Like a message box, it is \r
44 // formatted by the operating system according to parameters you set. \r
45 // However, a task dialog has many more features than a message box.\r
46 \r
47 // NOTES:  \r
48 //  Task Dialogs are only supported on Windows Vista and above.\r
49 //  Task Dialogs require XP themes enabled (use version 6 of Common Controls)\r
50 //  Task Dialogs are always modal.\r
51 \r
52 \r
53 #ifndef _WIN32XX_TASKDIALOG_H_\r
54 #define _WIN32XX_TASKDIALOG_H_\r
55 \r
56 #include "wincore.h"\r
57 \r
58 namespace Win32xx\r
59 {\r
60 \r
61         class CTaskDialog : public CWnd\r
62         {\r
63         public:\r
64                 CTaskDialog();\r
65                 virtual ~CTaskDialog() {}\r
66 \r
67                 void AddCommandControl(int nButtonID, LPCTSTR pszCaption);\r
68                 void AddRadioButton(int nRadioButtonID, LPCTSTR pszCaption);\r
69                 void AddRadioButtonGroup(int nIDRadioButtonsFirst, int nIDRadioButtonsLast);\r
70                 void ClickButton(int nButtonID) const;\r
71                 void ClickRadioButton(int nRadioButtonID) const;\r
72                 LRESULT DoModal(CWnd* pParent = NULL);\r
73                 void ElevateButton(int nButtonID, BOOL bElevated);\r
74                 void EnableButton(int nButtonID, BOOL bEnabled);\r
75                 void EnableRadioButton(int nButtonID, BOOL bEnabled);\r
76                 TASKDIALOGCONFIG GetConfig() const;\r
77                 TASKDIALOG_FLAGS GetOptions() const;\r
78                 int GetSelectedButtonID() const;\r
79                 int GetSelectedRadioButtonID() const;\r
80                 BOOL GetVerificationCheckboxState() const;\r
81                 static BOOL IsSupported();\r
82                 void NavigateTo(CTaskDialog& TaskDialog) const;\r
83                 void RemoveAllButtons();\r
84                 void RemoveAllRadioButtons();\r
85                 void Reset();\r
86                 void SetCommonButtons(TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons);\r
87                 void SetContent(LPCTSTR pszContent);\r
88                 void SetDefaultButton(int nButtonID);\r
89                 void SetDefaultRadioButton(int nRadioButtonID);\r
90                 void SetDialogWidth(UINT nWidth = 0);\r
91                 void SetExpansionArea(LPCTSTR pszExpandedInfo, LPCTSTR pszExpandedLabel = _T(""), LPCTSTR pszCollapsedLabel = _T(""));\r
92                 void SetFooterIcon(HICON hFooterIcon);\r
93                 void SetFooterIcon(LPCTSTR lpszFooterIcon);\r
94                 void SetFooterText(LPCTSTR pszFooter);\r
95                 void SetMainIcon(HICON hMainIcon);\r
96                 void SetMainIcon(LPCTSTR lpszMainIcon);\r
97                 void SetMainInstruction(LPCTSTR pszMainInstruction);\r
98                 void SetOptions(TASKDIALOG_FLAGS dwFlags);\r
99                 void SetProgressBarMarquee(BOOL bEnabled = TRUE, int nMarqueeSpeed = 0);\r
100                 void SetProgressBarPosition(int nProgressPos);\r
101                 void SetProgressBarRange(int nMinRange, int nMaxRange);\r
102                 void SetProgressBarState(int nNewState = PBST_NORMAL);\r
103                 void SetVerificationCheckbox(BOOL bChecked);\r
104                 void SetVerificationCheckboxText(LPCTSTR pszVerificationText);\r
105                 void SetWindowTitle(LPCTSTR pszWindowTitle);\r
106                 static HRESULT CALLBACK StaticTaskDialogProc(HWND hWnd, UINT uNotification, WPARAM wParam, LPARAM lParam, LONG_PTR dwRefData);\r
107                 void StoreText(std::vector<WCHAR>& vWChar, LPCTSTR pFromTChar);\r
108                 void UpdateElementText(TASKDIALOG_ELEMENTS eElement, LPCTSTR pszNewText);\r
109                 \r
110 \r
111         protected:\r
112                 // Override these functions as required\r
113                 virtual BOOL OnTDButtonClicked(int nButtonID);\r
114                 virtual void OnTDConstructed();\r
115                 virtual void OnTDCreated();\r
116                 virtual void OnTDDestroyed();\r
117                 virtual void OnTDExpandButtonClicked(BOOL bExpanded);\r
118                 virtual void OnTDHelp();\r
119                 virtual void OnTDHyperlinkClicked(LPCTSTR pszHref);\r
120                 virtual void OnTDNavigatePage();\r
121                 virtual BOOL OnTDRadioButtonClicked(int nRadioButtonID);\r
122                 virtual BOOL OnTDTimer(DWORD dwTickCount);\r
123                 virtual void OnTDVerificationCheckboxClicked(BOOL bChecked);\r
124                 virtual LRESULT TaskDialogProc(UINT uMsg, WPARAM wParam, LPARAM lParam);\r
125                 virtual LRESULT TaskDialogProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam);\r
126 \r
127         private:\r
128                 CTaskDialog(const CTaskDialog&);                                // Disable copy construction\r
129                 CTaskDialog& operator = (const CTaskDialog&);   // Disable assignment operator\r
130 \r
131                 std::vector<TASKDIALOG_BUTTON> m_vButtons;\r
132                 std::vector<TASKDIALOG_BUTTON> m_vRadioButtons;\r
133 \r
134                 std::vector< std::vector<WCHAR> > m_vButtonsText;               // A vector of WCHAR vectors\r
135                 std::vector< std::vector<WCHAR> > m_vRadioButtonsText;  // A vector of WCHAR vectors\r
136 \r
137                 std::vector<WCHAR> m_vWindowTitle;\r
138                 std::vector<WCHAR> m_vMainInstruction;\r
139                 std::vector<WCHAR> m_vContent;\r
140                 std::vector<WCHAR> m_vVerificationText;\r
141                 std::vector<WCHAR> m_vExpandedInformation;\r
142                 std::vector<WCHAR> m_vExpandedControlText;\r
143                 std::vector<WCHAR> m_vCollapsedControlText;\r
144                 std::vector<WCHAR> m_vFooter;\r
145 \r
146                 TASKDIALOGCONFIG m_tc;\r
147                 int             m_SelectedButtonID;\r
148                 int             m_SelectedRadioButtonID;\r
149                 BOOL    m_VerificationCheckboxState;\r
150         };\r
151 \r
152 }\r
153 \r
154 \r
155 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
156 \r
157 \r
158 namespace Win32xx\r
159 {\r
160 \r
161         inline CTaskDialog::CTaskDialog() : m_SelectedButtonID(0), m_SelectedRadioButtonID(0), m_VerificationCheckboxState(FALSE)\r
162         {\r
163                 ZeroMemory(&m_tc, sizeof(m_tc));\r
164                 m_tc.cbSize = sizeof(m_tc);\r
165                 m_tc.pfCallback = CTaskDialog::StaticTaskDialogProc;\r
166         }\r
167 \r
168         inline void CTaskDialog::AddCommandControl(int nButtonID, LPCTSTR pszCaption)\r
169         // Adds a command control or push button to the Task Dialog.\r
170         {\r
171                 assert (m_hWnd == NULL);\r
172 \r
173                 std::vector<WCHAR> vButtonText;\r
174                 StoreText(vButtonText, pszCaption);\r
175                 m_vButtonsText.push_back(vButtonText);  // m_vButtonsText is a vector of vector<WCHAR>'s\r
176 \r
177                 TASKDIALOG_BUTTON tdb;\r
178                 tdb.nButtonID = nButtonID;\r
179                 tdb.pszButtonText = &m_vButtonsText.back().front();\r
180 \r
181                 m_vButtons.push_back(tdb);\r
182         }\r
183 \r
184         inline void CTaskDialog::AddRadioButton(int nRadioButtonID, LPCTSTR pszCaption)\r
185         // Adds a radio button to the Task Dialog.\r
186         {\r
187                 assert (m_hWnd == NULL);\r
188 \r
189                 std::vector<WCHAR> vRadioButtonText;\r
190                 StoreText(vRadioButtonText, pszCaption);\r
191                 m_vRadioButtonsText.push_back(vRadioButtonText);        // m_vRadioButtonsText is a vector of vector<WCHAR>'s\r
192 \r
193                 TASKDIALOG_BUTTON tdb;\r
194                 tdb.nButtonID = nRadioButtonID;\r
195                 tdb.pszButtonText = &m_vRadioButtonsText.back().front();\r
196 \r
197                 m_vRadioButtons.push_back(tdb);\r
198         }\r
199 \r
200         inline void CTaskDialog::AddRadioButtonGroup(int nIDRadioButtonsFirst, int nIDRadioButtonsLast)\r
201         // Adds a range of radio buttons to the Task Dialog.\r
202         // Assumes the resource ID of the button and it's string match \r
203         {\r
204                 assert (m_hWnd == NULL);\r
205                 assert(nIDRadioButtonsFirst > 0);\r
206                 assert(nIDRadioButtonsLast > nIDRadioButtonsFirst);\r
207 \r
208                 TASKDIALOG_BUTTON tdb;\r
209                 for (int nID = nIDRadioButtonsFirst; nID <= nIDRadioButtonsLast; ++nID)\r
210                 {\r
211                         tdb.nButtonID = nID;\r
212                         tdb.pszButtonText = MAKEINTRESOURCEW(nID);\r
213                         m_vRadioButtons.push_back(tdb);                 \r
214                 }\r
215         }\r
216 \r
217         inline void CTaskDialog::ClickButton(int nButtonID) const\r
218         // Simulates the action of a button click in the Task Dialog.\r
219         {\r
220                 assert(m_hWnd);\r
221                 SendMessage(TDM_CLICK_BUTTON, (WPARAM)nButtonID, 0); \r
222         }\r
223 \r
224         inline void CTaskDialog::ClickRadioButton(int nRadioButtonID) const\r
225         // Simulates the action of a radio button click in the TaskDialog.\r
226         {\r
227                 assert(m_hWnd);\r
228                 SendMessage(TDM_CLICK_RADIO_BUTTON, (WPARAM)nRadioButtonID, 0);\r
229         }\r
230 \r
231         inline LRESULT CTaskDialog::DoModal(CWnd* pParent /* = NULL */)\r
232         // Creates and displays the Task Dialog.\r
233         {\r
234                 assert (m_hWnd == NULL);\r
235 \r
236                 m_tc.cbSize = sizeof(m_tc);\r
237                 m_tc.pButtons = m_vButtons.empty()? NULL : &m_vButtons.front();\r
238                 m_tc.cButtons = m_vButtons.size();\r
239                 m_tc.pRadioButtons = m_vRadioButtons.empty()? NULL : &m_vRadioButtons.front();\r
240                 m_tc.cRadioButtons = m_vRadioButtons.size();\r
241                 m_tc.hwndParent = pParent? pParent->GetHwnd() : NULL;\r
242 \r
243                 // Ensure this thread has the TLS index set\r
244                 TLSData* pTLSData = GetApp()->SetTlsIndex();\r
245 \r
246                 // Store the CWnd pointer in thread local storage\r
247                 pTLSData->pCWnd = this;\r
248 \r
249                 // Declare a pointer to the TaskDialogIndirect function\r
250                 HMODULE hComCtl = ::LoadLibrary(_T("COMCTL32.DLL"));\r
251                 assert(hComCtl);\r
252                 typedef HRESULT WINAPI TASKDIALOGINDIRECT(const TASKDIALOGCONFIG*, int*, int*, BOOL*);\r
253                 TASKDIALOGINDIRECT* pTaskDialogIndirect = (TASKDIALOGINDIRECT*)::GetProcAddress(hComCtl, "TaskDialogIndirect");\r
254 \r
255                 // Call TaskDialogIndirect through our function pointer\r
256                 LRESULT lr = (*pTaskDialogIndirect)(&m_tc, &m_SelectedButtonID, &m_SelectedRadioButtonID, &m_VerificationCheckboxState);\r
257 \r
258                 FreeLibrary(hComCtl);\r
259                 return lr;\r
260         }\r
261         \r
262         inline void CTaskDialog::ElevateButton(int nButtonID, BOOL bElevated)\r
263         // Adds a shield icon to indicate that the button's action requires elevated privilages. \r
264         {\r
265                 assert(m_hWnd);\r
266                 SendMessage(TDM_SET_BUTTON_ELEVATION_REQUIRED_STATE, (WPARAM)nButtonID, (LPARAM)bElevated);\r
267         }\r
268         \r
269         inline void CTaskDialog::EnableButton(int nButtonID, BOOL bEnabled)\r
270         // Enables or disables a push button in the TaskDialog.\r
271         {\r
272                 assert(m_hWnd);\r
273                 SendMessage(TDM_ENABLE_BUTTON, (WPARAM)nButtonID, (LPARAM)bEnabled);\r
274         }\r
275         inline void CTaskDialog::EnableRadioButton(int nRadioButtonID, BOOL bEnabled)\r
276         // Enables or disables a radio button in the TaskDialog.\r
277         {\r
278                 assert(m_hWnd);\r
279                 SendMessage(TDM_ENABLE_RADIO_BUTTON, (WPARAM)nRadioButtonID, (LPARAM)bEnabled);\r
280         }\r
281 \r
282         inline TASKDIALOGCONFIG CTaskDialog::GetConfig() const\r
283         // Returns the TASKDIALOGCONFIG structure for the Task Dialog.\r
284         {\r
285                 return m_tc;\r
286         }\r
287 \r
288         inline TASKDIALOG_FLAGS CTaskDialog::GetOptions() const\r
289         // Returns the Task Dialog's options. These are a combination of:\r
290         //  TDF_ENABLE_HYPERLINKS\r
291         //  TDF_USE_HICON_MAIN\r
292         //  TDF_USE_HICON_FOOTER\r
293         //  TDF_ALLOW_DIALOG_CANCELLATION\r
294         //  TDF_USE_COMMAND_LINKS\r
295         //  TDF_USE_COMMAND_LINKS_NO_ICON\r
296         //  TDF_EXPAND_FOOTER_AREA\r
297         //  TDF_EXPANDED_BY_DEFAULT\r
298         //  TDF_VERIFICATION_FLAG_CHECKED\r
299         //  TDF_SHOW_PROGRESS_BAR\r
300         //  TDF_SHOW_MARQUEE_PROGRESS_BAR\r
301         //  TDF_CALLBACK_TIMER\r
302         //  TDF_POSITION_RELATIVE_TO_WINDOW\r
303         //  TDF_RTL_LAYOUT\r
304         //  TDF_NO_DEFAULT_RADIO_BUTTON\r
305         //  TDF_CAN_BE_MINIMIZED\r
306         {\r
307                 return m_tc.dwFlags;\r
308         }\r
309 \r
310         inline int CTaskDialog::GetSelectedButtonID() const\r
311         // Returns the ID of the selected button. \r
312         {\r
313                 assert (m_hWnd == NULL);\r
314                 return m_SelectedButtonID;\r
315         }\r
316 \r
317         inline int CTaskDialog::GetSelectedRadioButtonID() const \r
318         // Returns the ID of the selected radio button.\r
319         {\r
320                 assert (m_hWnd == NULL);\r
321                 return m_SelectedRadioButtonID; \r
322         }\r
323                 \r
324         inline BOOL CTaskDialog::GetVerificationCheckboxState() const\r
325         // Returns the state of the verification check box.\r
326         {\r
327                 assert (m_hWnd == NULL);\r
328                 return m_VerificationCheckboxState;\r
329         }\r
330 \r
331         inline BOOL CTaskDialog::IsSupported()\r
332         // Returns true if TaskDialogs are supported on this system.\r
333         {\r
334                 HMODULE hModule = ::LoadLibrary(_T("COMCTL32.DLL"));\r
335                 assert(hModule);\r
336                 \r
337                 BOOL bResult = (BOOL)::GetProcAddress(hModule, "TaskDialogIndirect");\r
338                 \r
339                 ::FreeLibrary(hModule);\r
340                 return bResult;\r
341         }\r
342 \r
343         inline void CTaskDialog::NavigateTo(CTaskDialog& TaskDialog) const\r
344         // Replaces the information displayed by the task dialog.\r
345         {\r
346                 assert(m_hWnd);\r
347                 TASKDIALOGCONFIG tc = TaskDialog.GetConfig();\r
348                 SendMessage(TDM_NAVIGATE_PAGE, 0, (LPARAM)&tc);\r
349         }\r
350 \r
351         inline BOOL CTaskDialog::OnTDButtonClicked(int nButtonID)\r
352         // Called when the user selects a button or command link.\r
353         { \r
354                 UNREFERENCED_PARAMETER(nButtonID);\r
355                 \r
356                 // return TRUE to prevent the task dialog from closing\r
357                 return FALSE;\r
358         }\r
359 \r
360         inline void CTaskDialog::OnTDConstructed()\r
361         // Called when the task dialog is constructed, before it is displayed.\r
362         {}\r
363 \r
364         inline void CTaskDialog::OnTDCreated()\r
365         // Called when the task dialog is displayed.\r
366         {}\r
367         \r
368         inline void CTaskDialog::OnTDDestroyed()\r
369         // Called when the task dialog is destroyed.\r
370         {\r
371         }\r
372         \r
373         inline void CTaskDialog::OnTDExpandButtonClicked(BOOL bExpanded)\r
374         // Called when the expand button is clicked.\r
375         {\r
376                 UNREFERENCED_PARAMETER(bExpanded);\r
377         }\r
378         \r
379         inline void CTaskDialog::OnTDHelp()\r
380         // Called when the user presses F1 on the keyboard.\r
381         {}\r
382 \r
383         inline void CTaskDialog::OnTDHyperlinkClicked(LPCTSTR pszHref)\r
384         // Called when the user clicks on a hyperlink.\r
385         {\r
386                 UNREFERENCED_PARAMETER(pszHref);\r
387         }\r
388         \r
389         inline void CTaskDialog::OnTDNavigatePage()\r
390         // Called when a navigation has occurred.\r
391         {}\r
392         \r
393         inline BOOL CTaskDialog::OnTDRadioButtonClicked(int nRadioButtonID)\r
394         // Called when the user selects a radio button.\r
395         {\r
396                 UNREFERENCED_PARAMETER(nRadioButtonID);\r
397                 return TRUE; \r
398         }\r
399         \r
400         inline BOOL CTaskDialog::OnTDTimer(DWORD dwTickCount) \r
401         // Called every 200 milliseconds (aproximately) when the TDF_CALLBACK_TIMER flag is set. \r
402         {\r
403                 UNREFERENCED_PARAMETER(dwTickCount);\r
404 \r
405                 // return TRUE to reset the tick count \r
406                 return FALSE;\r
407         }\r
408         \r
409         inline void CTaskDialog::OnTDVerificationCheckboxClicked(BOOL bChecked)\r
410         // Called when the user clicks the Task Dialog verification check box.\r
411         {\r
412                 UNREFERENCED_PARAMETER(bChecked);\r
413         }\r
414 \r
415         inline void CTaskDialog::RemoveAllButtons()\r
416         // Removes all push buttons from the task dialog.\r
417         {\r
418                 assert (m_hWnd == NULL);\r
419                 m_vButtons.clear();\r
420                 m_vButtonsText.clear();\r
421         }\r
422 \r
423         inline void CTaskDialog::RemoveAllRadioButtons()\r
424         // Removes all radio buttons from the task dialog.\r
425         {\r
426                 assert (m_hWnd == NULL);\r
427                 m_vRadioButtons.clear();\r
428                 m_vRadioButtonsText.clear();\r
429         }\r
430 \r
431         inline void CTaskDialog::Reset()\r
432         // Returns the dialog to its default state.\r
433         {\r
434                 assert (m_hWnd == NULL);\r
435 \r
436                 RemoveAllButtons();\r
437                 RemoveAllRadioButtons();\r
438                 ZeroMemory(&m_tc, sizeof(m_tc));\r
439                 m_tc.cbSize = sizeof(m_tc);\r
440                 m_tc.pfCallback = CTaskDialog::StaticTaskDialogProc;\r
441 \r
442                 m_SelectedButtonID = 0;\r
443                 m_SelectedRadioButtonID = 0;\r
444                 m_VerificationCheckboxState = FALSE;\r
445 \r
446                 m_vWindowTitle.clear();\r
447                 m_vMainInstruction.clear();\r
448                 m_vContent.clear();\r
449                 m_vVerificationText.clear();\r
450                 m_vExpandedInformation.clear();\r
451                 m_vExpandedControlText.clear();\r
452                 m_vCollapsedControlText.clear();\r
453                 m_vFooter.clear();\r
454         }\r
455 \r
456         inline void CTaskDialog::SetCommonButtons(TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons)\r
457         // The dwCommonButtons parameter can be a combination of:\r
458         //      TDCBF_OK_BUTTON                 OK button\r
459         //      TDCBF_YES_BUTTON                Yes button      \r
460         //      TDCBF_NO_BUTTON                 No button\r
461         //      TDCBF_CANCEL_BUTTON             Cancel button\r
462         //      TDCBF_RETRY_BUTTON              Retry button\r
463         //      TDCBF_CLOSE_BUTTON              Close button\r
464         {\r
465                 assert (m_hWnd == NULL);\r
466                 m_tc.dwCommonButtons = dwCommonButtons; \r
467         }\r
468 \r
469         inline void CTaskDialog::SetContent(LPCTSTR pszContent)\r
470         // Sets the task dialog's primary content.\r
471         {\r
472                 StoreText(m_vContent, pszContent);\r
473                 m_tc.pszContent = &m_vContent.front(); \r
474 \r
475                 if (IsWindow())\r
476                         SendMessage(TDM_SET_ELEMENT_TEXT, (WPARAM)TDE_CONTENT, (LPARAM)(LPCWSTR)T2W(pszContent));\r
477         }\r
478 \r
479         inline void CTaskDialog::SetDefaultButton(int nButtonID) \r
480         // Sets the task dialog's default button.\r
481         // Can be either a button ID or one of the common buttons\r
482         {\r
483                 assert (m_hWnd == NULL);\r
484                 m_tc.nDefaultButton = nButtonID;\r
485         }\r
486 \r
487         inline void CTaskDialog::SetDefaultRadioButton(int nRadioButtonID) \r
488         // Sets the default radio button.\r
489         {\r
490                 assert (m_hWnd == NULL);\r
491                 m_tc.nDefaultRadioButton = nRadioButtonID;\r
492         }\r
493 \r
494         inline void CTaskDialog::SetDialogWidth(UINT nWidth /*= 0*/)\r
495         // The width of the task dialog's client area. If 0, the \r
496         // task dialog manager will calculate the ideal width.\r
497         {\r
498                 assert (m_hWnd == NULL);\r
499                 m_tc.cxWidth = nWidth;\r
500         }\r
501 \r
502         inline void CTaskDialog::SetExpansionArea(LPCTSTR pszExpandedInfo, LPCTSTR pszExpandedLabel /* = _T("")*/, LPCTSTR pszCollapsedLabel /* = _T("")*/)\r
503         // Sets the text in the expandable area of the Task Dialog.\r
504         {\r
505                 StoreText(m_vExpandedInformation, pszExpandedInfo);\r
506                 m_tc.pszExpandedInformation = &m_vExpandedInformation.front();\r
507                 \r
508                 StoreText(m_vExpandedControlText, pszExpandedLabel);\r
509                 m_tc.pszExpandedControlText = &m_vExpandedControlText.front();\r
510                 \r
511                 StoreText(m_vCollapsedControlText, pszCollapsedLabel);\r
512                 m_tc.pszCollapsedControlText = &m_vCollapsedControlText.front();\r
513 \r
514                 if (IsWindow())\r
515                         SendMessage(TDM_SET_ELEMENT_TEXT, (WPARAM)TDE_EXPANDED_INFORMATION, (LPARAM)(LPCWSTR)T2W(pszExpandedInfo));\r
516         }\r
517 \r
518         inline void CTaskDialog::SetFooterIcon(HICON hFooterIcon) \r
519         // Sets the icon that will be displayed in the Task Dialog's footer.\r
520         {\r
521                 m_tc.hFooterIcon = hFooterIcon;\r
522 \r
523                 if (IsWindow())\r
524                         SendMessage(TDM_UPDATE_ICON, (WPARAM)TDIE_ICON_FOOTER, (LPARAM)hFooterIcon);\r
525         }\r
526 \r
527         inline void CTaskDialog::SetFooterIcon(LPCTSTR lpszFooterIcon) \r
528         // Sets the icon that will be displayed in the Task Dialog's footer.\r
529         // Possible icons:\r
530         // TD_ERROR_ICON                A stop-sign icon appears in the task dialog.\r
531         // TD_WARNING_ICON              An exclamation-point icon appears in the task dialog.\r
532         // TD_INFORMATION_ICON  An icon consisting of a lowercase letter i in a circle appears in the task dialog.\r
533         // TD_SHIELD_ICON               A shield icon appears in the task dialog.\r
534         //  or a value passed via MAKEINTRESOURCE\r
535         {\r
536                 m_tc.pszFooterIcon = (LPCWSTR)lpszFooterIcon;\r
537 \r
538                 if (IsWindow())\r
539                         SendMessage(TDM_UPDATE_ICON, (WPARAM)TDIE_ICON_FOOTER, (LPARAM)lpszFooterIcon);\r
540         }\r
541 \r
542         inline void CTaskDialog::SetFooterText(LPCTSTR pszFooter)\r
543         // Sets the text that will be displayed in the Task Dialog's footer.\r
544         {\r
545                 StoreText(m_vFooter, pszFooter);\r
546                 m_tc.pszFooter = &m_vFooter.front();\r
547 \r
548                 if (IsWindow())\r
549                         SendMessage(TDM_SET_ELEMENT_TEXT, (WPARAM)TDE_FOOTER, (LPARAM)(LPCWSTR)T2W(pszFooter));\r
550         }\r
551 \r
552         inline void CTaskDialog::SetMainIcon(HICON hMainIcon) \r
553         // Sets Task Dialog's main icon.\r
554         {\r
555                 m_tc.hMainIcon = hMainIcon;\r
556 \r
557                 if (IsWindow())\r
558                         SendMessage(TDM_UPDATE_ICON, (WPARAM)TDIE_ICON_MAIN, (LPARAM)hMainIcon);\r
559         }\r
560 \r
561         inline void CTaskDialog::SetMainIcon(LPCTSTR lpszMainIcon)\r
562         // Sets Task Dialog's main icon.\r
563         // Possible icons:\r
564         // TD_ERROR_ICON                A stop-sign icon appears in the task dialog.\r
565         // TD_WARNING_ICON              An exclamation-point icon appears in the task dialog.\r
566         // TD_INFORMATION_ICON  An icon consisting of a lowercase letter i in a circle appears in the task dialog.\r
567         // TD_SHIELD_ICON               A shield icon appears in the task dialog.\r
568         //  or a value passed via MAKEINTRESOURCE\r
569         //\r
570         // Note: Some values of main icon will also generate a MessageBeep when the TaskDialog is created.\r
571         {\r
572                 m_tc.pszMainIcon = (LPCWSTR)lpszMainIcon;\r
573                 \r
574                 if (IsWindow())\r
575                         SendMessage(TDM_UPDATE_ICON, (WPARAM)TDIE_ICON_MAIN, (LPARAM)lpszMainIcon);\r
576         }\r
577 \r
578         inline void CTaskDialog::SetMainInstruction(LPCTSTR pszMainInstruction) \r
579         // Sets the Task Dialog's main instruction text.\r
580         {\r
581                 StoreText(m_vMainInstruction, pszMainInstruction);\r
582                 m_tc.pszMainInstruction = &m_vMainInstruction.front();\r
583 \r
584                 if (IsWindow())\r
585                         SendMessage(TDM_SET_ELEMENT_TEXT, (WPARAM)TDE_FOOTER, (LPARAM)(LPCWSTR)T2W(pszMainInstruction));\r
586         }\r
587 \r
588         inline void CTaskDialog::SetOptions(TASKDIALOG_FLAGS dwFlags)\r
589         // Sets the Task Dialog's options. These are a combination of:\r
590         //  TDF_ENABLE_HYPERLINKS\r
591         //  TDF_USE_HICON_MAIN\r
592         //  TDF_USE_HICON_FOOTER\r
593         //  TDF_ALLOW_DIALOG_CANCELLATION\r
594         //  TDF_USE_COMMAND_LINKS\r
595         //  TDF_USE_COMMAND_LINKS_NO_ICON\r
596         //  TDF_EXPAND_FOOTER_AREA\r
597         //  TDF_EXPANDED_BY_DEFAULT\r
598         //  TDF_VERIFICATION_FLAG_CHECKED\r
599         //  TDF_SHOW_PROGRESS_BAR\r
600         //  TDF_SHOW_MARQUEE_PROGRESS_BAR\r
601         //  TDF_CALLBACK_TIMER\r
602         //  TDF_POSITION_RELATIVE_TO_WINDOW\r
603         //  TDF_RTL_LAYOUT\r
604         //  TDF_NO_DEFAULT_RADIO_BUTTON\r
605         //  TDF_CAN_BE_MINIMIZED\r
606         {\r
607                 assert (m_hWnd == NULL);\r
608                 m_tc.dwFlags = dwFlags;\r
609         }\r
610 \r
611         inline void CTaskDialog::SetProgressBarMarquee(BOOL bEnabled /* = TRUE*/, int nMarqueeSpeed /* = 0*/) \r
612         // Starts and stops the marquee display of the progress bar, and sets the speed of the marquee.\r
613         {\r
614                 assert(m_hWnd);\r
615                 SendMessage(TDM_SET_PROGRESS_BAR_MARQUEE, (WPARAM)bEnabled, (LPARAM)nMarqueeSpeed);\r
616         }\r
617 \r
618         inline void CTaskDialog::SetProgressBarPosition(int nProgressPos) \r
619         // Sets the current position for a progress bar.\r
620         {\r
621                 assert(m_hWnd);\r
622                 SendMessage(TDM_SET_PROGRESS_BAR_POS, (WPARAM)nProgressPos, 0);\r
623         }\r
624 \r
625         inline void CTaskDialog::SetProgressBarRange(int nMinRange, int nMaxRange) \r
626         // Sets the minimum and maximum values for the hosted progress bar.\r
627         {\r
628                 assert(m_hWnd);\r
629                 SendMessage(TDM_SET_PROGRESS_BAR_RANGE, 0, MAKELPARAM(nMinRange, nMaxRange)); \r
630         }\r
631 \r
632         inline void CTaskDialog::SetProgressBarState(int nNewState /* = PBST_NORMAL*/)\r
633         // Sets the current state of the progress bar. Possible states are:\r
634         //  PBST_NORMAL\r
635         //  PBST_PAUSE\r
636         //  PBST_ERROR\r
637         {\r
638                 assert(m_hWnd);\r
639                 SendMessage(TDM_SET_PROGRESS_BAR_STATE, (WPARAM)nNewState, 0);\r
640         } \r
641 \r
642         inline void CTaskDialog::SetVerificationCheckbox(BOOL bChecked)\r
643         // Simulates a click on the verification checkbox of the Task Dialog, if it exists.\r
644         {\r
645                 assert(m_hWnd);\r
646                 SendMessage(TDM_CLICK_VERIFICATION, (WPARAM)bChecked, (LPARAM)bChecked);\r
647         }\r
648 \r
649         inline void CTaskDialog::SetVerificationCheckboxText(LPCTSTR pszVerificationText)\r
650         // Sets the text for the verification check box.\r
651         {\r
652                 assert (m_hWnd == NULL);\r
653                 StoreText(m_vVerificationText, pszVerificationText);\r
654                 m_tc.pszVerificationText = &m_vVerificationText.front();\r
655         }\r
656 \r
657         inline void CTaskDialog::SetWindowTitle(LPCTSTR pszWindowTitle)\r
658         // Sets the Task Dialog's window title.\r
659         {\r
660                 assert (m_hWnd == NULL);\r
661                 StoreText(m_vWindowTitle, pszWindowTitle);\r
662                 m_tc.pszWindowTitle = &m_vWindowTitle.front(); \r
663         }\r
664 \r
665         inline HRESULT CALLBACK CTaskDialog::StaticTaskDialogProc(HWND hWnd, UINT uNotification, WPARAM wParam, LPARAM lParam, LONG_PTR dwRefData)\r
666         // TaskDialogs direct their messages here.\r
667         {\r
668                 UNREFERENCED_PARAMETER(dwRefData);\r
669 \r
670                 assert( GetApp() );\r
671 \r
672                 try\r
673                 {\r
674                         CTaskDialog* t = (CTaskDialog*)GetApp()->GetCWndFromMap(hWnd);\r
675                         if (0 == t)\r
676                         {\r
677                                 // The CTaskDialog pointer wasn't found in the map, so add it now\r
678 \r
679                                 // Retrieve the pointer to the TLS Data\r
680                                 TLSData* pTLSData = (TLSData*)TlsGetValue(GetApp()->GetTlsIndex());\r
681                                 if (NULL == pTLSData)\r
682                                         throw CWinException(_T("Unable to get TLS"));\r
683 \r
684                                 // Retrieve pointer to CTaskDialog object from Thread Local Storage TLS\r
685                                 t = (CTaskDialog*)(pTLSData->pCWnd);\r
686                                 if (NULL == t)\r
687                                         throw CWinException(_T("Failed to route message"));\r
688 \r
689                                 pTLSData->pCWnd = NULL;\r
690 \r
691                                 // Store the CTaskDialog pointer in the HWND map\r
692                                 t->m_hWnd = hWnd;\r
693                                 t->AddToMap();\r
694                         }\r
695 \r
696                         return t->TaskDialogProc(uNotification, wParam, lParam);\r
697                 }\r
698 \r
699                 catch (const CWinException &e)\r
700                 {\r
701                         // Most CWinExceptions will end up here unless caught earlier.\r
702                         e.what();\r
703                 }\r
704 \r
705                 return 0L;\r
706 \r
707         } // LRESULT CALLBACK StaticTaskDialogProc(...)\r
708 \r
709         inline void CTaskDialog::StoreText(std::vector<WCHAR>& vWChar, LPCTSTR pFromTChar)\r
710         {\r
711                 // Stores a TChar string in a WCHAR vector\r
712 \r
713                 std::vector<TCHAR> vTChar;\r
714                 \r
715                 if (IS_INTRESOURCE(pFromTChar))         // support MAKEINTRESOURCE\r
716                 {\r
717                         CString cs = LoadString((UINT)pFromTChar);\r
718                         int len = pFromTChar? cs.GetLength() + 1 : 1;\r
719                         vTChar.assign(len, _T('\0'));\r
720                         vWChar.assign(len, _T('\0'));\r
721                         if (pFromTChar)\r
722                                 lstrcpy( &vTChar.front(), cs);\r
723                 }\r
724                 else\r
725                 {\r
726                         int len = lstrlen(pFromTChar) +1;\r
727                         vTChar.assign(len, _T('\0'));\r
728                         vWChar.assign(len, _T('\0'));   \r
729                         lstrcpy( &vTChar.front(), pFromTChar);\r
730                 }\r
731                 \r
732                 lstrcpyW(&vWChar.front(), T2W(&vTChar.front()) );\r
733         }\r
734 \r
735         inline LRESULT CTaskDialog::TaskDialogProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
736         // Handles the Task Dialog's notificaions.\r
737         {\r
738                 switch(uMsg)\r
739                 {\r
740                 case TDN_BUTTON_CLICKED:\r
741                         return OnTDButtonClicked((int)wParam);\r
742 \r
743                 case TDN_CREATED:\r
744                         OnTDCreated();\r
745                         break;\r
746                 case TDN_DESTROYED:             \r
747                         Cleanup();                      // Prepare this CWnd to be reused. \r
748                         OnTDDestroyed();\r
749                         break;\r
750                 case TDN_DIALOG_CONSTRUCTED:\r
751                         OnTDConstructed();\r
752                         break;\r
753                 case TDN_EXPANDO_BUTTON_CLICKED:\r
754                         OnTDExpandButtonClicked((BOOL)wParam);\r
755                         break;\r
756                 case TDN_HELP:\r
757                         OnTDHelp();\r
758                         break;\r
759                 case TDN_HYPERLINK_CLICKED:\r
760                         OnTDHyperlinkClicked(W2T((LPCWSTR)lParam));\r
761                         break;\r
762                 case TDN_NAVIGATED:\r
763                         OnTDNavigatePage();\r
764                         break;\r
765                 case TDN_RADIO_BUTTON_CLICKED:\r
766                         OnTDRadioButtonClicked((int)wParam);\r
767                         break;\r
768                 case TDN_TIMER:\r
769                         return OnTDTimer((DWORD)wParam);\r
770 \r
771                 case TDN_VERIFICATION_CLICKED:\r
772                         OnTDVerificationCheckboxClicked((BOOL)wParam);\r
773                         break;\r
774                 }\r
775 \r
776                 return S_OK;\r
777         }\r
778 \r
779         inline LRESULT CTaskDialog::TaskDialogProc(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
780         {\r
781                 // Override this function in your class derrived from CDialog if you wish to handle messages\r
782                 // A typical function might look like this:\r
783 \r
784                 //      switch (uMsg)\r
785                 //      {\r
786                 //      case MESSAGE1:          // Some Windows API message\r
787                 //              OnMessage1();   // A user defined function\r
788                 //              break;                  // Also do default processing\r
789                 //      case MESSAGE2:\r
790                 //              OnMessage2();\r
791                 //              return x;               // Don't do default processing, but instead return\r
792                 //                                              //  a value recommended by the Windows API documentation\r
793                 //      }\r
794 \r
795                 // Always pass unhandled messages on to TaskDialogProcDefault\r
796                 return TaskDialogProcDefault(uMsg, wParam, lParam);\r
797         }\r
798 \r
799         inline void CTaskDialog::UpdateElementText(TASKDIALOG_ELEMENTS eElement, LPCTSTR pszNewText)\r
800         // Updates a text element on the Task Dialog.\r
801         {\r
802                 assert(m_hWnd);\r
803                 SendMessage(TDM_UPDATE_ELEMENT_TEXT, (WPARAM)eElement, (LPARAM)(LPCWSTR)T2W(pszNewText));\r
804         }\r
805 \r
806 }\r
807 \r
808 \r
809 \r
810 #endif // _WIN32XX_TASKDIALOG_H_

UCC git Repository :: git.ucc.asn.au