CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2004
    Location
    Texas, USA
    Posts
    1,206

    CreateWindow failing?

    I must be stupid, I don't know why this isn't working:

    Code:
    //====================================================================================
    /*
    || Creates a window for the game
    || Returns NULL if failed, the window handle if successful.
    */
    HWND DirectX_Utils::GameWindowCreate(string WindowTitle)
    {
        WNDCLASS CS;
    
        CS.cbClsExtra           = 0;
        CS.cbWndExtra           = 0;
        CS.hbrBackground        = (HBRUSH)GetStockObject(BLACK_BRUSH);
        CS.hIcon                = NULL;
        CS.hCursor              = NULL;
        CS.hInstance            = GlobalInstance;
        CS.lpfnWndProc          = WindowProcedure;
        CS.lpszClassName        = "GameAppClass";
        CS.lpszMenuName         = 0;
        CS.style                = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS | CS_OWNDC;
    
        if(!RegisterClass(&CS))
            return NULL;
    
        return (MainWindow = CreateWindow("GameAppClass", WindowTitle.c_str(), WS_POPUP | WS_VISIBLE,
            100, 100, 300, 300, NULL, NULL, GlobalInstance, NULL));
    }
    CreateWindow returns NULL!

    GlobalInstance and WindowProcedure are both private members of my class, which are initialized appropriately at construction.

    MainWindow is a private member also which receives the handle to the window.

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: CreateWindow failing?

    What is WindowProcedure? Is this window procedure a member of your class? You can't use a function pointer to a member of your class for use as a window procedure.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: CreateWindow failing?

    Well...as usual...what does 'GetLastError()' return? For further information take a look at the following FAQ...

  4. #4
    Join Date
    Nov 2004
    Posts
    199

    Re: CreateWindow failing?

    Have you declared the function "WindowProcedure" as follow ?

    LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
    {
    switch(uiMsg)
    ...
    ...
    return DefWindowProc(...);
    }

    If yes, try this 2 way:

    CreateWindow("GameAppClass", WindowTitle.c_str(), WS_POPUP | WS_VISIBLE,
    100, 100, 300, 300, NULL, NULL, GlobalInstance, (void*)this);

    or

    CreateWindow("GameAppClass", WindowTitle.c_str(), WS_POPUP | WS_VISIBLE,
    100, 100, 300, 300, NULL, NULL, GetModuleHandle(NULL), NULL;

    I don't kwno how your complete class is, maybe these can cause an error...

    EDIT:
    I have forgotten:
    are you creating a fullscreen window or a window-mode one ? If window-mode, you must specify WS_CLIPCHILDREN | WS_CLIPSIBLINGS flags besides WS_POPUP | WS_VISIBLE...
    If you're creating a fullscreen window, the probrem can rise becouse you choose a resolution that your hardware/system doesn't supports

    Also I recommend you to use CreateWindowEx(....) in the future...


    Last edited by Elementer; November 28th, 2004 at 07:55 AM.

  5. #5
    Join Date
    Feb 2004
    Location
    Texas, USA
    Posts
    1,206

    Re: CreateWindow failing?

    Ooops.... I didn't put this at the end of my Window Proc:


    return DefWindowProc(hwnd, msg, wparam, lparam);


    *slaps himself*
    Last edited by MrDoomMaster; November 28th, 2004 at 11:30 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured