Button Creation, Handling the Click event
-
I searched for hours, but everything was C# or C++ mfc. I created a button, using CreateWindow, I found it on a tutorial site on how to make window controls, but there no example on how to handle the click. So I wrote this, am I missing something like a SendMessage to register the button?
HWND bt_IIS_Install;
bt_IIS_Exit = CreateWindow(L"button", L"Exit", WS_CHILD,
winWidth / 2 - 200,
winHeight - 90,
180, 32, h_IIS_Install_Client, NULL, GetModuleHandle(NULL), 0
);
ShowWindow( bt_IIS_Exit, SW_SHOW);I found this, that handles a dialog response, so I'm guessing that this is how I capture the button clicks, but I need to assign the defintion to the button.
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
//EndDialog(hDlg, LOWORD(wParam));
//return (INT_PTR)TRUE;
}break;
Am I on the right track here?
-
I searched for hours, but everything was C# or C++ mfc. I created a button, using CreateWindow, I found it on a tutorial site on how to make window controls, but there no example on how to handle the click. So I wrote this, am I missing something like a SendMessage to register the button?
HWND bt_IIS_Install;
bt_IIS_Exit = CreateWindow(L"button", L"Exit", WS_CHILD,
winWidth / 2 - 200,
winHeight - 90,
180, 32, h_IIS_Install_Client, NULL, GetModuleHandle(NULL), 0
);
ShowWindow( bt_IIS_Exit, SW_SHOW);I found this, that handles a dialog response, so I'm guessing that this is how I capture the button clicks, but I need to assign the defintion to the button.
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
//EndDialog(hDlg, LOWORD(wParam));
//return (INT_PTR)TRUE;
}break;
Am I on the right track here?
You should use the hMenu parameter to specify the control id of your button (IDOK or IDCANCEL in your case) From MSDN: hMenu [in, optional] A handle to a menu, or specifies a child-window identifier depending on the window style. For an overlapped or pop-up window, hMenu identifies the menu to be used with the window; it can be NULL if the class menu is to be used. For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window.
-
You should use the hMenu parameter to specify the control id of your button (IDOK or IDCANCEL in your case) From MSDN: hMenu [in, optional] A handle to a menu, or specifies a child-window identifier depending on the window style. For an overlapped or pop-up window, hMenu identifies the menu to be used with the window; it can be NULL if the class menu is to be used. For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window.
-
You should use the hMenu parameter to specify the control id of your button (IDOK or IDCANCEL in your case) From MSDN: hMenu [in, optional] A handle to a menu, or specifies a child-window identifier depending on the window style. For an overlapped or pop-up window, hMenu identifies the menu to be used with the window; it can be NULL if the class menu is to be used. For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window.
Well that took awhile to figure out. I created a menu in my resource file, and assigned the number to it in the other resource file. Then added the single hMenu item to the create window so WM_COMMAND can pick it up as the wParam. Thanks for the pointer to the huge lesson that I really learned from.
HWND bt_IIS_Install;
bt_IIS_Exit = CreateWindow(L"BUTTON", L"Exit", WS_CHILD,
winWidth / 2 - 200,
winHeight - 90,
180, 32, hIIS_Install, (HMENU)IDC_IIS_WS_EXIT, GetModuleHandle(NULL), 0
);
ShowWindow( bt_IIS_Exit, SW_SHOW); -
I searched for hours, but everything was C# or C++ mfc. I created a button, using CreateWindow, I found it on a tutorial site on how to make window controls, but there no example on how to handle the click. So I wrote this, am I missing something like a SendMessage to register the button?
HWND bt_IIS_Install;
bt_IIS_Exit = CreateWindow(L"button", L"Exit", WS_CHILD,
winWidth / 2 - 200,
winHeight - 90,
180, 32, h_IIS_Install_Client, NULL, GetModuleHandle(NULL), 0
);
ShowWindow( bt_IIS_Exit, SW_SHOW);I found this, that handles a dialog response, so I'm guessing that this is how I capture the button clicks, but I need to assign the defintion to the button.
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
//EndDialog(hDlg, LOWORD(wParam));
//return (INT_PTR)TRUE;
}break;
Am I on the right track here?
I did this in one of my articles - Mousey! Roll Over and Park[^] The settings dialog and all its controls are created using
CreateWindow
.«_Superman_» _I love work. It gives me something to do between weekends.
-
I did this in one of my articles - Mousey! Roll Over and Park[^] The settings dialog and all its controls are created using
CreateWindow
.«_Superman_» _I love work. It gives me something to do between weekends.
Great article. So does that mean that I created my buttons correctly? Writing an app in c++ has been my goal for a long time. Finally had a reason to pursue the next step. I don't want to put anymore visual basic programs out there any more, too much trouble to package and deploy them. I've got this nice eCommerce program, but I can't anybody to use it because it's not super easy to setup and deploy. So this program will make it easier to start using it. The goal is to use a windows program install the web server, create the default web site, import database, create email templates and so forth. Thanks for looking at my post! jkirkerx