A standard window procedure function takes this prototype:
LRESULT CALLBACK WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
When a message such as WM_MOUSEMOVE
or WM_CHAR
, the WndProc
function will receive the window the message originated from, and any extra parameters, which will be with msg and wParam/lParam.
What I have now is a class. Say
class Random
{
public:
void Initialize ();
private:
void Draw ();
HWND hWnd;
friend LRESULT CALLBACK RandomProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
};
After the hWnd
is initialized and created by Initialize ()
, it will send messages such as WM_LBUTTONDOWN
to RandomProc
. Once a message is received, I would like RandomProc
to use Draw ()
to redraw the window of the class Random
.
The thing is, I will have multiple Random
variables, and each will have a window. All the windows will send their messages to RandomProc
, and will want it to redraw the corresponding windows of the hWnd
. I do not know which random variable sent the message based upon the hWnd parameter nor the msg/wParam/lParam, and so cannot access the appropriate Draw ()
function and cannot redraw the correct window.
Is there a way to pass a pointer to the class of the window to the Procedure every time a message is sent or is there another way to access the Random class whose hWnd sent the message?
hWnd
parameter? If you want the windows to use the same procedure, make them use the same class, or specify the procedure as the appropriate one for each Windows class you use. – chrisHWND
. That's how you tell them apart usually. Is there a huge problem withDraw
taking aHWND
? – chrisHWND
. I think someone has answered that already. Thanks for your help! – GILGAMESH