1 // Win32++ Version 7.3
\r
2 // Released: 30th November 2011
\r
6 // url: https://sourceforge.net/projects/win32-framework
\r
9 // Copyright (c) 2005-2011 David Nash
\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
21 // The above copyright notice and this permission notice
\r
22 // shall be included in all copies or substantial portions
\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
35 ////////////////////////////////////////////////////////
\r
38 ////////////////////////////////////////////////////////
\r
40 // Declaration of the CTaskDialog class
\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
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
53 #ifndef _WIN32XX_TASKDIALOG_H_
\r
54 #define _WIN32XX_TASKDIALOG_H_
\r
56 #include "wincore.h"
\r
61 class CTaskDialog : public CWnd
\r
65 virtual ~CTaskDialog() {}
\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
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
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
128 CTaskDialog(const CTaskDialog&); // Disable copy construction
\r
129 CTaskDialog& operator = (const CTaskDialog&); // Disable assignment operator
\r
131 std::vector<TASKDIALOG_BUTTON> m_vButtons;
\r
132 std::vector<TASKDIALOG_BUTTON> m_vRadioButtons;
\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
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
146 TASKDIALOGCONFIG m_tc;
\r
147 int m_SelectedButtonID;
\r
148 int m_SelectedRadioButtonID;
\r
149 BOOL m_VerificationCheckboxState;
\r
155 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\r
161 inline CTaskDialog::CTaskDialog() : m_SelectedButtonID(0), m_SelectedRadioButtonID(0), m_VerificationCheckboxState(FALSE)
\r
163 ZeroMemory(&m_tc, sizeof(m_tc));
\r
164 m_tc.cbSize = sizeof(m_tc);
\r
165 m_tc.pfCallback = CTaskDialog::StaticTaskDialogProc;
\r
168 inline void CTaskDialog::AddCommandControl(int nButtonID, LPCTSTR pszCaption)
\r
169 // Adds a command control or push button to the Task Dialog.
\r
171 assert (m_hWnd == NULL);
\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
177 TASKDIALOG_BUTTON tdb;
\r
178 tdb.nButtonID = nButtonID;
\r
179 tdb.pszButtonText = &m_vButtonsText.back().front();
\r
181 m_vButtons.push_back(tdb);
\r
184 inline void CTaskDialog::AddRadioButton(int nRadioButtonID, LPCTSTR pszCaption)
\r
185 // Adds a radio button to the Task Dialog.
\r
187 assert (m_hWnd == NULL);
\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
193 TASKDIALOG_BUTTON tdb;
\r
194 tdb.nButtonID = nRadioButtonID;
\r
195 tdb.pszButtonText = &m_vRadioButtonsText.back().front();
\r
197 m_vRadioButtons.push_back(tdb);
\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
204 assert (m_hWnd == NULL);
\r
205 assert(nIDRadioButtonsFirst > 0);
\r
206 assert(nIDRadioButtonsLast > nIDRadioButtonsFirst);
\r
208 TASKDIALOG_BUTTON tdb;
\r
209 for (int nID = nIDRadioButtonsFirst; nID <= nIDRadioButtonsLast; ++nID)
\r
211 tdb.nButtonID = nID;
\r
212 tdb.pszButtonText = MAKEINTRESOURCEW(nID);
\r
213 m_vRadioButtons.push_back(tdb);
\r
217 inline void CTaskDialog::ClickButton(int nButtonID) const
\r
218 // Simulates the action of a button click in the Task Dialog.
\r
221 SendMessage(TDM_CLICK_BUTTON, (WPARAM)nButtonID, 0);
\r
224 inline void CTaskDialog::ClickRadioButton(int nRadioButtonID) const
\r
225 // Simulates the action of a radio button click in the TaskDialog.
\r
228 SendMessage(TDM_CLICK_RADIO_BUTTON, (WPARAM)nRadioButtonID, 0);
\r
231 inline LRESULT CTaskDialog::DoModal(CWnd* pParent /* = NULL */)
\r
232 // Creates and displays the Task Dialog.
\r
234 assert (m_hWnd == NULL);
\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
243 // Ensure this thread has the TLS index set
\r
244 TLSData* pTLSData = GetApp()->SetTlsIndex();
\r
246 // Store the CWnd pointer in thread local storage
\r
247 pTLSData->pCWnd = this;
\r
249 // Declare a pointer to the TaskDialogIndirect function
\r
250 HMODULE hComCtl = ::LoadLibrary(_T("COMCTL32.DLL"));
\r
252 typedef HRESULT WINAPI TASKDIALOGINDIRECT(const TASKDIALOGCONFIG*, int*, int*, BOOL*);
\r
253 TASKDIALOGINDIRECT* pTaskDialogIndirect = (TASKDIALOGINDIRECT*)::GetProcAddress(hComCtl, "TaskDialogIndirect");
\r
255 // Call TaskDialogIndirect through our function pointer
\r
256 LRESULT lr = (*pTaskDialogIndirect)(&m_tc, &m_SelectedButtonID, &m_SelectedRadioButtonID, &m_VerificationCheckboxState);
\r
258 FreeLibrary(hComCtl);
\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
266 SendMessage(TDM_SET_BUTTON_ELEVATION_REQUIRED_STATE, (WPARAM)nButtonID, (LPARAM)bElevated);
\r
269 inline void CTaskDialog::EnableButton(int nButtonID, BOOL bEnabled)
\r
270 // Enables or disables a push button in the TaskDialog.
\r
273 SendMessage(TDM_ENABLE_BUTTON, (WPARAM)nButtonID, (LPARAM)bEnabled);
\r
275 inline void CTaskDialog::EnableRadioButton(int nRadioButtonID, BOOL bEnabled)
\r
276 // Enables or disables a radio button in the TaskDialog.
\r
279 SendMessage(TDM_ENABLE_RADIO_BUTTON, (WPARAM)nRadioButtonID, (LPARAM)bEnabled);
\r
282 inline TASKDIALOGCONFIG CTaskDialog::GetConfig() const
\r
283 // Returns the TASKDIALOGCONFIG structure for the Task Dialog.
\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
304 // TDF_NO_DEFAULT_RADIO_BUTTON
\r
305 // TDF_CAN_BE_MINIMIZED
\r
307 return m_tc.dwFlags;
\r
310 inline int CTaskDialog::GetSelectedButtonID() const
\r
311 // Returns the ID of the selected button.
\r
313 assert (m_hWnd == NULL);
\r
314 return m_SelectedButtonID;
\r
317 inline int CTaskDialog::GetSelectedRadioButtonID() const
\r
318 // Returns the ID of the selected radio button.
\r
320 assert (m_hWnd == NULL);
\r
321 return m_SelectedRadioButtonID;
\r
324 inline BOOL CTaskDialog::GetVerificationCheckboxState() const
\r
325 // Returns the state of the verification check box.
\r
327 assert (m_hWnd == NULL);
\r
328 return m_VerificationCheckboxState;
\r
331 inline BOOL CTaskDialog::IsSupported()
\r
332 // Returns true if TaskDialogs are supported on this system.
\r
334 HMODULE hModule = ::LoadLibrary(_T("COMCTL32.DLL"));
\r
337 BOOL bResult = (BOOL)::GetProcAddress(hModule, "TaskDialogIndirect");
\r
339 ::FreeLibrary(hModule);
\r
343 inline void CTaskDialog::NavigateTo(CTaskDialog& TaskDialog) const
\r
344 // Replaces the information displayed by the task dialog.
\r
347 TASKDIALOGCONFIG tc = TaskDialog.GetConfig();
\r
348 SendMessage(TDM_NAVIGATE_PAGE, 0, (LPARAM)&tc);
\r
351 inline BOOL CTaskDialog::OnTDButtonClicked(int nButtonID)
\r
352 // Called when the user selects a button or command link.
\r
354 UNREFERENCED_PARAMETER(nButtonID);
\r
356 // return TRUE to prevent the task dialog from closing
\r
360 inline void CTaskDialog::OnTDConstructed()
\r
361 // Called when the task dialog is constructed, before it is displayed.
\r
364 inline void CTaskDialog::OnTDCreated()
\r
365 // Called when the task dialog is displayed.
\r
368 inline void CTaskDialog::OnTDDestroyed()
\r
369 // Called when the task dialog is destroyed.
\r
373 inline void CTaskDialog::OnTDExpandButtonClicked(BOOL bExpanded)
\r
374 // Called when the expand button is clicked.
\r
376 UNREFERENCED_PARAMETER(bExpanded);
\r
379 inline void CTaskDialog::OnTDHelp()
\r
380 // Called when the user presses F1 on the keyboard.
\r
383 inline void CTaskDialog::OnTDHyperlinkClicked(LPCTSTR pszHref)
\r
384 // Called when the user clicks on a hyperlink.
\r
386 UNREFERENCED_PARAMETER(pszHref);
\r
389 inline void CTaskDialog::OnTDNavigatePage()
\r
390 // Called when a navigation has occurred.
\r
393 inline BOOL CTaskDialog::OnTDRadioButtonClicked(int nRadioButtonID)
\r
394 // Called when the user selects a radio button.
\r
396 UNREFERENCED_PARAMETER(nRadioButtonID);
\r
400 inline BOOL CTaskDialog::OnTDTimer(DWORD dwTickCount)
\r
401 // Called every 200 milliseconds (aproximately) when the TDF_CALLBACK_TIMER flag is set.
\r
403 UNREFERENCED_PARAMETER(dwTickCount);
\r
405 // return TRUE to reset the tick count
\r
409 inline void CTaskDialog::OnTDVerificationCheckboxClicked(BOOL bChecked)
\r
410 // Called when the user clicks the Task Dialog verification check box.
\r
412 UNREFERENCED_PARAMETER(bChecked);
\r
415 inline void CTaskDialog::RemoveAllButtons()
\r
416 // Removes all push buttons from the task dialog.
\r
418 assert (m_hWnd == NULL);
\r
419 m_vButtons.clear();
\r
420 m_vButtonsText.clear();
\r
423 inline void CTaskDialog::RemoveAllRadioButtons()
\r
424 // Removes all radio buttons from the task dialog.
\r
426 assert (m_hWnd == NULL);
\r
427 m_vRadioButtons.clear();
\r
428 m_vRadioButtonsText.clear();
\r
431 inline void CTaskDialog::Reset()
\r
432 // Returns the dialog to its default state.
\r
434 assert (m_hWnd == NULL);
\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
442 m_SelectedButtonID = 0;
\r
443 m_SelectedRadioButtonID = 0;
\r
444 m_VerificationCheckboxState = FALSE;
\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
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
465 assert (m_hWnd == NULL);
\r
466 m_tc.dwCommonButtons = dwCommonButtons;
\r
469 inline void CTaskDialog::SetContent(LPCTSTR pszContent)
\r
470 // Sets the task dialog's primary content.
\r
472 StoreText(m_vContent, pszContent);
\r
473 m_tc.pszContent = &m_vContent.front();
\r
476 SendMessage(TDM_SET_ELEMENT_TEXT, (WPARAM)TDE_CONTENT, (LPARAM)(LPCWSTR)T2W(pszContent));
\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
483 assert (m_hWnd == NULL);
\r
484 m_tc.nDefaultButton = nButtonID;
\r
487 inline void CTaskDialog::SetDefaultRadioButton(int nRadioButtonID)
\r
488 // Sets the default radio button.
\r
490 assert (m_hWnd == NULL);
\r
491 m_tc.nDefaultRadioButton = nRadioButtonID;
\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
498 assert (m_hWnd == NULL);
\r
499 m_tc.cxWidth = nWidth;
\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
505 StoreText(m_vExpandedInformation, pszExpandedInfo);
\r
506 m_tc.pszExpandedInformation = &m_vExpandedInformation.front();
\r
508 StoreText(m_vExpandedControlText, pszExpandedLabel);
\r
509 m_tc.pszExpandedControlText = &m_vExpandedControlText.front();
\r
511 StoreText(m_vCollapsedControlText, pszCollapsedLabel);
\r
512 m_tc.pszCollapsedControlText = &m_vCollapsedControlText.front();
\r
515 SendMessage(TDM_SET_ELEMENT_TEXT, (WPARAM)TDE_EXPANDED_INFORMATION, (LPARAM)(LPCWSTR)T2W(pszExpandedInfo));
\r
518 inline void CTaskDialog::SetFooterIcon(HICON hFooterIcon)
\r
519 // Sets the icon that will be displayed in the Task Dialog's footer.
\r
521 m_tc.hFooterIcon = hFooterIcon;
\r
524 SendMessage(TDM_UPDATE_ICON, (WPARAM)TDIE_ICON_FOOTER, (LPARAM)hFooterIcon);
\r
527 inline void CTaskDialog::SetFooterIcon(LPCTSTR lpszFooterIcon)
\r
528 // Sets the icon that will be displayed in the Task Dialog's footer.
\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
536 m_tc.pszFooterIcon = (LPCWSTR)lpszFooterIcon;
\r
539 SendMessage(TDM_UPDATE_ICON, (WPARAM)TDIE_ICON_FOOTER, (LPARAM)lpszFooterIcon);
\r
542 inline void CTaskDialog::SetFooterText(LPCTSTR pszFooter)
\r
543 // Sets the text that will be displayed in the Task Dialog's footer.
\r
545 StoreText(m_vFooter, pszFooter);
\r
546 m_tc.pszFooter = &m_vFooter.front();
\r
549 SendMessage(TDM_SET_ELEMENT_TEXT, (WPARAM)TDE_FOOTER, (LPARAM)(LPCWSTR)T2W(pszFooter));
\r
552 inline void CTaskDialog::SetMainIcon(HICON hMainIcon)
\r
553 // Sets Task Dialog's main icon.
\r
555 m_tc.hMainIcon = hMainIcon;
\r
558 SendMessage(TDM_UPDATE_ICON, (WPARAM)TDIE_ICON_MAIN, (LPARAM)hMainIcon);
\r
561 inline void CTaskDialog::SetMainIcon(LPCTSTR lpszMainIcon)
\r
562 // Sets Task Dialog's main icon.
\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
570 // Note: Some values of main icon will also generate a MessageBeep when the TaskDialog is created.
\r
572 m_tc.pszMainIcon = (LPCWSTR)lpszMainIcon;
\r
575 SendMessage(TDM_UPDATE_ICON, (WPARAM)TDIE_ICON_MAIN, (LPARAM)lpszMainIcon);
\r
578 inline void CTaskDialog::SetMainInstruction(LPCTSTR pszMainInstruction)
\r
579 // Sets the Task Dialog's main instruction text.
\r
581 StoreText(m_vMainInstruction, pszMainInstruction);
\r
582 m_tc.pszMainInstruction = &m_vMainInstruction.front();
\r
585 SendMessage(TDM_SET_ELEMENT_TEXT, (WPARAM)TDE_FOOTER, (LPARAM)(LPCWSTR)T2W(pszMainInstruction));
\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
604 // TDF_NO_DEFAULT_RADIO_BUTTON
\r
605 // TDF_CAN_BE_MINIMIZED
\r
607 assert (m_hWnd == NULL);
\r
608 m_tc.dwFlags = dwFlags;
\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
615 SendMessage(TDM_SET_PROGRESS_BAR_MARQUEE, (WPARAM)bEnabled, (LPARAM)nMarqueeSpeed);
\r
618 inline void CTaskDialog::SetProgressBarPosition(int nProgressPos)
\r
619 // Sets the current position for a progress bar.
\r
622 SendMessage(TDM_SET_PROGRESS_BAR_POS, (WPARAM)nProgressPos, 0);
\r
625 inline void CTaskDialog::SetProgressBarRange(int nMinRange, int nMaxRange)
\r
626 // Sets the minimum and maximum values for the hosted progress bar.
\r
629 SendMessage(TDM_SET_PROGRESS_BAR_RANGE, 0, MAKELPARAM(nMinRange, nMaxRange));
\r
632 inline void CTaskDialog::SetProgressBarState(int nNewState /* = PBST_NORMAL*/)
\r
633 // Sets the current state of the progress bar. Possible states are:
\r
639 SendMessage(TDM_SET_PROGRESS_BAR_STATE, (WPARAM)nNewState, 0);
\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
646 SendMessage(TDM_CLICK_VERIFICATION, (WPARAM)bChecked, (LPARAM)bChecked);
\r
649 inline void CTaskDialog::SetVerificationCheckboxText(LPCTSTR pszVerificationText)
\r
650 // Sets the text for the verification check box.
\r
652 assert (m_hWnd == NULL);
\r
653 StoreText(m_vVerificationText, pszVerificationText);
\r
654 m_tc.pszVerificationText = &m_vVerificationText.front();
\r
657 inline void CTaskDialog::SetWindowTitle(LPCTSTR pszWindowTitle)
\r
658 // Sets the Task Dialog's window title.
\r
660 assert (m_hWnd == NULL);
\r
661 StoreText(m_vWindowTitle, pszWindowTitle);
\r
662 m_tc.pszWindowTitle = &m_vWindowTitle.front();
\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
668 UNREFERENCED_PARAMETER(dwRefData);
\r
670 assert( GetApp() );
\r
674 CTaskDialog* t = (CTaskDialog*)GetApp()->GetCWndFromMap(hWnd);
\r
677 // The CTaskDialog pointer wasn't found in the map, so add it now
\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
684 // Retrieve pointer to CTaskDialog object from Thread Local Storage TLS
\r
685 t = (CTaskDialog*)(pTLSData->pCWnd);
\r
687 throw CWinException(_T("Failed to route message"));
\r
689 pTLSData->pCWnd = NULL;
\r
691 // Store the CTaskDialog pointer in the HWND map
\r
696 return t->TaskDialogProc(uNotification, wParam, lParam);
\r
699 catch (const CWinException &e)
\r
701 // Most CWinExceptions will end up here unless caught earlier.
\r
707 } // LRESULT CALLBACK StaticTaskDialogProc(...)
\r
709 inline void CTaskDialog::StoreText(std::vector<WCHAR>& vWChar, LPCTSTR pFromTChar)
\r
711 // Stores a TChar string in a WCHAR vector
\r
713 std::vector<TCHAR> vTChar;
\r
715 if (IS_INTRESOURCE(pFromTChar)) // support MAKEINTRESOURCE
\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
722 lstrcpy( &vTChar.front(), cs);
\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
732 lstrcpyW(&vWChar.front(), T2W(&vTChar.front()) );
\r
735 inline LRESULT CTaskDialog::TaskDialogProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
736 // Handles the Task Dialog's notificaions.
\r
740 case TDN_BUTTON_CLICKED:
\r
741 return OnTDButtonClicked((int)wParam);
\r
746 case TDN_DESTROYED:
\r
747 Cleanup(); // Prepare this CWnd to be reused.
\r
750 case TDN_DIALOG_CONSTRUCTED:
\r
753 case TDN_EXPANDO_BUTTON_CLICKED:
\r
754 OnTDExpandButtonClicked((BOOL)wParam);
\r
759 case TDN_HYPERLINK_CLICKED:
\r
760 OnTDHyperlinkClicked(W2T((LPCWSTR)lParam));
\r
762 case TDN_NAVIGATED:
\r
763 OnTDNavigatePage();
\r
765 case TDN_RADIO_BUTTON_CLICKED:
\r
766 OnTDRadioButtonClicked((int)wParam);
\r
769 return OnTDTimer((DWORD)wParam);
\r
771 case TDN_VERIFICATION_CLICKED:
\r
772 OnTDVerificationCheckboxClicked((BOOL)wParam);
\r
779 inline LRESULT CTaskDialog::TaskDialogProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
\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
786 // case MESSAGE1: // Some Windows API message
\r
787 // OnMessage1(); // A user defined function
\r
788 // break; // Also do default processing
\r
791 // return x; // Don't do default processing, but instead return
\r
792 // // a value recommended by the Windows API documentation
\r
795 // Always pass unhandled messages on to TaskDialogProcDefault
\r
796 return TaskDialogProcDefault(uMsg, wParam, lParam);
\r
799 inline void CTaskDialog::UpdateElementText(TASKDIALOG_ELEMENTS eElement, LPCTSTR pszNewText)
\r
800 // Updates a text element on the Task Dialog.
\r
803 SendMessage(TDM_UPDATE_ELEMENT_TEXT, (WPARAM)eElement, (LPARAM)(LPCWSTR)T2W(pszNewText));
\r
810 #endif // _WIN32XX_TASKDIALOG_H_