Abhinay K Reddyreddy
Abhinay K Reddyreddy

Reputation: 511

how to set the default button in a TaskDialog?

I am using TaskDialog API in a win32 app. I created a Task Dialog with YES/NO buttons but I can't find any option to set the No button as default. YES button is always the default. Please let me know if there is a way to set the NO button as default. I know TaskDialogIndirect supports a default button option but its an overkill for what i am trying to do. I just want a simple YES/NO Dialog with NO button as default. I did not want to use the MessageBox API because i don't want a close button in the titlebar.

Thanks,

Abhinay

Upvotes: 3

Views: 1285

Answers (2)

Ajay
Ajay

Reputation: 18421

In addition to answer given by David, I would add my two cents - If you are using MFC, you may use CTaskDialog class.

Upvotes: 0

David
David

Reputation: 13580

Given:

TASKDIALOGCONFIG tc;

Set the default button by setting the nDefaultButton member, e.g.:

tc.nDefaultButton = ...;

"This may be any of the values specified in nButtonID members of one of the TASKDIALOG_BUTTON structures in the pButtons array, or one of the IDs corresponding to the buttons specified in the dwCommonButtons member:

  • IDCANCEL Make the Cancel button the default.
  • IDNO Make the No button the default.
  • IDOK Make the OK button the default.
  • IDRETRY Make the Retry button the default.
  • IDYES Make the Yes button the default.
  • IDCLOSE Make the Close button the default."

The above bit shamelessly quoted from MSDN.

So basically, if you're using the standard predefined buttons, set the field to one of the above constants; if you're using a custom button, set it to the ID you use when specifying the button.

Upvotes: 2

Related Questions