c++windowswinapimfctaskdialog

Replacing texts “OK”, “Cancel”, “Yes”, “No” in Windows Task Dialogs


On a Win32 Task Dialog the texts "OK", "Cancel", "Yes", "No" etc. of the standard buttons are automatically displayed in the system's language. That can be a problem if the language of a Software is different of the system's language.

For instance if a customer installs the French version of our software on an English Windows, the Task Dialog's content will be in French, but the standard buttons at the bottom of the Task Dialog will be in English no matter what.

Does anybody know how can I change these texts.

This question is similar to this SO question which is dealing with property sheets.

UPDATE:

I tried deriving a class from CTaskDialog and override the OnInit() methode in oder to grab the CTaskDialog's m_hWnd and have a similar approach than in the question mentioned beforehand, but unfortunately CTaskDialog::m_hWnd is private:

class CMyTaskDialog : public CTaskDialog
{
public:
  CMyTaskDialog(_In_ const CString& strContent, _In_ const CString& strMainInstruction, _In_ const CString& strTitle,
    _In_ int nCommonButtons = TDCBF_OK_BUTTON | TDCBF_CANCEL_BUTTON, _In_ int nTaskDialogOptions = TDF_ENABLE_HYPERLINKS | TDF_USE_COMMAND_LINKS,
    _In_ const CString& strFooter = CString());

  virtual HRESULT OnCreate();
};

CMyTaskDialog::CMyTaskDialog(_In_ const CString& strContent, _In_ const CString& strMainInstruction, _In_ const CString& strTitle,
  _In_ int nCommonButtons, _In_ int nTaskDialogOptions,
  _In_ const CString& strFooter) :
  CTaskDialog(strContent, strMainInstruction, strTitle,nCommonButtons, nTaskDialogOptions, strFooter)
{
}


HRESULT CMyTaskDialog::OnCreate()
{
  // tried to do stuff with m_hWnd, but m_hWnd is private :-(
  return __super::OnCreate();
}

However this is a very poor idea, it can be done properly as shown in my own answer below.


Solution

  • It's actually quite simple:

    Instead of using the standard buttons TDCBF_YES_BUTTON, TDCBF_NO_BUTTON, TDCBF_CANCEL_BUTTON etc. you need to use non of these buttons but add your own buttons with AddCommandControl, and create the CTaskDialog object with 0 in the nTaskDialogOptions parameter and thus disabling the TDF_USE_COMMAND_LINKS mode. Then those buttons won't be displayed as command links but as simple buttons.

    Minimal example:

      CTaskDialog taskDialog(L"", L"Voulez-vous enregistrer les modifications?",
                             L"Some title", 0, 0);
    
      taskDialog.AddCommandControl(100, L"Oui");
      taskDialog.AddCommandControl(102, L"Non"); 
      taskDialog.SetDefaultCommandControl(100);
      INT_PTR x = taskDialog.DoModal();
      ...
    

    enter image description here

    However there is one problem: you cannot have buttons and a command links in the same task dialog. But this problem is a minor one (at least for me) because IMO having command links and buttons in the same task dialog is probably not the best idea anyway.