CS410 Visual Programming Assignment 3 Solution Fall 2012

Assignment

Task 1:

a – Write a Program for windows with client area

b – Windows has caption as “Mouse Tester”

c – Windows has Minimize, Maximize and Close Buttons at the top right corner

d – Windows length and width would be as DEFAULT

Task 2:

a – When a Left Mouse Button is pressed in Client Area; a message box would be appearing with text as “Left Mouse Button isPressed.”
b – When a Right Mouse Button is pressed in Client Area; a message box would be appearing with text as “Right Mouse Buttonis Pressed.”

c – In sub tasks a and b, the message box appeared would have following properties;

         I – Caption of Message Boxes are “Mouse Press Information”

        II – Message Boxes have Information Icon

Solution:


Solution:

#include <windows.h>
const char my_ClassName[] = "myclass";
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
 switch(msg)
 {
 case WM_LBUTTONDOWN:
 MessageBox(hwnd,"Left Mouse Button Pressed","Mouse Press Information",MB_OK | MB_ICONINFORMATION);
 break;
 case WM_RBUTTONDOWN:
 MessageBox(hwnd,"Right Mouse Button Pressed","Mouse Press Information",MB_OK | MB_ICONINFORMATION);
 break;
 case WM_CLOSE:
 DestroyWindow(hwnd);
 break;
 case WM_DESTROY:
 PostQuitMessage(0);
 break;
 default:
 return DefWindowProc(hwnd, msg, wParam, lParam);
 }
 return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
 LPSTR lpCmdLine, int nCmdShow)
{
 WNDCLASSEX wc;
 HWND hwnd;
 MSG Msg;
// This wil initilize the wc class properties
 wc.cbSize = sizeof(WNDCLASSEX);
 wc.style = 0;
 wc.lpfnWndProc = WndProc;
 wc.cbClsExtra = 0;
 wc.cbWndExtra = 0;
 wc.hInstance = hInstance;
 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
 wc.lpszMenuName = NULL;
 wc.lpszClassName = my_ClassName;
 wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
 {
 MessageBox(NULL, "Window Registration Failed!", "Error!",
 MB_ICONEXCLAMATION | MB_OK);
 return 0;
 }
//This step will create window
 hwnd = CreateWindowEx(
 WS_EX_CLIENTEDGE,
 my_ClassName,
 "Mouse Tester",
 WS_OVERLAPPEDWINDOW,
 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
 NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
 {
 MessageBox(NULL, "Window Creation Failed!", "Error!",
 MB_ICONEXCLAMATION | MB_OK);
 return 0;
 }
ShowWindow(hwnd, nCmdShow);
 UpdateWindow(hwnd);
// This will receive messages
 while(GetMessage(&Msg, NULL, 0, 0) > 0)
 {
 TranslateMessage(&Msg);
 DispatchMessage(&Msg);
 }
 return Msg.wParam;
}
DOWNLOAD SOLUTION HERE
loading...