i am at the end of my wit...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ayan4u
    New Member
    • Apr 2007
    • 86

    i am at the end of my wit...

    [CODE=c]
    #include <windows.h>
    #include <time.h>
    #define WIDTH 320
    #define HEIGHT 240
    LRESULT CALLBACK WinProc(HWND, UINT, WPARAM, LPARAM);
    int WINAPI WinMain(HINSTAN CE hInstance, HINSTANCE hPrev, LPSTR CmdLine, int CmdShow)
    {
    HWND hWnd;
    MSG msg;
    WNDCLASSEX wc;

    wc.cbSize = sizeof(wc);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WinProc;
    wc.cbWndExtra = 0;
    wc.cbClsExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
    wc.hCursor = LoadCursor(NULL , IDC_ARROW);
    wc.hbrBackgroun d = (HBRUSH) GetStockObject( WHITE_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassNam e ="wndclass";
    wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);

    if(!RegisterCla ssEx(&wc))
    {
    MessageBox(NULL ,"Failed to register window","ERROR! ",MB_OK|MB_ICON EXCLAMATION);
    return EXIT_FAILURE;
    }

    hWnd = CreateWindow("w ndclass",
    "HPEN-Ayan",
    WS_OVERLAPPEDWI NDOW,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    WIDTH,
    HEIGHT,
    NULL,
    NULL,
    hInstance,
    NULL);

    if(!hWnd)
    {
    MessageBox(NULL ,"Failed to create window","ERROR! ",MB_OK|MB_ICON EXCLAMATION);
    return EXIT_FAILURE;
    }

    ShowWindow(hWnd , CmdShow);

    while(GetMessag e(&msg, NULL, 0, 0))
    {
    if(msg.message = WM_QUIT)
    break;

    TranslateMessag e(&msg);
    DispatchMessage (&msg);

    }

    UnregisterClass ("wndclass", hInstance);

    return msg.wParam;
    }

    LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    ...

    }
    [/CODE]

    now can some one tell me why this progrm is gettn stucked at CreateWindow() as it cannot get a handle to the window....so according to my prog...its giving a messagebox "Failed to create window"...
  • Darryl
    New Member
    • May 2007
    • 86

    #2
    2 Suggestions:

    1st, instead of just popping up a Create Failed message box, call getlasterror() and find out exactly why the window is failing to create.

    2nd, post the code for you WndProc, CreateWindow processes several messages before it return, namely the WM_CREATE, which if not handled properly could cause createwindow to return an error.

    Comment

    Working...