controls

Started by
5 comments, last by Cynic 17 years, 9 months ago
Hello Everybody, I would like to use a control, for example several buttons in a window, not a dialog box. However when the button is pushed is it possible to have that button handled by the window callback function the same way as what a dialog box callback function handles it. Example: I would like the button that I create to have an ID, so when it is pressed it can be handled as described below. WM_COMMAND: { switch(message) { case ID_MY_BUTTON1: return 0; case ID_MY_BUTTON2: return 0; } } Thanks Cynic
Advertisement
I thought if you but a button directly on a window, pressing it sends a WM_COMMAND message to your WndProc same as with DialogProc. Certainly works that way with menus.

Be interested to know if that is not correct.
Quote:Original post by EasilyConfused
I thought if you but a button directly on a window, pressing it sends a WM_COMMAND message to your WndProc same as with DialogProc.

It's the same.

Cynic, I think your problem may be that you don't have a proper loop setup for the window so that it can translate/dispatch messages as it should. In your code somewhere, you should have something that looks fairly similar to this:

// enter main message loopwhile(::GetMessage(&msg, NULL, 0, 0) == TRUE){	// process messages	::TranslateMessage(&msg);	::DispatchMessage(&msg);}

You also have to have your WNDCLASSEX structure filled out correctly and registered, but that's the general gist.
Hi guys,

The problem is, the controls that I have created are all created using CreateWindowEX().

How do I give the HWND that I have created an ID? For example when you create a control on a dialog box you can chage the ID from its properties.

How can you give the HWND an ID so it is the same?

I have made callback procs that were used with dialog boxes. I would like to use the same callback procs with the obvious minor changes for a window.

Anyone know how I could do this?

Thanks
Cynic
Quote:Original post by Cynic
How do I give the HWND that I have created an ID? For example when you create a control on a dialog box you can chage the ID from its properties.


From The docs:
Quote:
lParam
Handle to the control sending the message if the message is from a control. Otherwise, this parameter is NULL.
lParam has the HWND of the control, you can switch on that instead of an ID.
Cool!

But is there a way I can set an ID for the control instead of handling the wParam and lParam?

I already have my callback procs that I would like to use. So I don't want to have to change them.

Thanks
It's all good.

I found out how. When you create the control, you just have to definea macro and pass that to the function CreateWindowEx() as (HMENU)macro name.

Thanks

This topic is closed to new replies.

Advertisement