Project Description: In chapter-10 (Handouts), you have studied a completeWindow
ID: 3614936 • Letter: P
Question
Project Description:
In chapter-10 (Handouts), you have studied a completeWindow application (in four steps). Complete source code of eachstep is also given. You are required to merge this source code in afully functional Win32 application. Note that on successfulexecution, this application will create a Window (with thecharacteristics specified in Window Class structure). On clickingthe Window with Left Mouse Button, a message “Left MouseButton was pressed” should be displayed. Also modify theapplication such that it also handles “Right mouseclick”. On clicking the Right Mouse Button, it should displaya message “Right Mouse Button was pressed”. Comments inyour source code are also required because they carry separatemarks during evaluation, so provide proper comments in your sourcecode as much as possible. Output Windows are displayed asbelow:
Explanation / Answer
#include<windows.h>
LRESULT CALLBACKmyWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAMlParam);
bool RegisterAppWindow(HINSTANCE hInstance);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCEhPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
HWND hWnd;
MSG msg;
if(!RegisterAppWindow(hInstance))
{
return 1;
}
hWnd = CreateWindow("MyFirstWindowClass", "urid",WS_OVERLAPPEDWINDOW | WS_VISIBLE,//write here ur "vu id"
150, 90, 500, 350, NULL, NULL, hInstance,NULL);
if(!hWnd)
{
MessageBox(hWnd, "Unable to create Window", "ERROR",MB_OK);
return 1;
}
while(GetMessage(&msg, NULL, 0, 0) > 0)
DispatchMessage(&msg);
returnmsg.wParam;
}
bool RegisterAppWindow(HINSTANCE hInstance)
{
WNDCLASS wc;
ATOM classAtom;
wc.style = 0;
wc.lpfnWndProc = myWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground =(HBRUSH)GetStockObject(GRAY_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "MyFirstWindowClass";
classAtom =RegisterClass(&wc);
if(!classAtom)
{
MessageBox(NULL, "Error ! Registering Class", "ERROR",MB_OK);
return 0;
}
return 1;
}
LRESULT CALLBACKmyWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAMlParam)
{
switch (message)
{
case WM_LBUTTONDOWN:
MessageBox(hWnd, "Left Mouse Button Clicked","Information", MB_OK | MB_ICONINFORMATION);
break;
caseWM_RBUTTONDOWN:
MessageBox(hWnd, "Right MouseButton Clicked", "Information", MB_OK | MB_ICONINFORMATION);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_SYSCOMMAND:
{
wParam &= 0xFFF0;
switch(wParam)
{
case SC_CLOSE:
if(MessageBox(hWnd, "Are yousure, you want to quit?",
"Confirmation",MB_ICONEXCLAMATION|MB_YESNO) == IDYES)
{
DestroyWindow(hWnd);
}
else
{
wParam = 0;
}
break;
default:
return DefWindowProc(hWnd, message,wParam, lParam);
}
}
default:
returnDefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.