Click here to Skip to main content
Licence 
First Posted 30 Nov 2000
Views 96,758
Bookmarked 53 times

Resizing Controls at run time

By | 30 Nov 2000 | Article
A method to allow the user to visually resize and position any control at run time.

Sample Image - resize_at_runtime.gif

Introduction

Suppose you wanted to give the user the ability to modify the size and position on a certain control? This example shows how to implement resizing controls on a dialog box as it is done when drawing controls on a dialog template or using Visual Basic at design time.

In order to accomplish this, we can use the class CRectTracker to manage all the drawing and resizing of a rectangular frame which also has (optional) 6 resize handlers (as in the image above). First thing to do is to invoke a CRectTracker and specify given coordinates:

LPRECT rect = new RECT;
CWnd* wnd = (CWnd*)(GetDlgItem(IDC_EDIT1));
wnd->GetWindowRect(rect);
ScreenToClient(rect);
m_tracker = new CRectTracker(rect,CRectTracker::dottedLine  | 
                CRectTracker::resizeOutside | 
                CRectTracker::hatchedBorder );
m_tracker->Draw(pDC);

There are two events that are needed to be taken care of:

  1. SetCursor
    if (pWnd == this && m_tracker->SetCursor(this, nHitTest))
        return TRUE;

    This is done in order to draw the correct mouse cursors when floating the mouse pointer over the rectangle.

  2. OnLButtonDown
    m_tracker->Track(this, point, TRUE);
    Invalidate(FALSE);
    CDC* pDC = GetDC();
    m_tracker->Draw(pDC);

    This will take care of the drawing of the rectangle with resizing it.

Once you have finished, all you have to do is draw the control with the new rectangle coordinates:

LPRECT rect = new RECT;
CWnd* wnd = (CWnd*)(GetDlgItem(IDC_EDIT1));
rect = LPRECT(m_tracker->m_rect); 
wnd->MoveWindow(rect,TRUE) ;

That's it!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Amit Nabarro



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralActivex resize PinmemberRondina B4:57 20 May '04  
GeneralActivex resize PinsussAnonymous4:45 20 May '04  
Questionhow to use from c# application Pinsussjbmeeh10:33 13 Feb '04  
QuestionHow to save the new dialog layout back to a resource? PinmemberDJM1:25 5 Aug '03  
AnswerRe: How to save the new dialog layout back to a resource? PinmemberDavid Pritchard3:08 17 Nov '04  
GeneralCursor goes away when linked with Static Library Pinmembercdsmith6:34 29 Apr '03  
GeneralRe: Cursor goes away when linked with Static Library Pinmemberlesnikowski2:20 9 Jan '04  
GeneralRe: Cursor goes away when linked with Static Library Pinmembertohichoi20:57 19 Sep '05  
GeneralRe: Cursor goes away when linked with Static Library PinmemberM A V6:56 11 Jul '08  
AnswerRe: Cursor goes away when linked with Static Library PinmemberAnthony Dunk19:34 1 Jul '09  
GeneralI have a problem PinmemberBoscoW22:38 21 Feb '03  
GeneralGreat job PinmemberSynetech8:30 18 Feb '03  
GeneralNE?YO BLAD! PinmemberBooooo6:12 18 Nov '02  
GeneralCRectTracker hidden when controls overlap Pinmembersanskypotov22:05 7 Jul '02  
GeneralProblem PinmemberAnonymous0:03 15 Jun '01  
GeneralRe: Problem PinmemberAnonymous21:38 15 Oct '01  
GeneralRe: Problem PinmemberJ Cardinal14:10 9 Apr '02  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 1 Dec 2000
Article Copyright 2000 by Amit Nabarro
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid