C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » General »

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


Posted Date: 17 Sep 2009    Resource Type: Code Snippets    Category: General
Author: Abhisek PandaMember Level: Gold    
Rating: 1 out of 5Points: 10



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.



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
VC++ WndProc  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Blinking text in DOS, compiled with Turbo C
Previous Resource: A simple stop watch in c++
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use