Question

I have created two List Box items in a window. Now I'm trying to get notifications from them whenever one of their selection changes.

I'm getting LBN_SELCHANGE notification code under WM_COMMAND window message.

MSDN Documentation of LBN_SELCHANGE:

wParam
    The LOWORD contains the identifier of the list box.
    The HIWORD specifies the notification code.
lParam
    Handle to the list box.

Now, I want to distinguish these two list boxes (find which control is sent this message) with using those "identifier"s. I know, I can also find it from the handle value in the lParam argument, but if it is possible to use the identifier codes instead, it will be better in terms of not exposing window handles to the global namespace.

So, is it possible to assign an identifier (or find an automatically assigned ID if there is one) to a control without using resources?

Was it helpful?

Solution 2

When creating a child control the control ID is passed to CreateWindow as the hMenu parameter. The parameter's documentation contains the following section (emphasis mine):

For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window.

Apart from being unique among its siblings the window ID must fit into 16 bits (valid range is 8 to 0xDFFF). You can place your IDs into the VS-controlled Resource.h file and update the value of _APS_NEXT_CONTROL_VALUE to prevent collisions with siblings created from dialog resources.

OTHER TIPS

There also possible change child window identifier using

LONG WINAPI SetWindowLong( HWND hWnd, int nIndex, LONG dwNewLong );

with GWL_ID. However, better solution is create window with right identifier.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top