Thread: help with MDI CreateWindow

  1. #1
    Malum in se abachler's Avatar
    Join Date
    Apr 2007

    help with MDI CreateWindow

    hey guys, im having some problems with creating the frame window for an MDI application. Ive checked over the code a dozen tiems and cant find the error. I looking at petzold, but I keep getting the frame window creation failed result. Here is the relevant stuff -

        // in WinMain
        if(hwndFrame == NULL){
            MessageBox(0, "Frame Window Creation Failed!", "Error!",MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
            return 0;
    void CreateFrameWindow(HINSTANCE hInstance){
        WNDCLASS WndClass;
        RECT Rect;
        char    szClassName[] = "MyMDIFrameClass";
             = (CS_HREDRAW | CS_VREDRAW);
        WndClass.lpfnWndProc   = FrameWndProc;
        WndClass.cbClsExtra    = 0;
        WndClass.cbWndExtra    = 0;
        WndClass.hInstance     = hInstance;
        WndClass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        WndClass.hCursor       = LoadCursor(NULL, IDC_CROSS);
        WndClass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
        WndClass.lpszMenuName  = NULL; //MAKEINTRESOURCE(IDR_MENU1);
        WndClass.lpszClassName = szClassName;
            MessageBox(0, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
        Rect.left = 0; = 0;
        Rect.right = 1284;
        Rect.bottom = 964;
        AdjustWindowRect( &Rect , WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN , TRUE );
        hwndFrame = CreateWindow(   szClassName,
                                    "MyMDI App",
                                    WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
                                    CW_USEDEFAULT, CW_USEDEFAULT, 
                                    CW_USEDEFAULT, CW_USEDEFAULT,
                                    NULL, LoadMenu(hInstance,"IDR_MENU1"), 
                                    hInstance, NULL);
    BTW, im writing in straight C/C++, no MFC
    Last edited by abachler; 06-12-2007 at 10:10 AM.

  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Cayman Islands
    In your WndProc are you returning DefFrameProc for messages you don't handle?

    Did you test your hwnd right after the call to createwindow in the function? Is it valid there? If not, did you call getlasterror()? What value did you get for that?

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Im using DefFrameProc, I added this bit of error handlign code -
        sprintf(szError,"GetLastError() = %d\0",GetLastError());
        if(hwndFrame == NULL){
            MessageBox(NULL,"Frame Window Failure in-function",szError,MB_OK);
    GetLastError() is returning 1400 - Invalid Window Handle ???

    This doesnt make any sense to me, since im not passing it a window handle
    Last edited by abachler; 06-12-2007 at 12:38 PM.

  4. #4
    train spotter
    Join Date
    Aug 2001
    near a computer
    >>This doesnt make any sense to me, since im not passing it a window handle

    Yes you are, the menu's handle.

    Put a break point in the Frames WM_CREATE.

    Does your code get to try and create the frame window?

    I think it is to do with your menu, you have some commented in and some out. ie the class is registered as not having a menu then you try and add one.

    I think this is you error.


    Check this, does it load the menu or is it returning an invalid handle?


    LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1) ),

    Make sure it loads the menu BEFORE calling createwindow
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Editor design: Traditional MDI versus Tabbed MDI
    By psychopath in forum Game Programming
    Replies: 7
    Last Post: 01-22-2007, 07:48 AM
  2. Inserting text into MDI program
    By Rutabega in forum Windows Programming
    Replies: 0
    Last Post: 12-23-2005, 11:25 AM
  3. Cannot create MDI Client Win
    By JaWiB in forum Windows Programming
    Replies: 1
    Last Post: 10-31-2005, 10:05 PM
  4. CreateWindow failure
    By TheDan in forum Windows Programming
    Replies: 6
    Last Post: 07-08-2005, 07:49 AM
  5. MDI Problem
    By Rare177 in forum Windows Programming
    Replies: 3
    Last Post: 04-12-2005, 01:29 PM