Archived

This topic is now archived and is closed to further replies.

valg3

Window Class

Recommended Posts

valg3    122
I''ve got a class that initializes a full screen OpenGL window. However, I declare an instance of it as an extern, and I manipulate it from thre in WinMain() and WndProc(). Here''s the problem: I want to be able to declare an instance of that class and name that instance anything I want like CAppWindow *myGame; etc. Now, because WndProc() doesnt know what the name of our instance is how would I go about telling WndProc() what window is calling it so that I can call certain functions within the class if certain windows messages are queued? --valg3

Share this post


Link to post
Share on other sites
valg3    122
Oh, forgot to mention that. Yes, but how do I grab a pointer to the class by using the hwnd associated with the window that the instance of the class represents?

Share this post


Link to post
Share on other sites
Brannon    122
There are 2 things built into windows that are your best friends in this case:

1. GetWindowLongPtr()/SetWindowLongPtr(). Use GWLP_USERDATA to store the pointer to your class (or better yet, when you register the window class, add sizeof(DWORD_PTR) bytes to cbWndExtra, and use that space to store your pointer).

2. SetProp()/GetProp().

Read the docs on those functions. If it doesn''t hit you on how to do this, well, think about it until it does =).

Note: if you aren''t running a recent PlatformSDK, then you''ll want GetWindowLong/SetWindowLong. The *Ptr functions were added later for compatibility with 64bit pointers.

As for which one to use, if it''s your window and window class, then go with GetWindowLongPtr(). If it''s a system window class (like "EDIT") use GetProp() (just in case the system class is already using GWLP_USERDATA).


-Brannon

Share this post


Link to post
Share on other sites