Working with the Mouse Example

//Mouse Click Example//
#include <windows.h>
#include <tchar.h>
TCHAR mousestr[255]=TEXT("\0");
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
MSG msg;
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 = TEXT("myWindowClass");
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&wc);
CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("myWindowClass"), TEXT("Mouse Click Demo"), WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 700, 200, NULL, NULL, hInstance, NULL);
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
hdc=GetDC(hwnd);
switch (message)
{
case WM_LBUTTONDOWN://deals with left mouse button down
if (wParam & MK_SHIFT)//deals with shift key press followed by left button down
{
wsprintf(mousestr,TEXT("shift & left button down %d,%d"),LOWORD(lParam),HIWORD(lParam));
TextOut(hdc,LOWORD(lParam),HIWORD(lParam),mousestr,_tcslen(mousestr));
}
else if (wParam & MK_CONTROL)//deals with control key press followed by left button down
{
wsprintf(mousestr,TEXT("control & left button down %d,%d"),LOWORD(lParam),HIWORD(lParam));
TextOut(hdc,LOWORD(lParam),HIWORD(lParam),mousestr,_tcslen(mousestr));
}
else if (wParam & MK_RBUTTON)//deals with and right button down followed by left button down
{
wsprintf(mousestr,TEXT("left and right button %d,%d"),LOWORD(lParam),HIWORD(lParam));
TextOut(hdc,LOWORD(lParam),HIWORD(lParam),mousestr,_tcslen(mousestr));
}
else //default left mouse button only
{
wsprintf(mousestr,TEXT("left button down at %d,%d"),LOWORD(lParam),HIWORD(lParam));
TextOut(hdc,LOWORD(lParam),HIWORD(lParam),mousestr,_tcslen(mousestr));
}
ReleaseDC(hwnd,hdc);
break;
case WM_LBUTTONUP://deals with left mouse button up
wsprintf(mousestr,TEXT("left button up at %d,%d"),LOWORD(lParam),HIWORD(lParam));
TextOut(hdc,LOWORD(lParam),HIWORD(lParam),mousestr,_tcslen(mousestr));
ReleaseDC(hwnd,hdc);
break;
case WM_RBUTTONDOWN://deals with right mouse button down
wsprintf(mousestr,TEXT("right button down at %d,%d"),LOWORD(lParam),HIWORD(lParam));
TextOut(hdc,LOWORD(lParam),HIWORD(lParam),mousestr,_tcslen(mousestr));
ReleaseDC(hwnd,hdc);
break;
case WM_RBUTTONUP://deals with right mouse button up
wsprintf(mousestr,TEXT("right button up at %d,%d"),LOWORD(lParam),HIWORD(lParam));
TextOut(hdc,LOWORD(lParam),HIWORD(lParam),mousestr,_tcslen(mousestr));
ReleaseDC(hwnd,hdc);
break;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}