Hi all, Ive created a four button dialog box as a function and I want to return the number or name of the button pushed.
This is what I have;
At present I can only exit the form and get a zero returned! I want to start the dialog, get a response from the user and then close the form.
What am I doign wrong?, any help appreciated (as Im lost).
This is what I have;
Code:
#include <windows.h>
#include <tchar.h>
#define IDC_BUTTON1 1201
#define IDC_BUTTON2 1202
#define IDC_BUTTON3 1203
#define IDC_BUTTON4 1204
#define IDC_STATIC_1 1200
HINSTANCE InstanceHandle;
CHAR ButtonClicked = 'A';
TCHAR BoxText[] = _T("Filename");
LRESULT CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
CreateWindow("STATIC",
BoxText, // Initial Text
WS_CHILD | WS_VISIBLE | SS_LEFT, // Style
5, 5, 100, 30, // position
hwndDlg, // Owner
(HMENU)(IDC_STATIC_1), // ID
InstanceHandle, // The application
0);
CreateWindow("BUTTON",
"Yes", // Button Text
WS_CHILD | WS_VISIBLE, // Style
20, 70, 60, 30, // position
hwndDlg, // Owner
(HMENU)(IDC_BUTTON1), // ID
InstanceHandle, // The application
0);
CreateWindow("BUTTON",
"No", // Button Text
WS_CHILD | WS_VISIBLE, // Style
90, 70, 60, 30, // position
hwndDlg, // Owner
(HMENU)(IDC_BUTTON2), // ID
InstanceHandle, // The application
0);
CreateWindow("BUTTON",
"Not to All", // Button Text
WS_CHILD | WS_VISIBLE, // Style
200, 70, 60, 30, // position
hwndDlg, // Owner
(HMENU)(IDC_BUTTON3), // ID
InstanceHandle, // The application
0);
CreateWindow("BUTTON",
"Yes to All", // Button Text
WS_CHILD | WS_VISIBLE, // Style
360, 70, 60, 30, // position
hwndDlg, // Owner
(HMENU)(IDC_BUTTON4), // ID
InstanceHandle, // The application
0);
break;
case WM_COMMAND:
if(HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_BUTTON1)
{
ButtonClicked == '1';
}
if(HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_BUTTON2)
{
ButtonClicked == '2';
}
if(HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_BUTTON3)
{
ButtonClicked == '3';
}
if(HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_BUTTON4)
{
ButtonClicked == '4';
}
break;
}
return DefWindowProc(hwndDlg, msg, wParam, lParam);
}
extern "C"
int __declspec(dllexport) WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, INT nCmdShow)
{
InstanceHandle = hInstance;
WNDCLASS wc;
memset(&wc, 0, sizeof(WNDCLASS));
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wc.lpfnWndProc = DialogProc;
wc.hInstance = InstanceHandle;
wc.hbrBackground = (HBRUSH )(COLOR_BTNFACE + 1);
wc.lpszClassName = "ClassName";
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
if(!RegisterClass(&wc))
return FALSE;
HWND WindowHandle = CreateWindow("ClassName",
"ClassName", // Caption text
WS_MINIMIZEBOX | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | WS_MAXIMIZEBOX | WS_CAPTION |
WS_BORDER | WS_SYSMENU,
100, 100, 450, 150, // Position
NULL,
NULL,
InstanceHandle,
0);
MSG Msg;
while (GetMessage(&Msg, WindowHandle, 0, 0xFFFF) > 0)
{
if(!IsDialogMessage(WindowHandle, &Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
return 0;
}
At present I can only exit the form and get a zero returned! I want to start the dialog, get a response from the user and then close the form.
What am I doign wrong?, any help appreciated (as Im lost).