Week 7 Programming Exercise - CPP
Week 7 Programming Exercise - CPP
-------------------------------------------------------------------------*/
#include <windows.h>
#include <Windowsx.h>
#pragma comment(lib,"winmm.lib")
#define IDT_TIMER1 100
#define IDT_TIMER2 101
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
static int count1;
static int count2;
static int Forward=TRUE;
static int MouseXpos;
static int MouseYpos;
switch (message)
{
case WM_CREATE: //Process WM_CREATE message
{
TCHAR TempText[100];
case WM_TIMER:
switch (wParam)
{
case IDT_TIMER1:
// process the 1-second timer
{
TCHAR TempText[20];
TCHAR Timer1toDisplay[200]; //Reserve to store up to
200 characters
GetClientRect (hwnd, &rect) ; //Get rectange
dimensions of Client Area
hdc = GetDC (hwnd) ;
SendMessage(hwnd,WM_ERASEBKGND,(WPARAM)hdc,NULL);
TCHAR InstructionText[] = TEXT ("Program will start with
Count Up at center of display\n\
Press Left Mouse Button to Count Up at click location and\nPress Right Mouse Button
to Count Down at click location\n\
This Program uses TIMER, Mouse button click and SendMessage.\nThe program will
erase background every time the \
left or right mouse button is clicked.\nYou will need to put up your own question \
on the working\nof the program as an exercise to understand program built by other
people. \n\
Use debug to help yourself");
return 0;
}
case WM_LBUTTONDOWN:
Forward=TRUE;
MouseXpos = GET_X_LPARAM(lParam);
MouseYpos = GET_Y_LPARAM(lParam);
break;
case WM_RBUTTONDOWN:
Forward=FALSE;
MouseXpos = GET_X_LPARAM(lParam);
MouseYpos = GET_Y_LPARAM(lParam);
break;
case WM_DESTROY:
PostQuitMessage (0) ; //inserts a WM_QUIT message in the program's
message queue.
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}