Write a VC++ Program to draw a Rectangle and when User Clicks Inside the Rectangle should be Display the two Cross Line as Diagonal of the Rectangle. and it should be erased when clicked Outside.


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

static int x=220,y=180,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;

if(PtInRect(&r1,pt))
{
MoveToEx(hdc,x,y,0);
LineTo(hdc,x1,y1);
MoveToEx(hdc,x,y1,0);
LineTo(hdc,x1,y);
}
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

☀️ New AI Perfects Heliostat Aiming to Boost Solar Tower Power

๐Ÿ“‰ Study: African Women Face Higher Risk of Job Loss to AI in Outsourcing Sector