PDA

Click to See Complete Forum and Search --> : Controls On An Win 32 Form


PsyVision
Aug 31st, 2000, 04:59 AM
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 ?

parksie
Aug 31st, 2000, 08:09 AM
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:

WndProc(...) {
if(uMsg == WM_COMMAND && wParam == IDD_MYBTN) {
MessageBox(hwnd, "Button pressed", "Msg", MB_OK);
}
}

PsyVision
Aug 31st, 2000, 02:42 PM
Thanks (i can use that), But how do i create the button

parksie
Aug 31st, 2000, 02:49 PM
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.

PsyVision
Aug 31st, 2000, 03:18 PM
I know that part but with win 32 where you hard code all of the controls how do u do that

parksie
Aug 31st, 2000, 03:22 PM
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 :)

Aug 31st, 2000, 03:23 PM
Use CreateWindowEx.

PsyVision
Aug 31st, 2000, 03:38 PM
Thanks :-))))

V(ery) Basic
Sep 1st, 2000, 05:10 AM
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/psdk/winui/windows_1w6w.htm


It tells you the different types of classes and their different styles and what they do. ;)

Sep 1st, 2000, 09:44 AM
Put the following in your InitInstance sub.

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;
}

parksie
Sep 1st, 2000, 02:35 PM
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:

int WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPCTSTR lpszCommandLine, UINT nCmdShow) {
InitInstance(hInstance, nCmdShow);
}

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)