Write a VC++ Program that Displays a small Rectangle,clicking inside Rectangle color should be change and Clicking out side of the Rectangle Should erase.



LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;

HBRUSH hbr;
static int x=200,y=200,x1,y1;
static POINT pt;
static RECT r1;

switch (message)
{
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
x1=x+100;
y1=y+100;
Rectangle(hdc,x,y,x1,y1);
RECT rt;
GetClientRect(hWnd,&rt);
EndPaint(hWnd,&ps);
break;

case WM_LBUTTONDOWN:
hdc=GetDC(hWnd);
pt.x=LOWORD(lParam);
pt.y=HIWORD(lParam);

r1.left=x;
r1.top=y;
r1.right=x1;
r1.bottom=y1;

hbr=CreateSolidBrush(RGB(rand()%255,rand()%255,rand()%255));
SelectObject(hdc,hbr);

if(PtInRect(&r1,pt))
{
FillRect(hdc,&r1,hbr);
}
else
{
InvalidateRect(hWnd,&r1,true);
}
break;


case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

Comments

Popular posts from this blog

Uploading Image to Sql Server Image Datatype in asp.net using fileupload Control

Get Running Sum of Query SQL Query