.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Regular Expressions >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Window Procedure to draw a rectangle between two click points in VC++

Posted By:Abhisek Panda       Posted Date: November 26, 2009    Points: 10    Category: Regular Expressions    URL: http://www.dotnetspark.com  
 

This is a VC++ Window Procedure which can draw a rectangle between two click points.

HWND hwin;/*HandleToWindow instance */
HDC dc;/*HandleToDeviceContext instance*/
int click=0;
int x1, x2, y1, y2;
/*above is the public section*/
long _stdcall WndProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp)
{
switch(msg)
{
case WM_LBUTTONDOWN:
if(click==0)
{
x1=LOWORD(lp);
y1=HIWORD(lp);
click=1;
}
else
if(click==01)
{
x2=LOWORD(lp);
y2=HIWORD(lp);
Rectangle(dc,x1,y1,x2,y2);
click=0;
}
break;
case WM_DESTROY:
PostQuitMessage(hwin);
break;
default:
return DefWindowProc(hw,msg,wp,lp);
}
return(0L);
}

Description:-

Here when the left button is clicked first time then we are collecting (x1,y1) coordinates and (x2,y2) coordinates on second click using LOWORD and HIWORD.
Then we are passing the coordinates to Rectangle(dc,x1,y1,x2,y2) function where dc is the device context instance.

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend