Home > Software engineering >  How do I handle a message from a user generated combobox in my main window?
How do I handle a message from a user generated combobox in my main window?

Time:12-09

I've created a combobox manually in my main window using CreateWindow(). Because of this it has no ID associated with it only the handle returned by CreateWindow(). When the user makes a selection from the combobox list and the combobox throws a message, how do I handle that in the WinProc WM_COMMAND code since there is no ID associated with the combobox? As far as I can tell, I must know the combobox ID to handle the message. This is especially problematic once I have more than one combobox in the main window. Surely there is something I am missing and there is a simple answer.

CodePudding user response:

Okay. So what Igor Tandetnik stated is the answer.

It does have an ID - whatever you passed for hMenu parameter of CreateWindow...

This is also discussed in the following link.

What is winapi HMENU and how do i use it?

From the above link:

HMENU is a handle to a menu, e.g. as created by LoadMenu (which creates a menu from a specification in a resource).

But, the CreateWindow function re-uses the same argument for two different purposes. With a top-level window it's a menu handle, but with a child window it's the child window id, which should be in 16-bit integer range...

When creating a child window, just cast the id to HMENU.

  • Related