windows stuff in a class or global?

Started by
2 comments, last by Ainokea 19 years, 7 months ago
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.
Advertisement
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 :)
---PS3dev
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?
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.
______________________________________________________________________________________With the flesh of a cow.

This topic is closed to new replies.

Advertisement