Thread: Question about registering your window

  1. #1
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728

    Question about registering your window

    Ok, first off want to point out that I am VERY new to windows programming. I'm slowly working my way through Petzolds book(only on chapter 3) and came across a question that I haven't seen him answer yet.

    I'm confused by what registering your window means after you create your window class. The reason why I am confused is because when you actualy create the window, you don't reference the window class you created at all, yet it contains the parameters you set for the window class. Does registering make it so all windows created will be of that window class type? What if I wanted to create two windows of two different class types? Hope this makes sense, if not I'll try and explain it better.

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    The first parameter to CreateWindow() is a registered window class.

    You can register many window classes and instantiate many copies of any of them.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Errr... the example I have doesn't have a registered window as the first parameter. Is it overloaded?
    Code:
         hwnd = CreateWindow (TEXT("Hello!"), TEXT (" Hello!"), WS_OVERLAPPEDWINDOW,                 
                CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, NULL,                
                 NULL, hInstance,  NULL) ;

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    From MSDN...

    Code:
    HWND CreateWindow(
      LPCTSTR lpClassName,  // pointer to registered class name
      LPCTSTR lpWindowName, // pointer to window name
      DWORD dwStyle,        // window style
      int x,                // horizontal position of window
      int y,                // vertical position of window
      int nWidth,           // window width
      int nHeight,          // window height
      HWND hWndParent,      // handle to parent or owner window
      HMENU hMenu,          // handle to menu or child-window identifier
      HANDLE hInstance,     // handle to application instance
      LPVOID lpParam        // pointer to window-creation data
    );
    ... I can only assume your window class was registered with the Hello! as it's class name. It is not overloaded by the way.

    Later on, you'll use such things as...

    Code:
    hWnd = CreateWindow("BUTTON",
                        "Start",
    .
    .
    .
    ... where BUTTON is a pre registered class name, and Start the text on the button.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    whats the window class name?
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  6. #6
    Registered User
    Join Date
    Feb 2003
    Posts
    76
    We can assume that you don't know how to register a window class. This involves filling a WNDCLASS structure with the parameters for the class, such as its window procedure and class name, and then calling RegisterClass to create the class.

    You can then use the class name from the WNDCLASS structure as the class parameter for CreateWindow. CreateWindow (actually CreateWindowEx as CreateWindow calls CreateWindowEx) then uses the class name to determine, in part, how the window is to be created. The created window can then receive window messages that its class's window procedure processes.

    One more thing. You register a window class, not a window itself. You need register the class only once, and you can create as many windows using the class's name as you want.

  7. #7
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Ok, I relooked at my code and I see where I was confused. I didn't realize that the lines:
    Code:
    wndclass.lpszClassName = TEXT("Hello!") ;
    and
    Code:
    hwnd = CreateWindowEx (TEXT("Hello!"),...)
    were basically the links between the window class and the newly created window. I didn't see the connection before which was causing the confusion and made me wonder how the compiler knew to use which window class for each window created! Now I understand, thanks! Like I said, just started learning this stuff about 2 days ago, slow going so far...

  8. #8
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    It's one hell of a ride, but you get there in the end if you persevere. Good luck.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. input/output
    By dogbert234 in forum Windows Programming
    Replies: 11
    Last Post: 01-26-2005, 06:57 AM
  2. Problem with creating new window, from another window
    By Garfield in forum Windows Programming
    Replies: 6
    Last Post: 01-11-2004, 02:10 PM
  3. dont want to use all params
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 02-18-2003, 08:10 AM
  4. Window Procedure Question
    By shinobisot in forum Windows Programming
    Replies: 3
    Last Post: 01-15-2003, 11:38 AM
  5. Winamp Vis if anyone can help
    By Unregistered in forum Windows Programming
    Replies: 6
    Last Post: 01-27-2002, 12:43 AM