Thread: what ties the window class to the parent HWND?

  1. #1
    Shadow12345
    Guest

    what ties the window class to the parent HWND?

    In my basic windows application I have a parent window and a window class. Does windows 'tie' the window class and the main window together when registerclass is called?

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I may be understanding the question wrong so bear with me. RegisterClass ties the name of the class to the HINSTANCE unless otherwise told not to. When you create your main window you are creating a window that fits the specification of your WNDCLASS/WNDCLASSEX structure. As soon as the HINSTANCE that registered a class is no more that class is freed. A registered class works exactly the same as the pre-existing window type (i.e edit, combo, edit, tab, etc.). The only difference is that yours is temporary, and will only exist as long as the thread that created it. Understand?

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    CreateWindow and CreateWindowEx take a class name as a parameter. that's what ties it in. unless I understood you wrong.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  4. #4
    Shadow12345
    Guest
    No no you guys answered perfectly, you're both awesome, thanks for clarifying that for me.

    What are the differences between the WNDCLASS structure and the WNDCLASSEX structure?

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    LOL...you need to ask!!?

    WNDCLASSEX is an extended WNDCLASS

    Code:
    typedef struct _WNDCLASS { 
        UINT    style; 
        WNDPROC lpfnWndProc; 
        int     cbClsExtra; 
        int     cbWndExtra; 
        HANDLE  hInstance; 
        HICON   hIcon; 
        HCURSOR hCursor; 
        HBRUSH  hbrBackground; 
        LPCTSTR lpszMenuName; 
        LPCTSTR lpszClassName; 
    } WNDCLASS; 
    
    typedef struct _WNDCLASSEX { 
        UINT    cbSize; 
        UINT    style; 
        WNDPROC lpfnWndProc; 
        int     cbClsExtra; 
        int     cbWndExtra; 
        HANDLE  hInstance; 
        HICON   hIcon; 
        HCURSOR hCursor; 
        HBRUSH  hbrBackground; 
        LPCTSTR lpszMenuName; 
        LPCTSTR lpszClassName; 
        HICON   hIconSm; 
    } WNDCLASSEX;

  6. #6
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    Originally posted by master5001
    As soon as the HINSTANCE that registered a class is no more that class is freed.
    Though you might want to look into UnregisterClass() to make sure everything is freed as it should be.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    You are absolutely correct johnnie. Like a had mensioned earlier you can make classes that are not dependant on the hinstance. If you use the option CS_GLOBALCLASS for the style member of your WNDCLASS/WNDCLASSEX structure you will have to use UnregisterClass() to do cleanup. Also when a program ends abnormally (like a seg fault or something) windows isn't always able to clean up your classes. So it is a good idea for you to control your program, not the os.

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    FYI, for any parameter asking for an HINSTANCE you can substitute a stored HINSTANCE with GetModuleHandle(NULL).
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a Window Class
    By Dark_Phoenix in forum Windows Programming
    Replies: 2
    Last Post: 12-07-2008, 07:45 PM
  2. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  3. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  4. no errors but still errors
    By Megatron in forum Windows Programming
    Replies: 7
    Last Post: 01-12-2003, 11:21 PM
  5. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM