Wednesday, February 20, 2008

Sample Windows Application

A Sample Windows Application :


#include

long PASCAL ProcessMessagefn(HWND,UINT,WPARAM,LPARAM);

int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
HWND hWnd;
WNDCLASS wc;
MSG msg;
MessageBox(0," Welcome to our Application","Application",MB_OK);

if(!hPrevInstance)
{
wc.style=NULL;
wc.lpfnWndProc=ProcessMessagefn;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance =hInstance;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=GetStockObject(WHITE_BRUSH);
wc.lpszMenuName=NULL;
wc.lpszClassName="MyClass";

if(!RegisterClass(&wc))
{
MessageBox (0,"Could not register the WNDCLASS wc","Application", MB_OK);
return FALSE;
}

}

hWnd=CreateWindow("MyClass","Hello world", WS_OVERLAPPEDWINDOW, 10,10,200,300,NULL,NULL,hInstance,NULL);

if(!hWnd)
{
MessageBox (0,"could not create window","Application", MB_OK);
return FALSE;
}

ShowWindow (hWnd, nCmdShow);

while(GetMessage(&msg,0,0,0))
{
TranslateMessage (&msg.);
DispatchMessage (&msg.);
}
MessageBox(0,"Application terminating","Application",MB_OK);


return 0;

}


long PASCAL ProcessMessagefn(HWND hWnd ,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage (0);
break;

default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}

No comments: