December 4th, 2013

What's the difference between the wParam of the WM_NOTIFY message and the idFrom in the NMHDR structure?

The WM_NOTIFY message takes the following parameters:

  • wParam = identifier of the control sending the message
  • lParam = pointer to a NMHDR structure
    • hwndFrom = handle of the control sending the message
    • idFrom = identifier of the control sending the message
    • code = notification code
    • other fields depending on the notification code

Notice that the identifier of the control sending the message appears in two places, once in the wParam and again in the idFrom. What’s the difference? There is no difference. It’s just a convenience. The same value is passed in both places, and you can check whichever one is easier for you. You might use the wParam because it avoids having to dereference a pointer. You might use the NMHDR because that way you have only one thing to pass to your On­Notify helper function. Whatever floats your boat.

Passing the same information multiple ways is hardly new. The WM_COMMAND message also passes redundant information: The control identifier is passed in the low word of the wParam, and you can also get it by calling Get­Dlg­Ctrl­ID on the window handle passed in the lParam.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.