WINAPI Programming/Message Handling
WINAPI Messages
editAfter 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.
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
//this is the code to add to the WndProc.
case WM_LBUTTONDOWN:
{
TCHAR szFileName[MAX_PATH];
HINSTANCE hInstance = GetModuleHandle(NULL);
GetModuleFileName(hInstance, szFileName, MAX_PATH);
MessageBox(hwnd, szFileName, TEXT("This program is:"), MB_OK | MB_ICONINFORMATION);
}
break;
//end of the added code.
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
Questions
editLeave whatever questions you may have here.