About classes and HINSTANCE variable to Main

This is a discussion on About classes and HINSTANCE variable to Main within the Windows Programming forums, part of the Platform Specific Boards category; So here is the thing. This isn't really a *problem* but I'm looking for some insight. The thing is, i ...

About classes and HINSTANCE variable to Main

So here is the thing. This isn't really a *problem* but I'm looking for some insight. The thing is, i have a couple of classes in my program, and all of the classes need to do stuff to the main window.

The Main file has a variable declared up top as such:
static HINSTANCE hInst;

This is pretty much the handle to the current instance of the program. This variable, (definied in the WinMain function) is needed in some functions in my classes. Right now, I am passing in all of these variables(an HDC variable, an HWND variable...) to the classes individually. And doing so, its becoming more and more annoying to create a new object as I have to type in so many input parameters.

So I guess my question is, is there any way to access these "windows" variables from my classes without actually passing them all in?

Let me know if this problem needs more clarification. Thanks! Happy new years.

You can use a simple function to obtain the instance of the application.

Code:

HINSTANCE hInst = GetModuleHandle( NULL );

So in your code you could just put the call to GetModuleHandle as a parameter to whatever function you are calling. Hope this helps a little. There are other ways to do this but I won't get into them here.