Passing parameters to a window call in Windows
I'm new to programming against Windows calls, and I'm trying to figure out a way to pass a parameter to the lpfnWndProc functi开发者_JAVA百科on. I have the following code:
HWND hwnd;
WNDCLASS wc1 = {0};
wc1.lpszClassName = TEXT( "sample" );
wc1.hInstance = 0;
wc1.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
wc1.lpfnWndProc = DepthWndProc;
Note the line wc1.lpfnWndProc = DepthWndProc;
Am I able to pass DepthWndProc a parameter? If so, what does the syntax look like?
Thanks!
You are assigning a function pointer here, not making a call. Thus no passing of arguments.
Having to store extra state with a HWND isn't unusual, a very common requirement for a C++ class wrapper around a window for example. You should keep a map<> to help you retrieve the wrapper object from the window handle value. Using SetWindowLongPtr() with GWLP_USERDATA is possible too but less ideal if you don't control the window creation.
You can call DepthWndProc directly and pass its parameters, but why on earth would you do that? That's not how windows programming works.
You are giving windows a function to call whenever it has a message to send to your window.
精彩评论