App wont open

This is a discussion on App wont open within the Windows Programming forums, part of the Platform Specific Boards category; I'm using the tutorial from www.gametutorials.com to make a simple game, i started off just a plain window with a ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267

    App wont open

    I'm using the tutorial from www.gametutorials.com to make a simple game, i started off just a plain window with a black background but when i compile it and run it, the window doesn't show up and after a while, i ended up copying almost the entire thing from the tutorial but the window still wouldn't show up. I'm new to win32 so the mistake is probably obvious.

    Code:
    HWND CreateMainWindow(HINSTANCE hInstance)
    {
         HWND hWnd = NULL;
         WNDCLASS wc;
         
         memset(&wc, 0, sizeof(WNDCLASS));
         
         wc.hInstance     = hInstance;
         wc.lpszClassName = "Game";
         wc.lpfnWndProc   = WinProc;
         wc.style         = CS_HREDRAW | CS_VREDRAW;
         wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
         wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
         wc.lpszMenuName  = NULL;
         wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
         
         RegisterClass(&wc);
         
         hWnd = CreateWindow("Game",
                             "Game",
                             WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
                             CW_USEDEFAULT,
                             CW_USEDEFAULT,
                             600,
                             600,
                             NULL,
                             NULL,
                             hInstance,
                             NULL);
         
         g_hInstance = hInstance;                    
         
         ShowWindow(hWnd, SW_SHOWNORMAL);
         UpdateWindow(hWnd);
         
         return hWnd;
    }
    Code:
    int WINAPI WinMain (HINSTANCE hThisInstance, 
                        HINSTANCE hPrevInstance, 
                        LPSTR lpszargv,
                        int ishow)
    {
         HWND hWnd = CreateMainWindow(hThisInstance);
         
         if (hWnd == NULL) return false;
         
         init(hWnd);
         
         return (int)MainLoop();
    }
    every function here have been declared and defined

    Also, if anyone has that tutorial, does MainLoop return a WPARAM? the return value isnt used anywhere so why not void?

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I don't see anything necessarily wrong with that code. What do your init, MainLoop, and WinProc functions look like?
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    903
    What's the code of your WndProc ? Chances are that it is your problem.

  4. #4
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Maybe there is one "break" or "return" missing from a WndProc case label.
    That has happened to me pretty often.

  5. #5
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    Code:
    LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
            switch (msg)
            {
                   case WM_DESTROY:
                        deinit();
                        break;
                   default:
                        return DefWindowProc(hWnd, msg, lParam, wParam);
                        break;
            }
            return 0;
    }

  6. #6
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    Oh, so i mixed up wparam with lparam...
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. open empty file
    By mystic-d in forum C Programming
    Replies: 2
    Last Post: 11-16-2007, 10:27 AM
  2. open files in a loop in C
    By podiyan in forum C Programming
    Replies: 2
    Last Post: 10-19-2007, 02:50 AM
  3. Open file name object
    By JJFMJR in forum Windows Programming
    Replies: 3
    Last Post: 09-14-2007, 06:44 PM
  4. To open or not to open ?
    By darfader in forum C Programming
    Replies: 7
    Last Post: 09-24-2003, 09:14 AM
  5. Problems with open and save boxes
    By pinkcheese in forum Windows Programming
    Replies: 3
    Last Post: 05-21-2002, 07:03 PM

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