Sign in to follow this  
ekrax

windows stuff in a class or global?

Recommended Posts

is it generally better to leave all windows related stuff global ie, the variables ... HGLRC hRC; HDC hDC; HWND hWnd; HINSTANCE hInstance; ... and stuff like creating the window, (and for my opengl app, destroying and reszing the window) before i had this all global ... but i just moved it all into a single class GLwindow, then the only 2 functions left global are WndProc and WinMain, is this a good practice or not? thanks for any suggestions.

Share this post


Link to post
Share on other sites
Depends on the language ;) I assume you're using C++, in which case it generally is better practice to encapsulate related variables and methods within classes.

Personally with window stuff like that I put them in my 'main framework' class; the one that's setup by main() and contains the game loop. You'll probably need to access these variables for initialisation stuff, so I'd recommend making get methods for the ones you need. Macros might help too if you find yourself needing to access them a lot; though personally I've found the only time I felt it worth macro'ing something was (this was DirectX) to access the DX interface, which is used all the bloody time :)

Share this post


Link to post
Share on other sites
yeah so far i've only had to use a get device context function formy resource manager which needs to access this to build fonts.

also is it possible to have WndProc withen a class or must this be global?

Share this post


Link to post
Share on other sites
Quote:
Original post by ekrax
yeah so far i've only had to use a get device context function formy resource manager which needs to access this to build fonts.

also is it possible to have WndProc withen a class or must this be global?

It is possible.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this