2

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.

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
  • 1
    You could not use the `nCommonButtons`, but instead define custom buttons and use `pButton`. [link: TASKDIALOGCONFIG](https://msdn.microsoft.com/en-us/library/windows/desktop/bb787473(v=vs.85).aspx), [link:TASKDIALOG_BUTTON](https://msdn.microsoft.com/en-us/library/windows/desktop/bb787475(v=vs.85).aspx) – JHBonarius May 03 '18 at 12:06
  • 2
    Why would your application resist the system locale? – Chris Becke May 03 '18 at 12:43
  • @ChrisBecke The application's UI exists only in french, english and german. So on a spanish system the application's UI would either be in french, english or german anyway. So it would be strange to have spanish buttons on a non spanish UI. – Jabberwocky May 03 '18 at 13:09
  • @JHBonarius that looks promising, but apparenty you cannot do this with MFC's `CTaskDialog`, but only with the raw Win32 API. – Jabberwocky May 03 '18 at 14:02
  • @JHBonarius you showed me the path, thanks a lot. – Jabberwocky May 03 '18 at 15:11
  • I understand that concern, but Windows localisation already offers fallbacks. If you just provide your resources properly localised then your app will be displayed in the desktop locale, or a consistently chosen fallback. – Chris Becke May 04 '18 at 12:53
  • @ChrisBecke this doesn't resolve the problem described in my first comment addressed to you (e.g. spanish OK, Cancel, Retry etc. buttons and french texts above). – Jabberwocky May 04 '18 at 12:58
  • @MichaelWalz - as I understood it you would provide a single English/French/German version of your app, and a user with a system language so configured would see that language. If your application uses the MUI apis to advertise your supported languages,a system with Spanish - say - as the primary system UI language, would fall your entire application back to one of your supported languages that closest matches the systems fallback languages. So a Spanish user that understands German more than English could see your entire app in German, including dialogs. – Chris Becke May 04 '18 at 13:40
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/170381/discussion-between-michael-walz-and-chris-becke). – Jabberwocky May 04 '18 at 13:42

1 Answers1

3

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.

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115