help with MDI CreateWindow

This is a discussion on help with MDI CreateWindow within the Windows Programming forums, part of the Platform Specific Boards category; hey guys, im having some problems with creating the frame window for an MDI application. Ive checked over the code ...

  1. #1
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189

    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 -


    Code:
        // in WinMain
        CreateFrameWindow(hInstance);
        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";
     
        WndClass.style         = (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;
     
        if(!RegisterClass(&WndClass)){
            MessageBox(0, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
            return;
            }
     
        Rect.left = 0;
        Rect.top = 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);
     
        return;
        }
    BTW, im writing in straight C/C++, no MFC
    Last edited by abachler; 06-12-2007 at 10:10 AM.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    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
    Posts
    3,189
    Im using DefFrameProc, I added this bit of error handlign code -
    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.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,855
    >>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.

    LoadMenu(hInstance,"IDR_MENU1"),

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

    Try

    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, 06:48 AM
  2. Inserting text into MDI program
    By Rutabega in forum Windows Programming
    Replies: 0
    Last Post: 12-23-2005, 10:25 AM
  3. Cannot create MDI Client Win
    By JaWiB in forum Windows Programming
    Replies: 1
    Last Post: 10-31-2005, 09: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21