Thread: About classes and HINSTANCE variable to Main

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    25

    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.

    Nimit

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Windows question, Windows board.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. loading a dll with classes
    By *DEAD* in forum C++ Programming
    Replies: 2
    Last Post: 06-21-2007, 11:27 PM
  2. No Cube!!!
    By beene in forum Game Programming
    Replies: 3
    Last Post: 05-10-2007, 10:55 PM
  3. Wrapping Win32 in classes
    By mrafcho001 in forum Windows Programming
    Replies: 7
    Last Post: 03-02-2006, 06:56 PM
  4. Help with Class Library .NET and Classes :0
    By Robert_Sitter in forum Windows Programming
    Replies: 2
    Last Post: 11-27-2005, 08:42 PM
  5. input/output
    By dogbert234 in forum Windows Programming
    Replies: 11
    Last Post: 01-26-2005, 06:57 AM