CTaskDialog::AddCommandControl

加入新的命令按鈕控制項加入至 CTaskDialog

void AddCommandControl(
   int nCommandControlID,
   const CString& strCaption,
   BOOL bEnabled = TRUE,
   BOOL bRequiresElevation = FALSE
);

參數

  • [in] nCommandControlID
    Command 控制項識別項。

  • [in] strCaption
    CTaskDialog 向使用者顯示的字串。使用這個字串解譯命令的用途。

  • [in] bEnabled
    布林值 (Boolean) 參數新增按鈕是否啟用或停用。

  • [in] bRequiresElevation
    布林值 (Boolean) 參數順序是否需要提高權限。

備註

CTaskDialog 類別 可以顯示不限數目的命令按鈕控制項。不過,如果 CTaskDialog ,顯示任何命令按鈕控制項,它可顯示最多六個按鈕。如果 CTaskDialog 沒有命令按鈕控制項,它可顯示不限數目的按鈕。

當使用者選取命令按鈕控制項時, CTaskDialog 關閉。您可以使用 CTaskDialog::DoModal,如果您的應用程式會顯示 對話方塊中, 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);

需求

標題: afxtaskdialog.h

請參閱

參考

CTaskDialog 類別

階層架構圖

CTaskDialog::ClickCommandControl

CTaskDialog::GetSelectedCommandControlID

CTaskDialog::IsCommandControlEnabled

CTaskDialog::RemoveAllCommandControls

CTaskDialog::SetCommandControlOptions

CTaskDialog::SetDefaultCommandControl