Window won't show

This is a discussion on Window won't show within the Windows Programming forums, part of the Platform Specific Boards category; Hey. I just started working on some windows api programs, really basic stuff. Well, I have winProc and winMain and ...

  1. #1
    Toraton
    Guest

    Window won't show

    Hey. I just started working on some windows api programs, really basic stuff. Well, I have winProc and winMain and everything runs fine, but when I run it, the window I created does not show up. Here is the code I used:

    #include <windows.h>

    HWND hWnd;

    LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    switch(msg)
    {
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    };

    return DefWindowProc(hWnd, msg, wParam, lParam);
    };


    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
    WNDCLASSEX wcx;
    MSG msg;

    wcx.cbClsExtra = 0;
    wcx.cbWndExtra = 0;
    wcx.hbrBackground = (HBRUSH)(GetStockObject(BLACK_BRUSH));
    wcx.hIcon = LoadCursor(NULL, IDC_ARROW);
    wcx.hInstance = hInstance;
    wcx.lpszClassName = "Learning";
    wcx.lpfnWndProc = WindowProc;
    wcx.lpszMenuName = 0;

    RegisterClassEx(&wcx);

    hWnd = CreateWindowEx(WS_EX_LEFT, "Learning", "Learning", WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
    NULL, NULL, hInstance, NULL);

    ShowWindow(hWnd, nShowCmd);

    while(GetMessage(&msg, hWnd, NULL, NULL))
    {
    DispatchMessage(&msg);
    };

    return 0;
    };



    So I don't know why it doesn't work, it just doesn't. The window doesn't show up but it runs in the background and I have to ctrl-alt-del to kill it. Thanks in advance.

    Toraton

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Moved to the Windows forum...
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    Posts
    455
    you need to assign a height and width, heres mine:

    hwMain = CreateWindowEx(0, "LIQUID_BOT_SERVER_WINDOW", "L!quid Bot Server", WS_CAPTION|WS_BORDER|WS_SYSMENU|WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 645, 500, 0, 0, hInst, 0);

  4. #4
    Toraton
    Guest
    I've already tried that, but thanks anyway. CW_USEDEFAULT means use the default height and width, that shouldn't be the problem.

    Any other ideas?

    Toraton

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Okay here are some errors in your code.
    #1: In your window proc, you have semicolon after your switch statement, do not do this. Actually you have semicolon's after all your end braces! This is bad! Don't do it.

    Your RegisterWindowEx( ) function is failing. You would know this is you checked the return value. Always check the return value!

    You need to fill in the cbSize member with the sizeof the structure in bytes. Also you need to give it a style try this.

    Code:
    wcx.style = CS_DBLCLKS | CS_OWNDC |
    	       CS_HREDRAW | CS_VREDRAW;
    I tryed it and it worked after those changes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 03:33 PM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM
  3. my wndProc is out of scope
    By Raison in forum Windows Programming
    Replies: 35
    Last Post: 06-25-2004, 08:23 AM
  4. run a program
    By goodmonkie in forum Windows Programming
    Replies: 2
    Last Post: 10-07-2001, 12:19 PM
  5. Invoking MSWord
    By Donn in forum C Programming
    Replies: 21
    Last Post: 09-08-2001, 05:08 PM

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