WINAPI Messages
[edit | edit source]After successfully creating the window in Lesson One you may have noticed it is just a window, it doesen't do anything useful. Here you will learn how to handle messages and therefore create a Window with more functionality. First you will need to reuse the code from the previous example (Simple Window). When were fiished with this lesson it will show the user the name of this program. To handle mouse clicks we need to add a WM_LBUTTONDOWN handler. Like This.
LRESULTCALLBACKWinProc(HWNDhwnd,UINTmsg,WPARAMwParam,LPARAMlParam) { switch(msg) { //this is the code to add to the WndProc. caseWM_LBUTTONDOWN: { TCHARszFileName[MAX_PATH]; HINSTANCEhInstance=GetModuleHandle(NULL); GetModuleFileName(hInstance,szFileName,MAX_PATH); MessageBox(hwnd,szFileName,TEXT("This program is:"),MB_OK|MB_ICONINFORMATION); } break; //end of the added code. caseWM_CLOSE: DestroyWindow(hwnd); break; caseWM_DESTROY: PostQuitMessage(0); break; default: returnDefWindowProc(hwnd,msg,wParam,lParam); } return0; }
Questions
[edit | edit source]Leave whatever questions you may have here.
Hidden category:
