Class method for WndProc

隐身守侯 提交于 2019-11-28 01:35:05

I personally would not use either of these methods. The global variable approach works, but feels dirty. Especially with the lock. And the CBT hook is, well over the top. Although it points in the right direction.

The standard way to pass state information to your window procedure during creation is through lpParam parameter of CreateWindow or CreateWindowEx. So the technique is as follows:

  1. Pass your instance pointer in the lpParam parameter of CreateWindow or CreateWindowEx.
  2. Read this value in your WM_NCCREATE handler. That message supplies the information as part of the CREATESTRUCT struct.
  3. Still in WM_NCCREATE call SetWindowLongPtr to set the user data of the window to the instance pointer.
  4. All future calls to the window procedure can now obtain the instance pointer by calling GetWindowLongPtr.

Raymond Chen illustrates the details here: How can I make a WNDPROC or DLGPROC a member of my C++ class?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!