CTaskDialog 類別
功能像訊息方塊,但是可向使用者顯示其他資訊的快顯對話方塊。 CTaskDialog
也包含從使用者收集資訊的功能。
語法
class CTaskDialog : public CObject
成員
建構函式
名稱 | 描述 |
---|---|
CTaskDialog::CTaskDialog | 建構 CTaskDialog 物件。 |
方法
資料成員
名稱 | 描述 |
---|---|
m_aButtons |
的命令按鈕控制項 CTaskDialog 陣列。 |
m_aRadioButtons |
的選項按鈕控制項 CTaskDialog 陣列。 |
m_bVerified |
TRUE 表示已核取驗證核取方塊; FALSE 表示它不是。 |
m_footerIcon |
頁尾 CTaskDialog 中的圖示。 |
m_hWnd |
視窗的 CTaskDialog 控制碼。 |
m_mainIcon |
的主要圖示 CTaskDialog 。 |
m_nButtonDisabled |
遮罩,指出哪些通用按鈕已停用。 |
m_nButtonElevation |
表示哪些通用按鈕需要 UAC 提高許可權的遮罩。 |
m_nButtonId |
所選取命令按鈕控制項的識別碼。 |
m_nCommonButton |
遮罩,指出哪些通用按鈕會顯示在 CTaskDialog 上。 |
m_nDefaultCommandControl |
顯示 時 CTaskDialog 選取之命令按鈕控制項的識別碼。 |
m_nDefaultRadioButton |
顯示 時 CTaskDialog 所選取選項按鈕控制項的識別碼。 |
m_nFlags |
表示 選項的 CTaskDialog 遮罩。 |
m_nProgressPos |
進度列的目前位置。 這個值必須介於 m_nProgressRangeMin 和 m_nProgressRangeMax 之間。 |
m_nProgressRangeMax |
進度列的最大值。 |
m_nProgressRangeMin |
進度列的最小值。 |
m_nProgressState |
進度列的狀態。 如需詳細資訊,請參閱 CTaskDialog::SetProgressBarState 。 |
m_nRadioId |
所選選項按鈕控制項的識別碼。 |
m_nWidth |
以圖元為單位的 CTaskDialog 寬度。 |
m_strCollapse |
隱藏展開資訊時,展開方塊右邊顯示的字串 CTaskDialog 。 |
m_strContent |
的內容字串 CTaskDialog 。 |
m_strExpand |
顯示展開資訊時,展開方塊右邊顯示的字串 CTaskDialog 。 |
m_strFooter |
的頁尾 CTaskDialog 。 |
m_strInformation |
的展開資訊 CTaskDialog 。 |
m_strMainInstruction |
的主要指示 CTaskDialog 。 |
m_strTitle |
的 CTaskDialog 標題。 |
m_strVerification |
顯示在 [驗證] 核取方塊右邊的字串 CTaskDialog 。 |
備註
類別 CTaskDialog
會取代標準 Windows 訊息方塊,並具有其他功能,例如從使用者收集資訊的新控制項。 這個類別位於 Visual Studio 2010 和更新版本的 MFC 程式庫中。 CTaskDialog
從 Windows Vista 開始提供 。 舊版 Windows 無法顯示 CTaskDialog
物件。 用來 CTaskDialog::IsSupported
判斷目前使用者是否可以在執行時間顯示工作對話方塊。 仍然支援標準 Windows 訊息方塊。
CTaskDialog
只有在您使用 Unicode 程式庫建置應用程式時,才能使用 。
CTaskDialog
有兩個不同的建構函式。 一個建構函式可讓您指定兩個命令按鈕,以及最多六個一般按鈕控制項。 建立 之後 CTaskDialog
,您可以新增更多命令按鈕。 第二個建構函式不支援任何命令按鈕,但您可以新增無限數量的一般按鈕控制項。 如需建構函式的詳細資訊,請參閱 CTaskDialog::CTaskDialog 。
下圖顯示範例 CTaskDialog
,說明一些控制項的位置。
CTaskDialog 範例
需求
最低必要作業系統: Windows Vista
標頭: afxtaskdialog.h
CTaskDialog::AddCommandControl
將新的命令按鈕控制項新增至 CTaskDialog
。
void AddCommandControl(
int nCommandControlID,
const CString& strCaption,
BOOL bEnabled = TRUE,
BOOL bRequiresElevation = FALSE);
參數
nCommandControlID
[in]命令控制項識別碼。
strCaption
[in]向使用者顯示的字串 CTaskDialog
。 使用此字串來說明命令的用途。
bEnabled
[in]布林參數,指出是否啟用或停用新按鈕。
bRequiresElevation
[in]布林參數,指出命令是否需要提高許可權。
備註
CTaskDialog Class
可以顯示無限數量的命令按鈕控制項。 不過,如果 CTaskDialog
顯示任何命令按鈕控制項,則最多可以顯示六個按鈕。 CTaskDialog
如果沒有命令按鈕控制項,它可以顯示不限數量的按鈕。
當使用者選取命令按鈕控制項時,會 CTaskDialog
關閉 。 如果您的應用程式使用 CTaskDialog::D oModal 顯示對話方塊, DoModal
則會傳回 所選命令按鈕控制項的 nCommandControlID 。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title.
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
taskDialog.AddCommandControl(201, L"First command button control");
taskDialog.AddCommandControl(202, L"Second command button control");
taskDialog.AddCommandControl(203, L"Third command button control");
// Show the CTaskDialog and remember how the user closed it.
int selection = taskDialog.DoModal();
switch (selection)
{
case 201:
// TODO: Place processing here for the first
// command button control.
break;
case 202:
// TODO: Place processing here for the second
// command button control.
break;
case 203:
// TODO: Place processing here for the third
// command button control.
break;
default:
break;
}
// Remove all the command controls so that we can use the same task
// dialog with new command button controls.
taskDialog.RemoveAllCommandControls();
taskDialog.AddCommandControl(301,
L"New first command button control");
taskDialog.AddCommandControl(302,
L"New second command button control should require elevation",
TRUE, TRUE);
taskDialog.AddCommandControl(303,
L"New third command button control should be disabled");
// Change the default command button control
taskDialog.SetDefaultCommandControl(302);
// Make sure the third option is disabled.
if (taskDialog.IsCommandControlEnabled(303))
{
taskDialog.SetCommandControlOptions(303, FALSE);
}
taskDialog.DoModal();
switch (taskDialog.GetSelectedCommandControlID())
{
case 301:
// TODO: Place processing here for new first
// command button control.
break;
case 302:
// TODO: Place processing here for new second
// command button control.
break;
case 303:
// TODO: Place processing here for the new third
// command button control.
break;
default:
break;
}
// Remove all the command button controls and add new ones from
// the string table resource.
taskDialog.RemoveAllCommandControls();
taskDialog.LoadCommandControls(1001, 1005);
CTaskDialog::AddRadioButton
將選項按鈕新增至 CTaskDialog
。
void CTaskDialog::AddRadioButton(
int nRadioButtonID,
const CString& strCaption,
BOOL bEnabled = TRUE);
參數
nRadioButtonID
[in]選項按鈕的識別碼。
strCaption
[in]選項按鈕旁顯示的字串 CTaskDialog
。
bEnabled
[in]布林參數,指出是否啟用選項按鈕。
備註
CTaskDialog 類別 的選項按鈕 可讓您從使用者收集資訊。 使用 CTaskDialog::GetSelectedRadioButtonID 函數來判斷選取哪一個選項按鈕。
CTaskDialog
不需要 nRadioButtonID 參數對於每個選項按鈕而言都是唯一的。 不過,如果您未針對每個選項按鈕使用不同的識別碼,您可能會遇到非預期的行為。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
taskDialog.AddRadioButton(201, L"First option");
taskDialog.AddRadioButton(202, L"Second option");
taskDialog.AddRadioButton(203, L"Third option");
taskDialog.DoModal();
int selection = taskDialog.GetSelectedRadioButtonID();
switch (selection)
{
case 201:
// TODO: Place processing here for the first
// radio button.
break;
case 202:
// TODO: Place processing here for the second
// radio button.
break;
case 203:
// TODO: Place processing here for the third
// radio button.
break;
default:
break;
}
// Remove all the radio buttons so that we can use the same task
// dialog with new radio buttons.
taskDialog.RemoveAllRadioButtons();
taskDialog.AddRadioButton(301, L"New first option");
taskDialog.AddRadioButton(302, L"New second option");
taskDialog.AddRadioButton(303,
L"New third option should be disabled");
// Change the default radio button to the second option
taskDialog.SetDefaultRadioButton(302);
// Make sure the third option is disabled.
if (taskDialog.IsRadioButtonEnabled(303))
{
taskDialog.SetRadioButtonOptions(303, FALSE);
}
taskDialog.DoModal();
selection = taskDialog.GetSelectedRadioButtonID();
switch (taskDialog.GetSelectedRadioButtonID())
{
case 301:
// TODO: Place processing here for new first
// command button control.
break;
case 302:
// TODO: Place processing here for new second
// command button control.
break;
case 303:
// TODO: Place processing here for the new third
// command button control.
break;
default:
break;
}
// Remove all the radio button controls and add new ones from
// the string table resource.
taskDialog.RemoveAllRadioButtons();
taskDialog.LoadRadioButtons(1001, 1005);
CTaskDialog::ClickCommandControl
按一下命令按鈕控制項或以程式設計方式的通用按鈕。
protected:
void ClickCommandControl(int nCommandControlID) const;
參數
nCommandControlID
[in]要按一下之控制項的命令識別碼。
備註
此方法會產生 windows 訊息TDM_CLICK_BUTTON。
CTaskDialog::ClickRadioButton
以程式設計方式按一下選項按鈕。
protected:
void ClickRadioButton(int nRadioButtonID) const;
參數
nRadioButtonID
[in]要按一下的選項按鈕識別碼。
備註
此方法會產生 windows 訊息TDM_CLICK_RADIO_BUTTON。
CTaskDialog::CTaskDialog
建立 CTaskDialog 類別 的 實例。
CTaskDialog(
const CString& strContent,
const CString& strMainInstruction,
const CString& strTitle,
int nCommonButtons = TDCBF_OK_BUTTON | TDCBF_CANCEL_BUTTON,
int nTaskDialogOptions = TDF_ENABLE_HYPERLINKS | TDF_USE_COMMAND_LINKS,
const CString& strFooter = _T(""));
CTaskDialog(
const CString& strContent,
const CString& strMainInstruction,
const CString& strTitle,
int nIDCommandControlsFirst,
int nIDCommandControlsLast,
int nCommonButtons,
int nTaskDialogOptions = TDF_ENABLE_HYPERLINKS | TDF_USE_COMMAND_LINKS,
const CString& strFooter = _T(""));
參數
strContent
[in]要用於 之內容的 CTaskDialog
字串。
strMainInstruction
[in]的主要指示 CTaskDialog
。
strTitle
[in]的 CTaskDialog
標題。
nCommonButtons
[in]要加入至 CTaskDialog
的通用按鈕遮罩。
nTaskDialogOptions
[in]要用於 CTaskDialog
的選項組。
strFooter
[in]要當做頁尾使用的字串。
nIDCommandControlsFirst
[in]第一個命令的字串識別碼。
nIDCommandControlsLast
[in]最後一個命令的字串識別碼。
備註
有兩種方式可將 新增 CTaskDialog
至應用程式。 第一種方式是使用其中一個建構函式來建立 CTaskDialog
,並使用 CTaskDialog::D oModal 加以顯示 。 第二種方式是使用靜態函式 CTaskDialog::ShowDialog ,這可讓您在不明確建立 CTaskDialog
物件的情況下顯示 CTaskDialog
。
第二個建構函式會使用來自應用程式資源檔的資料來建立命令按鈕控制項。 資源檔中的字串資料表有數個字串與相關聯的字串識別碼。 這個方法會在包含 nIDCommandControlsFirst 和 nCommandControlsLast 之間 ,針對字串資料表中的每個有效專案新增命令按鈕控制項。 對於這些命令按鈕控制項,字串資料表中的字串是控制項的標題,而字串識別碼則是控制項的識別碼。
如需有效選項的清單,請參閱 CTaskDialog::SetOptions 。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Setting new information to be able to reuse the dialog resource
taskDialog.SetWindowTitle(L"New title for the task dialog");
taskDialog.SetContent(L"New message to show the user.");
taskDialog.SetMainInstruction(L"Even more important!");
taskDialog.SetMainIcon(TD_ERROR_ICON);
taskDialog.SetDialogWidth(300);
// Add a footer
taskDialog.SetFooterText(L"Footer information for the dialog.");
taskDialog.SetFooterIcon(TD_INFORMATION_ICON);
// Add expansion information
taskDialog.SetExpansionArea(L"Additional information\non two lines.",
L"Click here for more information.",
L"Click here to hide the extra information.");
// Change the options to show the expanded information by default.
// It is necessary to retrieve the current options first.
int options = taskDialog.GetOptions();
options |= TDF_EXPANDED_BY_DEFAULT;
taskDialog.SetOptions(options);
taskDialog.DoModal();
CTaskDialog::D oModal
CTaskDialog
顯示 ,並使它變成強制回應。
INT_PTR DoModal (HWND hParent = ::GetActiveWindow());
參數
hParent
[in]的父視窗 CTaskDialog
。
傳回值
整數,對應至使用者所做的選取範圍。
備註
顯示 CTaskDialog 的 這個實例。 然後,應用程式會等候使用者關閉對話方塊。
當使用者 CTaskDialog
選取通用按鈕、命令連結控制項或關閉 時 CTaskDialog
關閉 。 傳回值是指出使用者如何關閉對話方塊的識別碼。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Setting new information to be able to reuse the dialog resource
taskDialog.SetWindowTitle(L"New title for the task dialog");
taskDialog.SetContent(L"New message to show the user.");
taskDialog.SetMainInstruction(L"Even more important!");
taskDialog.SetMainIcon(TD_ERROR_ICON);
taskDialog.SetDialogWidth(300);
// Add a footer
taskDialog.SetFooterText(L"Footer information for the dialog.");
taskDialog.SetFooterIcon(TD_INFORMATION_ICON);
// Add expansion information
taskDialog.SetExpansionArea(L"Additional information\non two lines.",
L"Click here for more information.",
L"Click here to hide the extra information.");
// Change the options to show the expanded information by default.
// It is necessary to retrieve the current options first.
int options = taskDialog.GetOptions();
options |= TDF_EXPANDED_BY_DEFAULT;
taskDialog.SetOptions(options);
taskDialog.DoModal();
CTaskDialog::GetCommonButtonCount
擷取一般按鈕的數目。
int GetCommonButtonCount() const;
傳回值
可用的一般按鈕數目。
備註
常見的按鈕是您提供給 CTaskDialog::CTaskDialog 的預設按鈕。 CTaskDialog 類別 會顯示對話方塊底部的按鈕。
CommCtrl.h 中會提供按鈕的列舉清單。
CTaskDialog::GetCommonButtonFlag
將標準 Windows 按鈕轉換成與 CTaskDialog 類別 相關聯的通用按鈕類型。
int GetCommonButtonFlag(int nButtonId) const;
參數
nButtonId
[in]標準 Windows 按鈕值。
傳回值
對應 CTaskDialog
通用按鈕的值。 如果沒有對應的通用按鈕,這個方法會傳回 0。
CTaskDialog::GetCommonButtonId
將與 CTaskDialog 類別 相關聯的 其中一個通用按鈕類型轉換為標準 Windows 按鈕。
int GetCommonButtonId(int nFlag);
參數
nFlag
[in]與 CTaskDialog
類別相關聯的通用按鈕類型。
傳回值
對應標準 Windows 按鈕的值。 如果沒有對應的 Windows 按鈕,此方法會傳回 0。
CTaskDialog::GetOptions
傳回這個 CTaskDialog
的選項旗標。
int GetOptions() const;
傳回值
的 CTaskDialog
旗標。
備註
如需 CTaskDialog 類別 可用 選項的詳細資訊,請參閱 CTaskDialog::SetOptions 。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Setting new information to be able to reuse the dialog resource
taskDialog.SetWindowTitle(L"New title for the task dialog");
taskDialog.SetContent(L"New message to show the user.");
taskDialog.SetMainInstruction(L"Even more important!");
taskDialog.SetMainIcon(TD_ERROR_ICON);
taskDialog.SetDialogWidth(300);
// Add a footer
taskDialog.SetFooterText(L"Footer information for the dialog.");
taskDialog.SetFooterIcon(TD_INFORMATION_ICON);
// Add expansion information
taskDialog.SetExpansionArea(L"Additional information\non two lines.",
L"Click here for more information.",
L"Click here to hide the extra information.");
// Change the options to show the expanded information by default.
// It is necessary to retrieve the current options first.
int options = taskDialog.GetOptions();
options |= TDF_EXPANDED_BY_DEFAULT;
taskDialog.SetOptions(options);
taskDialog.DoModal();
CTaskDialog::GetSelectedCommandControlID
傳回選取的命令按鈕控制項。
int GetSelectedCommandControlID() const;
傳回值
目前選取之命令按鈕控制項的識別碼。
備註
您不需要使用此方法來擷取使用者選取之命令按鈕的識別碼。 該識別碼是由 CTaskDialog::D oModal 或 CTaskDialog::ShowDialog 傳回。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title.
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
taskDialog.AddCommandControl(201, L"First command button control");
taskDialog.AddCommandControl(202, L"Second command button control");
taskDialog.AddCommandControl(203, L"Third command button control");
// Show the CTaskDialog and remember how the user closed it.
int selection = taskDialog.DoModal();
switch (selection)
{
case 201:
// TODO: Place processing here for the first
// command button control.
break;
case 202:
// TODO: Place processing here for the second
// command button control.
break;
case 203:
// TODO: Place processing here for the third
// command button control.
break;
default:
break;
}
// Remove all the command controls so that we can use the same task
// dialog with new command button controls.
taskDialog.RemoveAllCommandControls();
taskDialog.AddCommandControl(301,
L"New first command button control");
taskDialog.AddCommandControl(302,
L"New second command button control should require elevation",
TRUE, TRUE);
taskDialog.AddCommandControl(303,
L"New third command button control should be disabled");
// Change the default command button control
taskDialog.SetDefaultCommandControl(302);
// Make sure the third option is disabled.
if (taskDialog.IsCommandControlEnabled(303))
{
taskDialog.SetCommandControlOptions(303, FALSE);
}
taskDialog.DoModal();
switch (taskDialog.GetSelectedCommandControlID())
{
case 301:
// TODO: Place processing here for new first
// command button control.
break;
case 302:
// TODO: Place processing here for new second
// command button control.
break;
case 303:
// TODO: Place processing here for the new third
// command button control.
break;
default:
break;
}
// Remove all the command button controls and add new ones from
// the string table resource.
taskDialog.RemoveAllCommandControls();
taskDialog.LoadCommandControls(1001, 1005);
CTaskDialog::GetSelectedRadioButtonID
傳回選取的選項按鈕。
int GetSelectedRadioButtonID() const;
傳回值
所選選項按鈕的識別碼。
備註
在使用者關閉對話方塊以擷取選取的選項按鈕之後,您可以使用這個方法。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
taskDialog.AddRadioButton(201, L"First option");
taskDialog.AddRadioButton(202, L"Second option");
taskDialog.AddRadioButton(203, L"Third option");
taskDialog.DoModal();
int selection = taskDialog.GetSelectedRadioButtonID();
switch (selection)
{
case 201:
// TODO: Place processing here for the first
// radio button.
break;
case 202:
// TODO: Place processing here for the second
// radio button.
break;
case 203:
// TODO: Place processing here for the third
// radio button.
break;
default:
break;
}
// Remove all the radio buttons so that we can use the same task
// dialog with new radio buttons.
taskDialog.RemoveAllRadioButtons();
taskDialog.AddRadioButton(301, L"New first option");
taskDialog.AddRadioButton(302, L"New second option");
taskDialog.AddRadioButton(303,
L"New third option should be disabled");
// Change the default radio button to the second option
taskDialog.SetDefaultRadioButton(302);
// Make sure the third option is disabled.
if (taskDialog.IsRadioButtonEnabled(303))
{
taskDialog.SetRadioButtonOptions(303, FALSE);
}
taskDialog.DoModal();
selection = taskDialog.GetSelectedRadioButtonID();
switch (taskDialog.GetSelectedRadioButtonID())
{
case 301:
// TODO: Place processing here for new first
// command button control.
break;
case 302:
// TODO: Place processing here for new second
// command button control.
break;
case 303:
// TODO: Place processing here for the new third
// command button control.
break;
default:
break;
}
// Remove all the radio button controls and add new ones from
// the string table resource.
taskDialog.RemoveAllRadioButtons();
taskDialog.LoadRadioButtons(1001, 1005);
CTaskDialog::GetVerificationCheckboxState
擷取 [驗證] 核取方塊的狀態。
BOOL GetVerificationCheckboxState() const;
傳回值
如果核取核取方塊,則為 TRUE;如果不是,則為 FALSE。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Add the verification checkbox and set the default state.
taskDialog.SetVerificationCheckboxText(L"Remember your selection.");
taskDialog.SetVerificationCheckbox(false);
taskDialog.DoModal();
if (taskDialog.GetVerificationCheckboxState())
{
// TODO: Write settings of the task dialog to the registry
}
CTaskDialog::IsCommandControlEnabled
判斷是否啟用命令按鈕控制項或按鈕。
BOOL IsCommandControlEnabled(int nCommandControlID) const;
參數
nCommandControlID
[in]要測試之命令按鈕控制項或按鈕的識別碼。
傳回值
如果控制項已啟用,則為 TRUE,否則為 FALSE。
備註
您可以使用此方法來判斷命令按鈕控制項和 Class* 的通用按鈕 CTaskDialog
可用性。
如果 nCommandControlID 不是通用 CTaskDialog
按鈕或命令按鈕控制項的有效識別碼,這個方法會擲回例外狀況。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title.
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
taskDialog.AddCommandControl(201, L"First command button control");
taskDialog.AddCommandControl(202, L"Second command button control");
taskDialog.AddCommandControl(203, L"Third command button control");
// Show the CTaskDialog and remember how the user closed it.
int selection = taskDialog.DoModal();
switch (selection)
{
case 201:
// TODO: Place processing here for the first
// command button control.
break;
case 202:
// TODO: Place processing here for the second
// command button control.
break;
case 203:
// TODO: Place processing here for the third
// command button control.
break;
default:
break;
}
// Remove all the command controls so that we can use the same task
// dialog with new command button controls.
taskDialog.RemoveAllCommandControls();
taskDialog.AddCommandControl(301,
L"New first command button control");
taskDialog.AddCommandControl(302,
L"New second command button control should require elevation",
TRUE, TRUE);
taskDialog.AddCommandControl(303,
L"New third command button control should be disabled");
// Change the default command button control
taskDialog.SetDefaultCommandControl(302);
// Make sure the third option is disabled.
if (taskDialog.IsCommandControlEnabled(303))
{
taskDialog.SetCommandControlOptions(303, FALSE);
}
taskDialog.DoModal();
switch (taskDialog.GetSelectedCommandControlID())
{
case 301:
// TODO: Place processing here for new first
// command button control.
break;
case 302:
// TODO: Place processing here for new second
// command button control.
break;
case 303:
// TODO: Place processing here for the new third
// command button control.
break;
default:
break;
}
// Remove all the command button controls and add new ones from
// the string table resource.
taskDialog.RemoveAllCommandControls();
taskDialog.LoadCommandControls(1001, 1005);
CTaskDialog::IsRadioButtonEnabled
判斷是否啟用選項按鈕。
BOOL IsRadioButtonEnabled(int nRadioButtonID) const;
參數
nRadioButtonID
[in]要測試的選項按鈕識別碼。
傳回值
如果選項按鈕已啟用,則為 TRUE;如果不是,則為 FALSE。
備註
如果 nRadioButtonID 不是選項按鈕的有效識別碼,這個方法會擲回例外狀況。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
taskDialog.AddRadioButton(201, L"First option");
taskDialog.AddRadioButton(202, L"Second option");
taskDialog.AddRadioButton(203, L"Third option");
taskDialog.DoModal();
int selection = taskDialog.GetSelectedRadioButtonID();
switch (selection)
{
case 201:
// TODO: Place processing here for the first
// radio button.
break;
case 202:
// TODO: Place processing here for the second
// radio button.
break;
case 203:
// TODO: Place processing here for the third
// radio button.
break;
default:
break;
}
// Remove all the radio buttons so that we can use the same task
// dialog with new radio buttons.
taskDialog.RemoveAllRadioButtons();
taskDialog.AddRadioButton(301, L"New first option");
taskDialog.AddRadioButton(302, L"New second option");
taskDialog.AddRadioButton(303,
L"New third option should be disabled");
// Change the default radio button to the second option
taskDialog.SetDefaultRadioButton(302);
// Make sure the third option is disabled.
if (taskDialog.IsRadioButtonEnabled(303))
{
taskDialog.SetRadioButtonOptions(303, FALSE);
}
taskDialog.DoModal();
selection = taskDialog.GetSelectedRadioButtonID();
switch (taskDialog.GetSelectedRadioButtonID())
{
case 301:
// TODO: Place processing here for new first
// command button control.
break;
case 302:
// TODO: Place processing here for new second
// command button control.
break;
case 303:
// TODO: Place processing here for the new third
// command button control.
break;
default:
break;
}
// Remove all the radio button controls and add new ones from
// the string table resource.
taskDialog.RemoveAllRadioButtons();
taskDialog.LoadRadioButtons(1001, 1005);
CTaskDialog::IsSupported
判斷執行應用程式的電腦是否支援 CTaskDialog
。
static BOOL IsSupported();
傳回值
如果電腦支援 , CTaskDialog
則為 TRUE;否則為 FALSE。
備註
使用此函式來判斷執行應用程式的電腦是否支援 類別 CTaskDialog
。 如果電腦不支援 CTaskDialog
,您應該提供另一種方法來向使用者傳達資訊。 如果您的應用程式嘗試在不支援 CTaskDialog
類別的電腦上使用 CTaskDialog
,就會當機。
範例
// TODO: Replace the string below with the actual message to the user
CString message("Important information to the user");
// TODO: Replace the string below with the title of this project
CString title("Project Title");
CString emptyString;
if (CTaskDialog::IsSupported())
{
CTaskDialog::ShowDialog(message, emptyString, title, 0, 0,
TDCBF_OK_BUTTON);
}
else
{
AfxMessageBox(message);
}
CTaskDialog::LoadCommandControls
使用字串資料表中的資料來新增命令按鈕控制項。
void LoadCommandControls(
int nIDCommandControlsFirst,
int nIDCommandControlsLast);
參數
nIDCommandControlsFirst
[in]第一個命令的字串識別碼。
nIDCommandControlsLast
[in]最後一個命令的字串識別碼。
備註
這個方法會使用應用程式資源檔中的資料來建立命令按鈕控制項。 資源檔中的字串資料表有數個字串與相關聯的字串識別碼。 使用這個方法加入的新命令按鈕控制項會使用控制項的標題字串,以及控制項識別碼的字串識別碼。 選取的字串範圍是由 nIDCommandControlsFirst 和 nCommandControlsLast 提供, 包含。 如果範圍中有空的專案,則 方法不會新增該專案的命令按鈕控制項。
根據預設,會啟用新的命令按鈕控制項,而且不需要提高許可權。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title.
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
taskDialog.AddCommandControl(201, L"First command button control");
taskDialog.AddCommandControl(202, L"Second command button control");
taskDialog.AddCommandControl(203, L"Third command button control");
// Show the CTaskDialog and remember how the user closed it.
int selection = taskDialog.DoModal();
switch (selection)
{
case 201:
// TODO: Place processing here for the first
// command button control.
break;
case 202:
// TODO: Place processing here for the second
// command button control.
break;
case 203:
// TODO: Place processing here for the third
// command button control.
break;
default:
break;
}
// Remove all the command controls so that we can use the same task
// dialog with new command button controls.
taskDialog.RemoveAllCommandControls();
taskDialog.AddCommandControl(301,
L"New first command button control");
taskDialog.AddCommandControl(302,
L"New second command button control should require elevation",
TRUE, TRUE);
taskDialog.AddCommandControl(303,
L"New third command button control should be disabled");
// Change the default command button control
taskDialog.SetDefaultCommandControl(302);
// Make sure the third option is disabled.
if (taskDialog.IsCommandControlEnabled(303))
{
taskDialog.SetCommandControlOptions(303, FALSE);
}
taskDialog.DoModal();
switch (taskDialog.GetSelectedCommandControlID())
{
case 301:
// TODO: Place processing here for new first
// command button control.
break;
case 302:
// TODO: Place processing here for new second
// command button control.
break;
case 303:
// TODO: Place processing here for the new third
// command button control.
break;
default:
break;
}
// Remove all the command button controls and add new ones from
// the string table resource.
taskDialog.RemoveAllCommandControls();
taskDialog.LoadCommandControls(1001, 1005);
CTaskDialog::LoadRadioButtons
使用字串資料表中的資料新增選項按鈕控制項。
void LoadRadioButtons(
int nIDRadioButtonsFirst,
int nIDRadioButtonsLast);
參數
nIDRadioButtonsFirst
[in]第一個選項按鈕的字串識別碼。
nIDRadioButtonsLast
[in]最後一個選項按鈕的字串識別碼。
備註
這個方法會使用應用程式資源檔中的資料來建立選項按鈕。 資源檔中的字串資料表有數個字串與相關聯的字串識別碼。 使用此方法新增的新選項按鈕會使用選項按鈕標題字串,以及選項按鈕識別碼的字串識別碼。 選取的字串範圍是由 nIDRadioButtonsFirst 和 nRadioButtonsLast 提供, 包含。 如果範圍中有空的專案,則 方法不會為該專案新增選項按鈕。
根據預設,會啟用新的選項按鈕。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
taskDialog.AddRadioButton(201, L"First option");
taskDialog.AddRadioButton(202, L"Second option");
taskDialog.AddRadioButton(203, L"Third option");
taskDialog.DoModal();
int selection = taskDialog.GetSelectedRadioButtonID();
switch (selection)
{
case 201:
// TODO: Place processing here for the first
// radio button.
break;
case 202:
// TODO: Place processing here for the second
// radio button.
break;
case 203:
// TODO: Place processing here for the third
// radio button.
break;
default:
break;
}
// Remove all the radio buttons so that we can use the same task
// dialog with new radio buttons.
taskDialog.RemoveAllRadioButtons();
taskDialog.AddRadioButton(301, L"New first option");
taskDialog.AddRadioButton(302, L"New second option");
taskDialog.AddRadioButton(303,
L"New third option should be disabled");
// Change the default radio button to the second option
taskDialog.SetDefaultRadioButton(302);
// Make sure the third option is disabled.
if (taskDialog.IsRadioButtonEnabled(303))
{
taskDialog.SetRadioButtonOptions(303, FALSE);
}
taskDialog.DoModal();
selection = taskDialog.GetSelectedRadioButtonID();
switch (taskDialog.GetSelectedRadioButtonID())
{
case 301:
// TODO: Place processing here for new first
// command button control.
break;
case 302:
// TODO: Place processing here for new second
// command button control.
break;
case 303:
// TODO: Place processing here for the new third
// command button control.
break;
default:
break;
}
// Remove all the radio button controls and add new ones from
// the string table resource.
taskDialog.RemoveAllRadioButtons();
taskDialog.LoadRadioButtons(1001, 1005);
CTaskDialog::NavigateTo
將焦點傳輸到另一個 CTaskDialog
。
protected:
void NavigateTo(CTaskDialog& oTaskDialog) const;
參數
oTaskDialog
[in] CTaskDialog
接收焦點的 。
備註
這個方法會在顯示 oTaskDialog 時隱藏目前的 CTaskDialog
。 oTaskDialog 會顯示在與目前 CTaskDialog
相同的位置。
CTaskDialog::OnCommandControlClick
當使用者按一下命令按鈕控制項時,架構會呼叫此方法。
virtual HRESULT OnCommandControlClick(int nCommandControlID);
參數
nCommandControlID
[in]使用者選取之命令按鈕控制項的識別碼。
傳回值
預設實作會傳回S_OK。
備註
覆寫衍生類別中的這個方法,以實作自訂行為。
CTaskDialog::OnCreate
架構會在建立 CTaskDialog
之後呼叫這個方法。
virtual HRESULT OnCreate();
傳回值
預設實作會傳回S_OK。
備註
覆寫衍生類別中的這個方法,以實作自訂行為。
CTaskDialog::OnDestroy
架構會在終結 CTaskDialog
之前立即呼叫這個方法。
virtual HRESULT OnDestroy();
傳回值
預設實作會傳回S_OK。
備註
覆寫衍生類別中的這個方法,以實作自訂行為。
CTaskDialog::OnExpandButtonClick
當使用者按一下展開按鈕時,架構會呼叫此方法。
virtual HRESULT OnExpandButtonClicked(BOOL bExpanded);
參數
bExpanded
[in]非零值表示顯示額外的資訊;0 表示隱藏額外的資訊。
傳回值
預設實作會傳回S_OK。
備註
覆寫衍生類別中的這個方法,以實作自訂行為。
CTaskDialog::OnHelp
當使用者要求協助時,架構會呼叫此方法。
virtual HRESULT OnHelp();
傳回值
預設實作會傳回S_OK。
備註
覆寫衍生類別中的這個方法,以實作自訂行為。
CTaskDialog::OnHyperlinkClick
當使用者按一下超連結時,架構會呼叫此方法。
virtual HRESULT OnHyperlinkClick(const CString& strHref);
參數
strHref
[in]表示超連結的字串。
傳回值
預設實作會傳回S_OK。
備註
這個方法會先呼叫 ShellExecute ,再傳回S_OK。
覆寫衍生類別中的這個方法,以實作自訂行為。
CTaskDialog::OnInit
架構會在 初始化 時 CTaskDialog
呼叫這個方法。
virtual HRESULT OnInit();
傳回值
預設實作會傳回S_OK。
備註
覆寫衍生類別中的這個方法,以實作自訂行為。
CTaskDialog::OnNavigatePage
架構會呼叫此方法,以回應 CTaskDialog::NavigateTo 方法。
virtual HRESULT OnNavigatePage();
傳回值
預設實作會傳回S_OK。
備註
覆寫衍生類別中的這個方法,以實作自訂行為。
CTaskDialog::OnRadioButtonClick
當使用者選取選項按鈕控制項時,架構會呼叫此方法。
virtual HRESULT OnRadioButtonClick(int nRadioButtonID);
參數
nRadioButtonID
[in]使用者按下的選項按鈕控制項識別碼。
傳回值
預設實作會傳回S_OK。
備註
覆寫衍生類別中的這個方法,以實作自訂行為。
CTaskDialog::OnTimer
架構會在計時器到期時呼叫這個方法。
virtual HRESULT OnTimer(long lTime);
參數
lTime
[in]建立 之後 CTaskDialog
的毫秒或計時器重設的時間。
傳回值
預設實作會傳回S_OK。
備註
覆寫衍生類別中的這個方法,以實作自訂行為。
CTaskDialog::OnVerificationCheckboxClick
當使用者按一下 [驗證] 核取方塊時,架構會呼叫此方法。
virtual HRESULT OnVerificationCheckboxClick(BOOL bChecked);
參數
bChecked
[in]TRUE 表示已選取驗證核取方塊;FALSE 表示它不是。
傳回值
預設實作會傳回S_OK。
備註
覆寫衍生類別中的這個方法,以實作自訂行為。
CTaskDialog::RemoveAllCommandControls
從 移除所有命令按鈕控制項 CTaskDialog
。
void RemoveAllCommandControls();
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title.
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
taskDialog.AddCommandControl(201, L"First command button control");
taskDialog.AddCommandControl(202, L"Second command button control");
taskDialog.AddCommandControl(203, L"Third command button control");
// Show the CTaskDialog and remember how the user closed it.
int selection = taskDialog.DoModal();
switch (selection)
{
case 201:
// TODO: Place processing here for the first
// command button control.
break;
case 202:
// TODO: Place processing here for the second
// command button control.
break;
case 203:
// TODO: Place processing here for the third
// command button control.
break;
default:
break;
}
// Remove all the command controls so that we can use the same task
// dialog with new command button controls.
taskDialog.RemoveAllCommandControls();
taskDialog.AddCommandControl(301,
L"New first command button control");
taskDialog.AddCommandControl(302,
L"New second command button control should require elevation",
TRUE, TRUE);
taskDialog.AddCommandControl(303,
L"New third command button control should be disabled");
// Change the default command button control
taskDialog.SetDefaultCommandControl(302);
// Make sure the third option is disabled.
if (taskDialog.IsCommandControlEnabled(303))
{
taskDialog.SetCommandControlOptions(303, FALSE);
}
taskDialog.DoModal();
switch (taskDialog.GetSelectedCommandControlID())
{
case 301:
// TODO: Place processing here for new first
// command button control.
break;
case 302:
// TODO: Place processing here for new second
// command button control.
break;
case 303:
// TODO: Place processing here for the new third
// command button control.
break;
default:
break;
}
// Remove all the command button controls and add new ones from
// the string table resource.
taskDialog.RemoveAllCommandControls();
taskDialog.LoadCommandControls(1001, 1005);
CTaskDialog::RemoveAllRadioButtons
從 移除所有選項按鈕 CTaskDialog
。
void RemoveAllRadioButtons();
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
taskDialog.AddRadioButton(201, L"First option");
taskDialog.AddRadioButton(202, L"Second option");
taskDialog.AddRadioButton(203, L"Third option");
taskDialog.DoModal();
int selection = taskDialog.GetSelectedRadioButtonID();
switch (selection)
{
case 201:
// TODO: Place processing here for the first
// radio button.
break;
case 202:
// TODO: Place processing here for the second
// radio button.
break;
case 203:
// TODO: Place processing here for the third
// radio button.
break;
default:
break;
}
// Remove all the radio buttons so that we can use the same task
// dialog with new radio buttons.
taskDialog.RemoveAllRadioButtons();
taskDialog.AddRadioButton(301, L"New first option");
taskDialog.AddRadioButton(302, L"New second option");
taskDialog.AddRadioButton(303,
L"New third option should be disabled");
// Change the default radio button to the second option
taskDialog.SetDefaultRadioButton(302);
// Make sure the third option is disabled.
if (taskDialog.IsRadioButtonEnabled(303))
{
taskDialog.SetRadioButtonOptions(303, FALSE);
}
taskDialog.DoModal();
selection = taskDialog.GetSelectedRadioButtonID();
switch (taskDialog.GetSelectedRadioButtonID())
{
case 301:
// TODO: Place processing here for new first
// command button control.
break;
case 302:
// TODO: Place processing here for new second
// command button control.
break;
case 303:
// TODO: Place processing here for the new third
// command button control.
break;
default:
break;
}
// Remove all the radio button controls and add new ones from
// the string table resource.
taskDialog.RemoveAllRadioButtons();
taskDialog.LoadRadioButtons(1001, 1005);
CTaskDialog::SetCommandControlOptions
更新 上的 CTaskDialog
命令按鈕控制項。
void SetCommandControlOptions(
int nCommandControlID,
BOOL bEnabled,
BOOL bRequiresElevation = FALSE);
參數
nCommandControlID
[in]要更新之命令控制項的識別碼。
bEnabled
[in]布林參數,指出指定的命令按鈕控制項是否已啟用或停用。
bRequiresElevation
[in]布林參數,指出指定的命令按鈕控制項是否需要提高許可權。
備註
使用此方法可變更是否啟用命令按鈕控制項,或在將命令按鈕新增至 CTaskDialog
類別之後需要提高許可權。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title.
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
taskDialog.AddCommandControl(201, L"First command button control");
taskDialog.AddCommandControl(202, L"Second command button control");
taskDialog.AddCommandControl(203, L"Third command button control");
// Show the CTaskDialog and remember how the user closed it.
int selection = taskDialog.DoModal();
switch (selection)
{
case 201:
// TODO: Place processing here for the first
// command button control.
break;
case 202:
// TODO: Place processing here for the second
// command button control.
break;
case 203:
// TODO: Place processing here for the third
// command button control.
break;
default:
break;
}
// Remove all the command controls so that we can use the same task
// dialog with new command button controls.
taskDialog.RemoveAllCommandControls();
taskDialog.AddCommandControl(301,
L"New first command button control");
taskDialog.AddCommandControl(302,
L"New second command button control should require elevation",
TRUE, TRUE);
taskDialog.AddCommandControl(303,
L"New third command button control should be disabled");
// Change the default command button control
taskDialog.SetDefaultCommandControl(302);
// Make sure the third option is disabled.
if (taskDialog.IsCommandControlEnabled(303))
{
taskDialog.SetCommandControlOptions(303, FALSE);
}
taskDialog.DoModal();
switch (taskDialog.GetSelectedCommandControlID())
{
case 301:
// TODO: Place processing here for new first
// command button control.
break;
case 302:
// TODO: Place processing here for new second
// command button control.
break;
case 303:
// TODO: Place processing here for the new third
// command button control.
break;
default:
break;
}
// Remove all the command button controls and add new ones from
// the string table resource.
taskDialog.RemoveAllCommandControls();
taskDialog.LoadCommandControls(1001, 1005);
CTaskDialog::SetCommonButtonOptions
更新要啟用的通用按鈕子集,以及需要 UAC 提高許可權。
void SetCommonButtonOptions(
int nDisabledButtonMask,
int nElevationButtonMask = 0);
參數
nDisabledButtonMask
[in]要停用之通用按鈕的遮罩。
nElevationButtonMask
[in]需要提高許可權之常見按鈕的遮罩。
備註
您可以使用建構 函式 CTaskDialog::CTaskDialog 和 CTaskDialog ::SetCommonButtons 方法來設定 CTaskDialog 類別 實例 可用的通用按鈕。 CTaskDialog::SetCommonButtonOptions
不支援新增一般按鈕。
如果您使用此方法來停用或提高這個 CTaskDialog
無法使用的通用按鈕,這個方法會使用 ENSURE 宏擲回例外狀況。
這個方法會啟用任何可供 使用的 CTaskDialog
按鈕,但不是在 nDisabledButtonMask 中 ,即使先前已停用也一樣。 此方法會以類似的方式處理提高許可權:如果通用按鈕可用,但不包含在 nElevationButtonMask 中 ,則會將通用按鈕記錄為不需要提高許可權。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title);
// Create a button mask.
int buttons = TDCBF_OK_BUTTON | TDCBF_CANCEL_BUTTON;
buttons |= TDCBF_RETRY_BUTTON | TDCBF_CLOSE_BUTTON;
taskDialog.SetCommonButtons(buttons);
// Disable the close button and make the retry button require
// elevation.
taskDialog.SetCommonButtonOptions(TDCBF_CLOSE_BUTTON,
TDCBF_RETRY_BUTTON);
taskDialog.DoModal();
CTaskDialog::SetCommonButtons
將一般按鈕新增至 CTaskDialog
。
void SetCommonButtons(
int nButtonMask,
int nDisabledButtonMask = 0,
int nElevationButtonMask = 0);
參數
nButtonMask
[in]要加入至 的 CTaskDialog
按鈕遮罩。
nDisabledButtonMask
[in]要停用之按鈕的遮罩。
nElevationButtonMask
[in]需要提高許可權的按鈕遮罩。
備註
建立類別實例的 CTaskDialog
顯示視窗之後,即無法呼叫這個方法。 如果您這樣做,這個方法會擲回例外狀況。
nButtonMask 所 指示的按鈕會覆寫先前新增至 CTaskDialog
的任何通用按鈕。 只有 nButtonMask 中 指出的按鈕可用。
如果 nDisabledButtonMask 或 nElevationButtonMask 包含不在 nButtonMask 中的 按鈕,這個方法會使用 ENSURE 宏擲回例外狀況。
根據預設,所有通用按鈕都會啟用,而且不需要提高許可權。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title);
// Create a button mask.
int buttons = TDCBF_OK_BUTTON | TDCBF_CANCEL_BUTTON;
buttons |= TDCBF_RETRY_BUTTON | TDCBF_CLOSE_BUTTON;
taskDialog.SetCommonButtons(buttons);
// Disable the close button and make the retry button require
// elevation.
taskDialog.SetCommonButtonOptions(TDCBF_CLOSE_BUTTON,
TDCBF_RETRY_BUTTON);
taskDialog.DoModal();
CTaskDialog::SetContent
更新 的內容 CTaskDialog
。
void SetContent(const CString& strContent);
參數
strContent
[in]要向使用者顯示的字串。
備註
類別的內容 CTaskDialog
是對話方塊主區段中向使用者顯示的文字。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Setting new information to be able to reuse the dialog resource
taskDialog.SetWindowTitle(L"New title for the task dialog");
taskDialog.SetContent(L"New message to show the user.");
taskDialog.SetMainInstruction(L"Even more important!");
taskDialog.SetMainIcon(TD_ERROR_ICON);
taskDialog.SetDialogWidth(300);
// Add a footer
taskDialog.SetFooterText(L"Footer information for the dialog.");
taskDialog.SetFooterIcon(TD_INFORMATION_ICON);
// Add expansion information
taskDialog.SetExpansionArea(L"Additional information\non two lines.",
L"Click here for more information.",
L"Click here to hide the extra information.");
// Change the options to show the expanded information by default.
// It is necessary to retrieve the current options first.
int options = taskDialog.GetOptions();
options |= TDF_EXPANDED_BY_DEFAULT;
taskDialog.SetOptions(options);
taskDialog.DoModal();
CTaskDialog::SetDefaultCommandControl
指定預設命令按鈕控制項。
void SetDefaultCommandControl(int nCommandControlID);
參數
nCommandControlID
[in]要設為預設值之命令按鈕控制項的識別碼。
備註
預設命令按鈕控制項是第一次向使用者顯示 時 CTaskDialog
所選取的控制項。
如果找不到 nCommandControlID 所 指定的命令按鈕控制項,這個方法會擲回例外狀況。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title.
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
taskDialog.AddCommandControl(201, L"First command button control");
taskDialog.AddCommandControl(202, L"Second command button control");
taskDialog.AddCommandControl(203, L"Third command button control");
// Show the CTaskDialog and remember how the user closed it.
int selection = taskDialog.DoModal();
switch (selection)
{
case 201:
// TODO: Place processing here for the first
// command button control.
break;
case 202:
// TODO: Place processing here for the second
// command button control.
break;
case 203:
// TODO: Place processing here for the third
// command button control.
break;
default:
break;
}
// Remove all the command controls so that we can use the same task
// dialog with new command button controls.
taskDialog.RemoveAllCommandControls();
taskDialog.AddCommandControl(301,
L"New first command button control");
taskDialog.AddCommandControl(302,
L"New second command button control should require elevation",
TRUE, TRUE);
taskDialog.AddCommandControl(303,
L"New third command button control should be disabled");
// Change the default command button control
taskDialog.SetDefaultCommandControl(302);
// Make sure the third option is disabled.
if (taskDialog.IsCommandControlEnabled(303))
{
taskDialog.SetCommandControlOptions(303, FALSE);
}
taskDialog.DoModal();
switch (taskDialog.GetSelectedCommandControlID())
{
case 301:
// TODO: Place processing here for new first
// command button control.
break;
case 302:
// TODO: Place processing here for new second
// command button control.
break;
case 303:
// TODO: Place processing here for the new third
// command button control.
break;
default:
break;
}
// Remove all the command button controls and add new ones from
// the string table resource.
taskDialog.RemoveAllCommandControls();
taskDialog.LoadCommandControls(1001, 1005);
CTaskDialog::SetDefaultRadioButton
指定預設選項按鈕。
void SetDefaultRadioButton(int nRadioButtonID);
參數
nRadioButtonID
[in]要設為預設值的選項按鈕識別碼。
備註
預設選項按鈕是第一次向使用者顯示時 CTaskDialog
所選取的按鈕。
如果找不到 nRadioButtonID 所 指定的選項按鈕,這個方法會擲回例外狀況。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
taskDialog.AddRadioButton(201, L"First option");
taskDialog.AddRadioButton(202, L"Second option");
taskDialog.AddRadioButton(203, L"Third option");
taskDialog.DoModal();
int selection = taskDialog.GetSelectedRadioButtonID();
switch (selection)
{
case 201:
// TODO: Place processing here for the first
// radio button.
break;
case 202:
// TODO: Place processing here for the second
// radio button.
break;
case 203:
// TODO: Place processing here for the third
// radio button.
break;
default:
break;
}
// Remove all the radio buttons so that we can use the same task
// dialog with new radio buttons.
taskDialog.RemoveAllRadioButtons();
taskDialog.AddRadioButton(301, L"New first option");
taskDialog.AddRadioButton(302, L"New second option");
taskDialog.AddRadioButton(303,
L"New third option should be disabled");
// Change the default radio button to the second option
taskDialog.SetDefaultRadioButton(302);
// Make sure the third option is disabled.
if (taskDialog.IsRadioButtonEnabled(303))
{
taskDialog.SetRadioButtonOptions(303, FALSE);
}
taskDialog.DoModal();
selection = taskDialog.GetSelectedRadioButtonID();
switch (taskDialog.GetSelectedRadioButtonID())
{
case 301:
// TODO: Place processing here for new first
// command button control.
break;
case 302:
// TODO: Place processing here for new second
// command button control.
break;
case 303:
// TODO: Place processing here for the new third
// command button control.
break;
default:
break;
}
// Remove all the radio button controls and add new ones from
// the string table resource.
taskDialog.RemoveAllRadioButtons();
taskDialog.LoadRadioButtons(1001, 1005);
CTaskDialog::SetDialogWidth
調整 的 CTaskDialog
寬度。
void SetDialogWidth(int nWidth = 0);
參數
nWidth
[in]對話方塊的寬度,以圖元為單位。
備註
參數 nWidth 必須大於或等於 0。 否則,這個方法會擲回例外狀況。
如果 nWidth 設定為 0,這個方法會將對話方塊設定為預設大小。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Setting new information to be able to reuse the dialog resource
taskDialog.SetWindowTitle(L"New title for the task dialog");
taskDialog.SetContent(L"New message to show the user.");
taskDialog.SetMainInstruction(L"Even more important!");
taskDialog.SetMainIcon(TD_ERROR_ICON);
taskDialog.SetDialogWidth(300);
// Add a footer
taskDialog.SetFooterText(L"Footer information for the dialog.");
taskDialog.SetFooterIcon(TD_INFORMATION_ICON);
// Add expansion information
taskDialog.SetExpansionArea(L"Additional information\non two lines.",
L"Click here for more information.",
L"Click here to hide the extra information.");
// Change the options to show the expanded information by default.
// It is necessary to retrieve the current options first.
int options = taskDialog.GetOptions();
options |= TDF_EXPANDED_BY_DEFAULT;
taskDialog.SetOptions(options);
taskDialog.DoModal();
CTaskDialog::SetExpansionArea
更新 的 CTaskDialog
擴充區域。
void SetExpansionArea(
const CString& strExpandedInformation,
const CString& strCollapsedLabel = _T(""),
const CString& strExpandedLabel = _T(""));
參數
strExpandedInformation
[in]當使用者按一下展開按鈕時, CTaskDialog
對話方塊主體中顯示的字串。
strCollapsedLabel
[in]展開區域折迭時,展開按鈕旁顯示的字串 CTaskDialog
。
strExpandedLabel
[in]顯示展開區域時, CTaskDialog
展開按鈕旁顯示的字串。
備註
類別的 CTaskDialog
擴充區域可讓您為使用者提供其他資訊。 擴充區域位於 的主要部分 CTaskDialog
,位於標題和內容字串底下。
CTaskDialog
第一次顯示 時,它不會顯示展開的資訊,並將放在 strCollapsedLabel
展開按鈕旁邊。 當使用者按一下展開按鈕時,會顯示 CTaskDialog
strExpandedInformation ,並將標籤變更為 strExpandedLabel 。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Setting new information to be able to reuse the dialog resource
taskDialog.SetWindowTitle(L"New title for the task dialog");
taskDialog.SetContent(L"New message to show the user.");
taskDialog.SetMainInstruction(L"Even more important!");
taskDialog.SetMainIcon(TD_ERROR_ICON);
taskDialog.SetDialogWidth(300);
// Add a footer
taskDialog.SetFooterText(L"Footer information for the dialog.");
taskDialog.SetFooterIcon(TD_INFORMATION_ICON);
// Add expansion information
taskDialog.SetExpansionArea(L"Additional information\non two lines.",
L"Click here for more information.",
L"Click here to hide the extra information.");
// Change the options to show the expanded information by default.
// It is necessary to retrieve the current options first.
int options = taskDialog.GetOptions();
options |= TDF_EXPANDED_BY_DEFAULT;
taskDialog.SetOptions(options);
taskDialog.DoModal();
CTaskDialog::SetFooterIcon
更新 的 CTaskDialog
頁尾圖示。
void SetFooterIcon(HICON hFooterIcon);
void SetFooterIcon(LPCWSTR lpszFooterIcon);
參數
hFooterIcon
[in]的新圖示 CTaskDialog
。
lpszFooterIcon
[in]的新圖示 CTaskDialog
。
備註
頁尾圖示會顯示在 CTaskDialog 類別 底部 。 它可以有相關聯的頁尾文字。 您可以使用 CTaskDialog::SetFooterText 來變更頁尾文字 。
如果 CTaskDialog
顯示 或輸入參數為 Null,這個方法會擲回具有 ENSURE 宏的例外 狀況。
CTaskDialog
只能接受 HICON
或 LPCWSTR
作為頁尾圖示。 這是藉由在建構函式或 CTaskDialog::SetOptions 中設定選項TDF_USE_HICON_FOOTER來設定。 根據預設,會 CTaskDialog
設定為使用 LPCWSTR
做為頁尾圖示的輸入類型。 如果您嘗試使用不適當的類型設定圖示,此方法會產生例外狀況。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Setting new information to be able to reuse the dialog resource
taskDialog.SetWindowTitle(L"New title for the task dialog");
taskDialog.SetContent(L"New message to show the user.");
taskDialog.SetMainInstruction(L"Even more important!");
taskDialog.SetMainIcon(TD_ERROR_ICON);
taskDialog.SetDialogWidth(300);
// Add a footer
taskDialog.SetFooterText(L"Footer information for the dialog.");
taskDialog.SetFooterIcon(TD_INFORMATION_ICON);
// Add expansion information
taskDialog.SetExpansionArea(L"Additional information\non two lines.",
L"Click here for more information.",
L"Click here to hide the extra information.");
// Change the options to show the expanded information by default.
// It is necessary to retrieve the current options first.
int options = taskDialog.GetOptions();
options |= TDF_EXPANDED_BY_DEFAULT;
taskDialog.SetOptions(options);
taskDialog.DoModal();
CTaskDialog::SetFooterText
更新 的頁尾 CTaskDialog
上的文字。
void SetFooterText(const CString& strFooterText);
參數
strFooterText
[in]頁尾的新文字。
備註
頁尾圖示會出現在 底部 CTaskDialog
的頁尾文字旁邊。 您可以使用 CTaskDialog::SetFooterIcon 來變更頁尾圖示 。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Setting new information to be able to reuse the dialog resource
taskDialog.SetWindowTitle(L"New title for the task dialog");
taskDialog.SetContent(L"New message to show the user.");
taskDialog.SetMainInstruction(L"Even more important!");
taskDialog.SetMainIcon(TD_ERROR_ICON);
taskDialog.SetDialogWidth(300);
// Add a footer
taskDialog.SetFooterText(L"Footer information for the dialog.");
taskDialog.SetFooterIcon(TD_INFORMATION_ICON);
// Add expansion information
taskDialog.SetExpansionArea(L"Additional information\non two lines.",
L"Click here for more information.",
L"Click here to hide the extra information.");
// Change the options to show the expanded information by default.
// It is necessary to retrieve the current options first.
int options = taskDialog.GetOptions();
options |= TDF_EXPANDED_BY_DEFAULT;
taskDialog.SetOptions(options);
taskDialog.DoModal();
CTaskDialog::SetMainIcon
更新 的主要圖示 CTaskDialog
。
void SetMainIcon(HICON hMainIcon);
void SetMainIcon(LPCWSTR lpszMainIcon);
參數
hMainIcon
[in]新的圖示。
lpszMainIcon
[in]新的圖示。
備註
如果 CTaskDialog
顯示 或輸入參數為 Null,這個方法會擲回具有 ENSURE 宏的例外 狀況。
CTaskDialog
只能接受 HICON
或 LPCWSTR
作為主要圖示。 您可以在建構函式或 CTaskDialog::SetOptions 方法中設定TDF_USE_HICON_MAIN選項來設定此設定。 根據預設,會 CTaskDialog
設定為使用 LPCWSTR
作為主要圖示的輸入類型。 如果您嘗試使用不適當的類型設定圖示,此方法會產生例外狀況。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Setting new information to be able to reuse the dialog resource
taskDialog.SetWindowTitle(L"New title for the task dialog");
taskDialog.SetContent(L"New message to show the user.");
taskDialog.SetMainInstruction(L"Even more important!");
taskDialog.SetMainIcon(TD_ERROR_ICON);
taskDialog.SetDialogWidth(300);
// Add a footer
taskDialog.SetFooterText(L"Footer information for the dialog.");
taskDialog.SetFooterIcon(TD_INFORMATION_ICON);
// Add expansion information
taskDialog.SetExpansionArea(L"Additional information\non two lines.",
L"Click here for more information.",
L"Click here to hide the extra information.");
// Change the options to show the expanded information by default.
// It is necessary to retrieve the current options first.
int options = taskDialog.GetOptions();
options |= TDF_EXPANDED_BY_DEFAULT;
taskDialog.SetOptions(options);
taskDialog.DoModal();
CTaskDialog::SetMainInstruction
更新 的主要指示 CTaskDialog
。
void SetMainInstruction(const CString& strInstructions);
參數
strInstructions
[in]新的主要指示。
備註
類別的主要指示 CTaskDialog
是以大粗體字型向使用者顯示的文字。 它位於標題列下方的對話方塊中。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Setting new information to be able to reuse the dialog resource
taskDialog.SetWindowTitle(L"New title for the task dialog");
taskDialog.SetContent(L"New message to show the user.");
taskDialog.SetMainInstruction(L"Even more important!");
taskDialog.SetMainIcon(TD_ERROR_ICON);
taskDialog.SetDialogWidth(300);
// Add a footer
taskDialog.SetFooterText(L"Footer information for the dialog.");
taskDialog.SetFooterIcon(TD_INFORMATION_ICON);
// Add expansion information
taskDialog.SetExpansionArea(L"Additional information\non two lines.",
L"Click here for more information.",
L"Click here to hide the extra information.");
// Change the options to show the expanded information by default.
// It is necessary to retrieve the current options first.
int options = taskDialog.GetOptions();
options |= TDF_EXPANDED_BY_DEFAULT;
taskDialog.SetOptions(options);
taskDialog.DoModal();
CTaskDialog::SetOptions
設定 的選項 CTaskDialog
。
void SetOptions(int nOptionFlag);
參數
nOptionFlag
[in]要用於 的 CTaskDialog
旗標集合。
備註
這個方法會清除 的所有目前選項 CTaskDialog
。 若要保留目前的選項,您必須先使用 CTaskDialog::GetOptions 擷取它們,並將其與您想要設定的選項結合。
下表列出所有有效的選項。
名稱 | 描述 |
---|---|
TDF_ENABLE_HYPERLINKS | 啟用 中的 CTaskDialog 超連結。 |
TDF_USE_HICON_MAIN | 將 CTaskDialog 設定為將 用於 HICON 主要圖示的 。 替代方式是使用 LPCWSTR 。 |
TDF_USE_HICON_FOOTER | 將 CTaskDialog 設定為用於 HICON 頁尾圖示的 。 替代方式是使用 LPCWSTR 。 |
TDF_ALLOW_DIALOG_CANCELLATION | CTaskDialog 讓使用者使用鍵盤或使用對話方塊右上角的圖示關閉 ,即使 [取消 ] 按鈕未啟用也一樣 。 如果未設定此旗標且 未啟用 [取消 ] 按鈕,使用者就無法使用 Alt+F4、Escape 鍵或標題列的關閉按鈕來關閉對話方塊。 |
TDF_USE_COMMAND_LINKS | 將 CTaskDialog 設定為使用命令按鈕控制項。 |
TDF_USE_COMMAND_LINKS_NO_ICON | 將 設定 CTaskDialog 為使用命令按鈕控制項,而不顯示控制項旁的圖示。 TDF_USE_COMMAND_LINKS會覆寫TDF_USE_COMMAND_LINKS_NO_ICON。 |
TDF_EXPAND_FOOTER_AREA | 表示展開區域目前已展開。 |
TDF_EXPANDED_BY_DEFAULT | 判斷擴充區域是否預設為展開。 |
TDF_VERIFICATION_FLAG_CHECKED | 表示目前已選取驗證核取方塊。 |
TDF_SHOW_PROGRESS_BAR | 設定 CTaskDialog 以顯示進度列。 |
TDF_SHOW_MARQUEE_PROGRESS_BAR | 將進度列設定為選框進度列。 如果啟用此選項,您必須將TDF_SHOW_PROGRESS_BAR設定為具有預期的行為。 |
TDF_CALLBACK_TIMER | 表示回 CTaskDialog 呼間隔設定為大約 200 毫秒。 |
TDF_POSITION_RELATIVE_TO_WINDOW | 將 CTaskDialog 設定為相對於父視窗置中。 如果未啟用此旗標,則會 CTaskDialog 相對於監視器置中。 |
TDF_RTL_LAYOUT | 設定 CTaskDialog 從右至左閱讀配置的 。 |
TDF_NO_DEFAULT_RADIO_BUTTON | 表示出現時 CTaskDialog 未選取任何選項按鈕。 |
TDF_CAN_BE_MINIMIZED | 可讓使用者將 最小化 CTaskDialog 。 若要支援此選項, CTaskDialog 不可為強制回應。 MFC 不支援此選項,因為 MFC 不支援無 CTaskDialog 模式 。 |
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Setting new information to be able to reuse the dialog resource
taskDialog.SetWindowTitle(L"New title for the task dialog");
taskDialog.SetContent(L"New message to show the user.");
taskDialog.SetMainInstruction(L"Even more important!");
taskDialog.SetMainIcon(TD_ERROR_ICON);
taskDialog.SetDialogWidth(300);
// Add a footer
taskDialog.SetFooterText(L"Footer information for the dialog.");
taskDialog.SetFooterIcon(TD_INFORMATION_ICON);
// Add expansion information
taskDialog.SetExpansionArea(L"Additional information\non two lines.",
L"Click here for more information.",
L"Click here to hide the extra information.");
// Change the options to show the expanded information by default.
// It is necessary to retrieve the current options first.
int options = taskDialog.GetOptions();
options |= TDF_EXPANDED_BY_DEFAULT;
taskDialog.SetOptions(options);
taskDialog.DoModal();
CTaskDialog::SetProgressBarMarquee
設定 的選框列 CTaskDialog
,並將其新增至對話方塊。
void SetProgressBarMarquee(
BOOL bEnabled = TRUE,
int nMarqueeSpeed = 0);
參數
bEnabled
[in]TRUE 表示啟用選框列;FALSE 表示停用選框列,並將它從 CTaskDialog
中移除。
nMarqueeSpeed
[in]整數,表示選框線的速度。
備註
選框列會出現在 類別的主 CTaskDialog
文字下方。
使用 nMarqueeSpeed 來設定選框列的速度;較大的值表示速度較慢。 nMarqueeSpeed 的值為 0 ,會讓選框列以 Windows 的預設速度移動。
如果 nMarqueeSpeed 小於 0, 這個方法會擲回 ENSURE 宏的例外狀況。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Add a marquee progress bar.
taskDialog.SetProgressBarMarquee();
taskDialog.DoModal();
// Remove the marquee bar and replace it with a standard progress bar
taskDialog.SetProgressBarMarquee(0);
taskDialog.SetProgressBarRange(0, 100);
taskDialog.SetProgressBarPosition(75);
taskDialog.SetProgressBarState();
taskDialog.DoModal();
CTaskDialog::SetProgressBarPosition
調整進度列的位置。
void SetProgressBarPosition(int nProgressPos);
參數
nProgressPos
[in]進度列的位置。
備註
如果 nProgressPos 不在進度列範圍內,這個方法會擲回 ENSURE 宏的例外 狀況。 您可以使用 CTaskDialog::SetProgressBarRange 來變更進度列範圍 。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Add a marquee progress bar.
taskDialog.SetProgressBarMarquee();
taskDialog.DoModal();
// Remove the marquee bar and replace it with a standard progress bar
taskDialog.SetProgressBarMarquee(0);
taskDialog.SetProgressBarRange(0, 100);
taskDialog.SetProgressBarPosition(75);
taskDialog.SetProgressBarState();
taskDialog.DoModal();
CTaskDialog::SetProgressBarRange
調整進度列的範圍。
void SetProgressBarRange(
int nRangeMin,
int nRangeMax);
參數
nRangeMin
[in]進度列的下限。
nRangeMax
[in]進度列的上限。
備註
進度列的位置相對於 nRangeMin 和 nRangeMax 。 例如,如果 nRangeMin 為 50 且 nRangeMax 為 100,則 75 的位置會在進度列的一半之間。 使用 CTaskDialog::SetProgressBarPosition 來設定進度列的位置。
若要顯示進度列,必須啟用TDF_SHOW_PROGRESS_BAR選項,且不得啟用TDF_SHOW_MARQUEE_PROGRESS_BAR。 此方法會自動設定TDF_SHOW_PROGRESS_BAR並清除TDF_SHOW_MARQUEE_PROGRESS_BAR。 使用 CTaskDialog::SetOptions 手動變更 CTaskDialog 類別 實例 的選項。
如果 nRangeMin 不小於 nRangeMax , 這個方法會擲回 ENSURE 宏的例外狀況。 如果 CTaskDialog
已經顯示 ,而且具有選框進度列,這個方法也會擲回例外狀況。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Add a marquee progress bar.
taskDialog.SetProgressBarMarquee();
taskDialog.DoModal();
// Remove the marquee bar and replace it with a standard progress bar
taskDialog.SetProgressBarMarquee(0);
taskDialog.SetProgressBarRange(0, 100);
taskDialog.SetProgressBarPosition(75);
taskDialog.SetProgressBarState();
taskDialog.DoModal();
CTaskDialog::SetProgressBarState
設定進度列的狀態,並在 上 CTaskDialog
顯示它。
void SetProgressBarState(int nState = PBST_NORMAL);
參數
nState
[in]進度列的狀態。 如需可能的值,請參閱一節。
備註
如果 CTaskDialog
已經顯示 ,而且具有選框進度列,這個方法會擲回具有 ENSURE 宏的例外 狀況。
下表列出 nState 的 可能值。 在這些情況下,進度列會填滿一般色彩,直到到達指定的停止位置為止。 此時,它會根據狀態變更色彩。
名稱 | 描述 |
---|---|
PBST_NORMAL | 進度列填滿之後, CTaskDialog 不會變更列的色彩。 根據預設,一般色彩為綠色。 |
PBST_ERROR | 進度列填滿之後,會將 CTaskDialog 列的色彩變更為錯誤色彩。 根據預設,這是紅色的。 |
PBST_PAUSED | 進度列填滿之後,會將 CTaskDialog 列的色彩變更為暫停的色彩。 根據預設,這是黃色的。 |
您可以使用 CTaskDialog::SetProgressBarPosition 來設定進度列停止 的位置。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Add a marquee progress bar.
taskDialog.SetProgressBarMarquee();
taskDialog.DoModal();
// Remove the marquee bar and replace it with a standard progress bar
taskDialog.SetProgressBarMarquee(0);
taskDialog.SetProgressBarRange(0, 100);
taskDialog.SetProgressBarPosition(75);
taskDialog.SetProgressBarState();
taskDialog.DoModal();
CTaskDialog::SetRadioButtonOptions
啟用或停用選項按鈕。
void SetRadioButtonOptions(
int nRadioButtonID,
BOOL bEnabled);
參數
nRadioButtonID
[in]選項按鈕控制項的識別碼。
bEnabled
[in]TRUE 表示啟用選項按鈕;FALSE 可停用選項按鈕。
備註
如果 nRadioButtonID 不是選項按鈕的有效識別碼,這個方法會擲回 ENSURE 宏的例外 狀況。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
taskDialog.AddRadioButton(201, L"First option");
taskDialog.AddRadioButton(202, L"Second option");
taskDialog.AddRadioButton(203, L"Third option");
taskDialog.DoModal();
int selection = taskDialog.GetSelectedRadioButtonID();
switch (selection)
{
case 201:
// TODO: Place processing here for the first
// radio button.
break;
case 202:
// TODO: Place processing here for the second
// radio button.
break;
case 203:
// TODO: Place processing here for the third
// radio button.
break;
default:
break;
}
// Remove all the radio buttons so that we can use the same task
// dialog with new radio buttons.
taskDialog.RemoveAllRadioButtons();
taskDialog.AddRadioButton(301, L"New first option");
taskDialog.AddRadioButton(302, L"New second option");
taskDialog.AddRadioButton(303,
L"New third option should be disabled");
// Change the default radio button to the second option
taskDialog.SetDefaultRadioButton(302);
// Make sure the third option is disabled.
if (taskDialog.IsRadioButtonEnabled(303))
{
taskDialog.SetRadioButtonOptions(303, FALSE);
}
taskDialog.DoModal();
selection = taskDialog.GetSelectedRadioButtonID();
switch (taskDialog.GetSelectedRadioButtonID())
{
case 301:
// TODO: Place processing here for new first
// command button control.
break;
case 302:
// TODO: Place processing here for new second
// command button control.
break;
case 303:
// TODO: Place processing here for the new third
// command button control.
break;
default:
break;
}
// Remove all the radio button controls and add new ones from
// the string table resource.
taskDialog.RemoveAllRadioButtons();
taskDialog.LoadRadioButtons(1001, 1005);
CTaskDialog::SetVerificationCheckbox
設定驗證核取方塊的核取狀態。
void SetVerificationCheckbox(BOOL bChecked);
參數
bChecked
[in]TRUE 表示顯示 時 CTaskDialog
已選取驗證核取方塊;FALSE 表示顯示 時 CTaskDialog
未選取驗證核取方塊。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Add the verification checkbox and set the default state.
taskDialog.SetVerificationCheckboxText(L"Remember your selection.");
taskDialog.SetVerificationCheckbox(false);
taskDialog.DoModal();
if (taskDialog.GetVerificationCheckboxState())
{
// TODO: Write settings of the task dialog to the registry
}
CTaskDialog::SetVerificationCheckboxText
設定顯示在 [驗證] 核取方塊右邊的文字。
void SetVerificationCheckboxText(CString& strVerificationText);
參數
strVerificationText
[in]這個方法顯示在 [驗證] 核取方塊旁的文字。
備註
如果類別的這個實例已經顯示,這個方法會擲回具有 ENSURE 宏的 CTaskDialog
例外 狀況。
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Add the verification checkbox and set the default state.
taskDialog.SetVerificationCheckboxText(L"Remember your selection.");
taskDialog.SetVerificationCheckbox(false);
taskDialog.DoModal();
if (taskDialog.GetVerificationCheckboxState())
{
// TODO: Write settings of the task dialog to the registry
}
CTaskDialog::SetWindowTitle
設定 的 CTaskDialog
標題。
void SetWindowTitle(CString& strWindowTitle);
參數
strWindowTitle
[in]的新標題 CTaskDialog
。
備註
範例
// TODO: Replace the strings below with the appropriate message,
// main instruction, and dialog title
CString message("This is an important message to the user.");
CString mainInstruction("Important!\nPlease read!");
CString title("Alert Dialog");
CTaskDialog taskDialog(message, mainInstruction, title,
TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
// Setting new information to be able to reuse the dialog resource
taskDialog.SetWindowTitle(L"New title for the task dialog");
taskDialog.SetContent(L"New message to show the user.");
taskDialog.SetMainInstruction(L"Even more important!");
taskDialog.SetMainIcon(TD_ERROR_ICON);
taskDialog.SetDialogWidth(300);
// Add a footer
taskDialog.SetFooterText(L"Footer information for the dialog.");
taskDialog.SetFooterIcon(TD_INFORMATION_ICON);
// Add expansion information
taskDialog.SetExpansionArea(L"Additional information\non two lines.",
L"Click here for more information.",
L"Click here to hide the extra information.");
// Change the options to show the expanded information by default.
// It is necessary to retrieve the current options first.
int options = taskDialog.GetOptions();
options |= TDF_EXPANDED_BY_DEFAULT;
taskDialog.SetOptions(options);
taskDialog.DoModal();
CTaskDialog::ShowDialog
建立並顯示 CTaskDialog
。
static INT_PTR ShowDialog(
const CString& strContent,
const CString& strMainInstruction,
const CString& strTitle,
int nIDCommandControlsFirst,
int nIDCommandControlsLast,
int nCommonButtons = TDCBF_YES_BUTTON | TDCBF_NO_BUTTON,
int nTaskDialogOptions = TDF_ENABLE_HYPERLINKS | TDF_USE_COMMAND_LINKS,
const CString& strFooter = _T(""));
參數
strContent
[in]要用於 之內容的 CTaskDialog
字串。
strMainInstruction
[in]的主要指示 CTaskDialog
。
strTitle
[in]的 CTaskDialog
標題。
nIDCommandControlsFirst
[in]第一個命令的字串識別碼。
nIDCommandControlsLast
[in]最後一個命令的字串識別碼。
nCommonButtons
[in]要加入至 的 CTaskDialog
按鈕遮罩。
nTaskDialogOptions
[in]要用於 CTaskDialog
的選項組。
strFooter
[in]要當做頁尾使用的字串。
傳回值
整數,對應至使用者所做的選取範圍。
備註
這個靜態方法可讓您建立 類別的實例, CTaskDialog
而不需在程式碼中明確建立 CTaskDialog
物件。 因為沒有 CTaskDialog
物件,所以如果您使用此方法向使用者顯示 CTaskDialog
,則無法呼叫 的任何其他方法 CTaskDialog
。
這個方法會使用應用程式資源檔中的資料來建立命令按鈕控制項。 資源檔中的字串資料表有數個字串與相關聯的字串識別碼。 這個方法會在包含 nIDCommandControlsFirst 和 nCommandControlsLast 之間 ,針對字串資料表中的每個有效專案新增命令按鈕控制項。 對於這些命令按鈕控制項,字串資料表中的字串是控制項的標題,而字串識別碼則是控制項的識別碼。
如需有效選項的清單,請參閱 CTaskDialog::SetOptions 。
當使用者 CTaskDialog
選取通用按鈕、命令連結控制項或關閉 時 CTaskDialog
關閉 。 傳回值是指出使用者如何關閉對話方塊的識別碼。
範例
// TODO: Replace the string below with the actual message to the user
CString message("Important information to the user");
// TODO: Replace the string below with the title of this project
CString title("Project Title");
CString emptyString;
if (CTaskDialog::IsSupported())
{
CTaskDialog::ShowDialog(message, emptyString, title, 0, 0,
TDCBF_OK_BUTTON);
}
else
{
AfxMessageBox(message);
}
CTaskDialog::TaskDialogCallback
架構會呼叫此方法,以回應各種 Windows 訊息。
friend:
HRESULT TaskDialogCallback(
HWND hWnd,
UINT uNotification,
WPARAM wParam,
LPARAM lParam,
LONG_PTR dwRefData);
參數
hwnd
[in]結構的 m_hWnd
CTaskDialog
控制碼。
uNotification
[in]指定所產生訊息的通知程式碼。
wParam
[in]訊息的詳細資訊。
lParam
[in]訊息的詳細資訊。
dwRefData
[in]回呼訊息所套用之 物件的指標 CTaskDialog
。
傳回值
取決於特定的通知程式碼。 如需詳細資訊,請參閱<備註>一節。
備註
的預設實作 TaskDialogCallback
會處理特定訊息,然後呼叫 CTaskDialog 類別 的適當 On 方法 。 例如,為了回應TDN_BUTTON_CLICKED訊息, TaskDialogCallback
呼叫 CTaskDialog::OnCommandControlClick 。
wParam 和 lParam 的值 取決於特定產生的訊息。 這兩個值都可以是空的。 下表列出支援的預設通知,以及 wParam 和 lParam 的值 代表的內容。 如果您在衍生類別中覆寫此方法,您應該為下表中的每個訊息實作回呼程式碼。
通知訊息 | wParam 值 | lParam 值 |
---|---|---|
TDN_CREATED | 未使用。 | 未使用。 |
TDN_NAVIGATED | 未使用。 | 未使用。 |
TDN_BUTTON_CLICKED | 命令按鈕控制項識別碼。 | 未使用。 |
TDN_HYPERLINK_CLICKED | 未使用。 | 包含連結的 LPCWSTR 結構。 |
TDN_TIMER | 建立 之後 CTaskDialog 的毫秒或計時器重設的時間。 |
未使用。 |
TDN_DESTROYED | 未使用。 | 未使用。 |
TDN_RADIO_BUTTON_CLICKED | 選項按鈕識別碼。 | 未使用。 |
TDN_DIALOG_CONSTRUCTED | 未使用。 | 未使用。 |
TDN_VERIFICATION_CLICKED | 如果核取核取方塊,則為 1,如果不是,則為 0。 | 未使用。 |
TDN_HELP | 未使用。 | 未使用。 |
TDN_EXPANDO_BUTTON_CLICKED | 如果展開區域已折迭,則為 0;如果顯示展開文字,則為非零。 | 未使用。 |
另請參閱
意見反映
https://aka.ms/ContentUserFeedback。
即將推出:我們會在 2024 年淘汰 GitHub 問題,並以全新的意見反應系統取代並作為內容意見反應的渠道。 如需更多資訊,請參閱:提交及檢視以下的意見反映: