- 1 year ago
How would I change the footer text of a TaskDialogIndirect from inside its callback function?
To change the footer text of a TaskDialogIndirect
from inside its callback function, you can call the SetElementText()
function with the TDE_CONTENT
flag to set the text of the TDIE_FOOTER
element.
Here's an example of how to change the footer text of a TaskDialogIndirect
from inside its callback function:
c++#include <Windows.h>
#include <CommCtrl.h>
int CALLBACK TaskDialogCallback(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, LONG_PTR dwRefData) {
switch (msg) {
case TDN_CREATED:
// Set the initial footer text
TaskDialog_SetElementText(hwnd, TDIE_FOOTER, L"Initial footer text");
break;
case TDN_BUTTON_CLICKED:
if (wParam == IDOK) {
// Change the footer text when the OK button is clicked
TaskDialog_SetElementText(hwnd, TDIE_FOOTER, L"Footer text changed by callback");
}
break;
}
return S_OK;
}
int main() {
// Initialize COM
CoInitialize(NULL);
// Create a TASKDIALOGCONFIG structure
TASKDIALOGCONFIG config = {};
config.cbSize = sizeof(config);
config.hInstance = NULL;
config.dwFlags = TDF_ALLOW_DIALOG_CANCELLATION | TDF_USE_COMMAND_LINKS;
config.pszWindowTitle = L"Task Dialog Test";
config.pszMainInstruction = L"Main instruction text";
config.pszContent = L"Content text";
config.pszExpandedInformation = L"Expanded information text";
config.pszCollapsedControlText = L"Show more information";
config.pszExpandedControlText = L"Hide more information";
config.pfCallback = TaskDialogCallback;
// Show the task dialog
int button = 0;
TaskDialogIndirect(&config, &button, NULL, NULL);
// Cleanup
CoUninitialize();
return 0;
}
In this example, we define a callback function called TaskDialogCallback()
that handles the TDN_CREATED
and TDN_BUTTON_CLICKED
messages. When the dialog is created, we set the initial footer text using the TaskDialog_SetElementText()
function with the TDIE_FOOTER
element. When the OK button is clicked, we change the footer text using the same function.
In the main()
function, we create a TASKDIALOGCONFIG
structure and set its properties to configure the task dialog. We specify the TaskDialogCallback()
function as the callback function using the pfCallback
property. We then show the task dialog using the TaskDialogIndirect()
function.
Note that to use the TaskDialog_SetElementText()
function, you need to include the CommCtrl.h
header and link against the comctl32.lib
library.