Lesson One
[edit | edit source]One of the most important things to learn about using the WINAPI to write windows applications is that to do so you have to fill a Windows class structure. The following code will show you how.
Window Procedure
[edit | edit source]#include<windows.h> TCHAR*Simple=TEXT("A Simple Window..."); LRESULTCALLBACKWinProc(HWNDhwnd,UINTMsg,WPARAMwParam,LPARAMlParam) { switch(Msg) { caseWM_CLOSE: DestroyWindow(hwnd); break; caseWM_DESTROY: PostQuitMessage(0); break; default: returnDefWindowProc(hwnd,Msg,wParam,lParam); } return0; }
WinMain Function
[edit | edit source]intWINAPIWinMain(HINSTANCEhInst,HINSTANCEhPrev,LPSTRlpCmd,intnShow) { WNDCLASSwc; HWNDhwnd; MSGMsg; //The WNDCLASS struct wc is filled here by assigning all members of the struct wc.lpfnWndProc=WinProc; wc.hInstance=hInst; wc.style=CS_BYTEALIGNCLIENT; wc.lpszMenuName=NULL; wc.lpszClassName=Simple; wc.hIcon=LoadIcon(NULL,IDI_APPLICATION); wc.hCursor=LoadCursor(NULL,IDC_ARROW); wc.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH); wc.cbWndExtra=0;wc.cbClsExtra=0; //end of struct assignments //Register our newly defined window class RegisterClass(&wc); //Create a window from wc class hwnd=CreateWindow(Simple,Simple,WS_OVERLAPPEDWINDOW|WS_VISIBLE, CW_USEDEFAULT,CW_USEDEFAULT,300,210,HWND_DESKTOP,NULL,hInst,NULL); //Updating the window UpdateWindow(hwnd); //The message loop or the place where messages are routed while(GetMessage(&Msg,NULL,0,0)>0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return(int)Msg.wParam;<br> }
Questions
[edit | edit source]Leave all your questions here.
Bodene 04:29, 17 January 2007 (UTC)
Could you explain what a windows class structure is, what its for etc? Anonymous 07.38, 3 July 2007
Hidden category:
