I have created a form in wein 32 yet i dont know how to create controls on the form and how to see when theyre clicked. How do i add controls and now when a button is pressed or something like that ?
Printable View
I have created a form in wein 32 yet i dont know how to create controls on the form and how to see when theyre clicked. How do i add controls and now when a button is pressed or something like that ?
Example - a button. When that button is clicked, a WM_COMMAND message will be sent to your application. The wParam information will contain the Dialogue ID of the button. You can use this in your WndProc:
Code:WndProc(...) {
if(uMsg == WM_COMMAND && wParam == IDD_MYBTN) {
MessageBox(hwnd, "Button pressed", "Msg", MB_OK);
}
}
Thanks (i can use that), But how do i create the button
In a dialogue, you need to put it into the resource file. Select the "Resources" tab in the VC IDE, and open up the dialogue. It's pretty much like VB from there, apart from there's no event handling AT ALL (unless you use MFC, which it's not a good idea to until you understand how Windows works). I'll email you a small generic app.
I know that part but with win 32 where you hard code all of the controls how do u do that
It's all in there - you should get an email with a couple of projects in...Yahoo!'s mail system notwithstanding ;)
I'll be finished in about 5mins :)
Use CreateWindowEx.
Thanks :-))))
If there's anything about CreateWindowEx in parksie's project you don't understand, this describes every part of CreateWindowEx:
http://msdn.microsoft.com/library/ps...ndows_1w6w.htm
It tells you the different types of classes and their different styles and what they do. ;)
Put the following in your InitInstance sub.
Code:BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
HWND bWnd;
// Draw the Button
bWnd = CreateWindowEx(NULL, "Button", "Button1", WS_CHILD, 0, 0, 64, 64, hWnd, NULL, hInst, NULL);
ShowWindow(bWnd, 1);
ShowWindow(bWnd, nCmdShow);
UpdateWindow(bWnd);
return TRUE;
}
Megatron - it's best to keep the stored window handle as a global, so that it can be accessed from other source files. Plus, you'd have to have something like:
You also need to set up a window procedure or your window won't be able to close properly. (the app will still be running with no window open)Code:int WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPCTSTR lpszCommandLine, UINT nCmdShow) {
InitInstance(hInstance, nCmdShow);
}