conz
conz

Reputation: 121

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 function. 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!

Upvotes: 2

Views: 1303

Answers (2)

Hans Passant
Hans Passant

Reputation: 942438

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.

Upvotes: 1

Benjamin Lindley
Benjamin Lindley

Reputation: 103751

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.

Upvotes: 0

Related Questions