VC++ Program that Displays a small Rectangle with every Left Mouse button.Double Clicking on existing rectangle should erase the rectangle.

Add
wcex.style= CS_HREDRAW | CS_VREDRAW |CS_DBLCLKS;

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

static int n,i;
static RECT count[100];
static int x,y,x1,y1;

switch (message) 
{
case WM_LBUTTONDOWN:
hdc=GetDC(hWnd);
x=LOWORD(lParam);
y=HIWORD(lParam);
x1=x+100;
y1=y+100;

Rectangle(hdc,x,y,x1,y1);
count[n].left=x;
count[n].top=y;
count[n].right=x1;
count[n].bottom=y1;
n++;
break;
case WM_LBUTTONDBLCLK:
x=LOWORD(lParam);
y=HIWORD(lParam);

for(i=0;i<n;i++)
{
if(x>count[i].left && x<count[i].right && y<count[i].bottom && y>count[i].top)
{
InvalidateRect(hWnd,&count[i],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