0

I'm using a task dialog via the TaskDialogIndirect function.

Everything works as expected except that the width of the dialog is exactly twice of what I specified in the cxWidth field of the TASKDIALOGCONFIG structure.

Relevant code:

  TASKDIALOGCONFIG tdc;
  ZeroMemory(&tdc, sizeof(tdc));
  tdc.cbSize = sizeof(TASKDIALOGCONFIG);
  tdc.hwndParent = hwndParent;
  tdc.hInstance = NULL;
  tdc.pszWindowTitle = L"Title";
  tdc.pszMainInstruction = L"Foo";
  tdc.pszContent = L"Bar";
  tdc.dwFlags = TDF_POSITION_RELATIVE_TO_WINDOW;
  tdc.cxWidth = 150;
  int result;
  HRESULT hr = TaskDialogIndirect(&tdc, &result, NULL, NULL);

The documentation says that the cxWidth is the width in dialog units.

With the code above the width of the dialog is 300 pixels instead of 150 which means that one horizontal dialog unit is 2 which seems really small.

If I want to specify the width of the task dialog explicitely, how should I proceed? Is suppose I cannot rely on the fact that one horizontal dialog unit is always 2 in this case.

Uli Gerhardt
  • 13,748
  • 1
  • 45
  • 83
Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
  • 1
    I suppose that your question is really, "what are dialog units?" I would expect that websearch would tell you the answer. – David Heffernan Jun 26 '19 at 15:40
  • @DavidHeffernan I know what dialog units are, they depend on the font used in the dialog, which I don't know. – Jabberwocky Jun 26 '19 at 15:47
  • What are you expecting? It will never be 150 pixels wide if you ask for 150 dialog units. You cannot rely on it being 2 either. – Anders Jun 26 '19 at 17:29
  • 1
    https://learn.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getdialogbaseunits, which also contains some example code for properly calculating the values in either direction. – Ken White Jun 26 '19 at 17:43
  • @Anders I don't expect anything, I want to know what to do in orde3r to fix the width reliably – Jabberwocky Jun 26 '19 at 18:09
  • @KenWhite [`GetDialogBaseUnits`](https://learn.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getdialogbaseunits) returns 8 for the x dialog base unit. This is not really helpful as I have a factor of 2 as mentioned in the question. – Jabberwocky Jun 27 '19 at 09:46
  • 1
    @Jabberwocky: You didn't read far enough down that page, then. There's a calculation for conversion. It's not straight multiplication - it's a MulDiv(). – Ken White Jun 27 '19 at 11:52
  • @KenWhite OK, that works, thanks. Now my only concern is if I can trust the values returned by `GetDialogBaseUnits`. – Jabberwocky Jun 27 '19 at 12:09
  • @Jabberwocky: It's been reliable (and maintained) since the days of Windows 3.x. I'd think you'll be OK. – Ken White Jun 27 '19 at 12:21

0 Answers0