I am making a function that uses TaskDialogIndirect()
to construct more advanced Message Boxes. I want to be able to pass custom buttons to the function. For that, I am using an array of TASKDIALOG_BUTTON
as a parameter. The only problem is that I am getting an error and I do not know what it means:
C2061 - Syntax Error: identifier 'TASKDIALOG_BUTTON'
I could not find any information on the Internet about this exact issue.
CMessageBox.hpp:
#pragma once
#include "Global.hpp"
struct TaskDialogData
{
int X;
int Y;
};
class CMessageBox
{
public:
static int MessageBoxPosL(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType, int X, int Y, PCWSTR Icon, TASKDIALOG_BUTTON CustomBtns[], TASKDIALOG_COMMON_BUTTON_FLAGS StandardBtns = NULL, TASKDIALOG_FLAGS flags = NULL);
};
CMessageBox.cpp:
#include "CMessageBox.hpp"
static HRESULT CALLBACK TaskDialogCallback(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, LONG_PTR lpRefData)
{
if (msg == TDN_DIALOG_CONSTRUCTED) // This sets the position of the MessageBox
{
TaskDialogData* data = (TaskDialogData*)lpRefData;
SetWindowPos(hwnd, NULL, data->X, data->Y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
else if (msg == TDN_HYPERLINK_CLICKED) { // Opens all hyperlinks in default browser
LPCTSTR url = (LPCTSTR)lParam;
ShellExecute(NULL, _T("open"), url, NULL, NULL, SW_SHOW);
}
return S_OK;
}
int CMessageBox::MessageBoxPosL(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType, int X, int Y, PCWSTR Icon, TASKDIALOG_BUTTON CustomBtns[], TASKDIALOG_COMMON_BUTTON_FLAGS StandardBtns, TASKDIALOG_FLAGS flags)
{
TaskDialogData data;
data.X = X;
data.Y = Y;
TASKDIALOGCONFIG config = {};
config.cbSize = sizeof(config);
config.hwndParent = hWnd; // Parent window; SHOULD BE NORMALLY NULL!
config.pszWindowTitle = (PCWSTR)lpCaption;
config.pszContent = (PCWSTR)lpText;
config.pfCallback = &TaskDialogCallback; // Callback function
config.lpCallbackData = (LONG_PTR)&data; // Data sent to callback function
config.dwFlags = TDF_ENABLE_HYPERLINKS | flags;
config.dwCommonButtons = StandardBtns;
config.pButtons = CustomBtns;
config.cButtons = _ARRAYSIZE(CustomBtns);
config.pszMainIcon = Icon;
int button = 0;
TaskDialogIndirect(&config, &button, NULL, NULL);
return button; //This returns the Button that was clicked in the TaskDialog
}