Sign in to follow this  
Cynic

controls

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 loop
while(::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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this