Thread: RegisterClass() and specific modules?

  1. #1
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877

    RegisterClass() and specific modules?

    Hello all, I've recently made a maze game with win32 and ran into a weird problem, I've solved it, but it left me with questions.

    In WinMain() we have the registration of a child class called "Cell" like this:

    Code:
        wndclass.style = CS_HREDRAW | CS_VREDRAW ;
        wndclass.lpfnWndProc = CellProc ;
        wndclass.cbClsExtra = 0 ;
        wndclass.cbWndExtra = sizeof( Cell* ) ;
        wndclass.hInstance = hInstance ;
        wndclass.hIcon = NULL ;
        wndclass.hCursor = LoadCursor (NULL, IDC_ARROW ) ;
        wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH) ;
        wndclass.lpszMenuName = NULL ;
        wndclass.lpszClassName = TEXT("Cell") ;
    
        if( !RegisterClass( &wndclass ) )
        {
            MessageBox( NULL, TEXT("Error registering \"Cell\" class, closing\n"), TEXT("Error"), MB_OK );
    
            SendMessage( hwndBoard, WM_CLOSE, 0, 0 );
    
            return 0;
        }
    The RegisterClass() function returns successfully. Then later in the "board.cpp" module, I call CreateWindow() to create the "Cell" windows, with the HINSTANCE value that was passed into WinMain (this is inside a loop):

    Code:
        HWND winCell = CreateWindow( TEXT("Cell"),
                                     NULL,
                                     WS_CHILD | WS_VISIBLE,
                                     rcCell.left,
                                     rcCell.top,
                                     rcCell.right,
                                     rcCell.bottom,
                                     winBoard,
                                     ( HMENU ) i * iWidth + j,
                                     hInst,
                                     ( PVOID ) this );
    This call fails, and the error code is 1407 (Can not find window class). I solved this by just moving the registration into the "board.cpp" module.

    However this left me with questions I wasn't able to find very good answers to:

    1. Is the memory used to hold the value passed into RegisterClass() unique to each module, and if so how is win32 identifying the callers module?

    2. Would it be possible to keep the RegisterClass() call in one module while creating the window in another, and if so how?

    Thanks!


    ( PS. In the last iteration of the program I've removed the "Cell" windows completely, but I would like to figure this out. I might post the game when done, as it has a pretty interesting mechanic. ).
    WndProc = (2[b] || !(2[b])) ? SufferNobly : TakeArms;

  2. #2
    Registered User
    Join Date
    Aug 2013
    Posts
    451
    Quote Originally Posted by Alpo View Post
    Hello all, I've recently made a maze game with win32 and ran into a weird problem, I've solved it, but it left me with questions.

    In WinMain() we have the registration of a child class called "Cell" like this:

    Code:
        wndclass.style = CS_HREDRAW | CS_VREDRAW ;
        wndclass.lpfnWndProc = CellProc ;
        wndclass.cbClsExtra = 0 ;
        wndclass.cbWndExtra = sizeof( Cell* ) ;
        wndclass.hInstance = hInstance ;
        wndclass.hIcon = NULL ;
        wndclass.hCursor = LoadCursor (NULL, IDC_ARROW ) ;
        wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH) ;
        wndclass.lpszMenuName = NULL ;
        wndclass.lpszClassName = TEXT("Cell") ;
    
        if( !RegisterClass( &wndclass ) )
        {
            MessageBox( NULL, TEXT("Error registering \"Cell\" class, closing\n"), TEXT("Error"), MB_OK );
    
            SendMessage( hwndBoard, WM_CLOSE, 0, 0 );
    
            return 0;
        }
    The RegisterClass() function returns successfully. Then later in the "board.cpp" module, I call CreateWindow() to create the "Cell" windows, with the HINSTANCE value that was passed into WinMain (this is inside a loop):

    Code:
        HWND winCell = CreateWindow( TEXT("Cell"),
                                     NULL,
                                     WS_CHILD | WS_VISIBLE,
                                     rcCell.left,
                                     rcCell.top,
                                     rcCell.right,
                                     rcCell.bottom,
                                     winBoard,
                                     ( HMENU ) i * iWidth + j,
                                     hInst,
                                     ( PVOID ) this );
    This call fails, and the error code is 1407 (Can not find window class). I solved this by just moving the registration into the "board.cpp" module.

    However this left me with questions I wasn't able to find very good answers to:

    1. Is the memory used to hold the value passed into RegisterClass() unique to each module, and if so how is win32 identifying the callers module?

    2. Would it be possible to keep the RegisterClass() call in one module while creating the window in another, and if so how?

    Thanks!


    ( PS. In the last iteration of the program I've removed the "Cell" windows completely, but I would like to figure this out. I might post the game when done, as it has a pretty interesting mechanic. ).
    do you have the 3rd parameter correct? and see if the backcolor is diferent from other controls, on back

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with modules
    By Jacob Boyd in forum C++ Programming
    Replies: 3
    Last Post: 10-23-2012, 10:08 AM
  2. modules in C++
    By jamort in forum C++ Programming
    Replies: 1
    Last Post: 06-03-2009, 02:07 AM
  3. failing RegisterClass
    By Bajanine in forum Windows Programming
    Replies: 6
    Last Post: 02-02-2008, 09:25 AM
  4. Modules
    By tim545666 in forum C++ Programming
    Replies: 0
    Last Post: 04-10-2002, 11:44 PM
  5. Modules
    By Garfield in forum C Programming
    Replies: 4
    Last Post: 09-30-2001, 10:23 AM