Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

Unable to register windows class.....

$
0
0
#include <Windows.h>


    const char g_szClassName[]="myWindowClass";
    LRESULT CALLBACK WndProc(HWND hWnd,unsigned int msg,WPARAM wParam,LPARAM lParam)
    {
        switch(msg)
        {
        case WM_CLOSE:
            DestroyWindow(hWnd);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            return DefWindowProc(hWnd,msg,wParam,lParam);
        }
        return 0;
    }

    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
     WNDCLASSEX wc;
     HWND hWnd;
     MSG Msg;

     wc.cbSize=sizeof(WNDCLASSEX);
     wc.lpfnWndProc=WndProc;
     wc.cbClsExtra=0;
     wc.cbWndExtra=0;
     wc.hInstance=hInstance;
     wc.hIcon=LoadIcon(0,IDI_APPLICATION);
     wc.hCursor=LoadCursor(0,IDC_ARROW);
     wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
     wc.lpszMenuName=NULL;
     wc.lpszClassName=g_szClassName;
     wc.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
    
     if(!RegisterClassEx(&wc))
     {
         MessageBox(NULL,"window can't register the class","Error",MB_ICONEXCLAMATION|MB_OK);   //getting stuck here
    
         return 0;
     }

     hWnd=CreateWindowEx(WS_EX_CLIENTEDGE,g_szClassName,"The title of the window",WS_OVERLAPPED,CW_USEDEFAULT,CW_USEDEFAULT,240,120,NULL,NULL,hInstance,NULL);
     if(hWnd==0)
        { MessageBox(0,"window can't be created","Error",MB_ICONEXCLAMATION|MB_OK);
     return 0;
     }

     ShowWindow(hWnd,nCmdShow);
     UpdateWindow(hWnd);

     while(GetMessage(&Msg,NULL,0,0)>0)
     {
         TranslateMessage(&Msg);
         DispatchMessage(&Msg);
     }

     return Msg.wParam;
    }

Viewing all articles
Browse latest Browse all 15302

Trending Articles