Home > other >  How would I change the footer text of a TaskDialogIndirect from inside its callback function?
How would I change the footer text of a TaskDialogIndirect from inside its callback function?

Time:12-30

I am currently making a TaskDialogIndirect with a limited response time. The only issue is, that I cannot change the footer text of the TaskDialogIndirect after it has been created.

I have set up a timer and want to change the footer's text to show the timer's progress. The only issue is that my code to change the text is not working.

Here is the code that I am using to change the text. (hwnd supplied by callback function):

HWND MainBody = GetWindow(hwnd, GW_CHILD);  // Getting the DirectUIHWND window

switch (msg) {
    case TDN_DIALOG_CONSTRUCTED:
        //SetDlgItemText(hwnd, 3, L"Test");  // Does not work
        SetWindowText(GetDlgItem(MainBody, 3), L"TEST"); // Google told me that 3 is the common footer definition
        break;
}

CodePudding user response:

Don't try to dig into the internals and manipulate the constituent elements yourself. Instead, use the documented APIs. This is always good practice to follow in Windows programming.

Specifically, send the Task Dialog window a TDM_SET_ELEMENT_TEXT message with the WPARAM argument set to TDE_FOOTER and the LPARAM argument set to a pointer to the string containing the new text (or the ID of a string resource, created with the MAKEINTRESOURCE macro).

switch (msg) {
    case TDN_DIALOG_CONSTRUCTED:
        SendMessage(hwnd,
                    TDM_SET_ELEMENT_TEXT,
                    static_cast<WPARAM>(TDE_FOOTER),
                    reinterpret_cast<LPARAM>(L"Construction complete!"));
        break;
}

Alternatively, if you don't want the Task Dialog to resize itself to accommodate the new text, send a TDM_UPDATE_ELEMENT_TEXT message instead. The parameters are otherwise the same. See the "Remarks" section of the linked documentation for an explanation of the differences in behavior between these two similar messages.

This works inside or outside of the callback function. All you need is a handle to the Task Dialog window. (Of course, if the Task Dialog is modal, unless you've installed some type of hook, you'll essentially have to do this from inside of the callback function, as that's the only place your code would be executing when the Task Dialog is visible.)

  • Related