Click here to Skip to main content
11,702,396 members (74,375 online)
Click here to Skip to main content

Resizing Controls at run time

, 30 Nov 2000 111.4K 2.7K 61
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

Amit Nabarro
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
Questiontracker is coveraged by the sibling object Pin
handsome0314-Jun-12 17:56
memberhandsome0314-Jun-12 17:56 
GeneralActivex resize Pin
Rondina B20-May-04 4:57
memberRondina B20-May-04 4:57 
GeneralActivex resize Pin
Anonymous20-May-04 4:45
sussAnonymous20-May-04 4:45 
Questionhow to use from c# application Pin
jbmeeh13-Feb-04 10:33
sussjbmeeh13-Feb-04 10:33 
QuestionHow to save the new dialog layout back to a resource? Pin
DJM5-Aug-03 1:25
memberDJM5-Aug-03 1:25 
AnswerRe: How to save the new dialog layout back to a resource? Pin
David Pritchard17-Nov-04 3:08
memberDavid Pritchard17-Nov-04 3:08 
GeneralCursor goes away when linked with Static Library Pin
cdsmith29-Apr-03 6:34
membercdsmith29-Apr-03 6:34 
GeneralRe: Cursor goes away when linked with Static Library Pin
lesnikowski9-Jan-04 2:20
memberlesnikowski9-Jan-04 2:20 
GeneralRe: Cursor goes away when linked with Static Library Pin
tohichoi19-Sep-05 20:57
membertohichoi19-Sep-05 20:57 
GeneralRe: Cursor goes away when linked with Static Library Pin
M A V11-Jul-08 6:56
memberM A V11-Jul-08 6:56 
AnswerRe: Cursor goes away when linked with Static Library Pin
Anthony Dunk1-Jul-09 19:34
memberAnthony Dunk1-Jul-09 19:34 
GeneralI have a problem Pin
BoscoW21-Feb-03 22:38
memberBoscoW21-Feb-03 22:38 
GeneralGreat job Pin
Synetech18-Feb-03 8:30
memberSynetech18-Feb-03 8:30 
GeneralNE?YO BLAD! Pin
Booooo18-Nov-02 6:12
memberBooooo18-Nov-02 6:12 
General<FONT COLOR="#FF0000">CRectTracker hidden when controls overlap </font> Pin
sanskypotov7-Jul-02 22:05
membersanskypotov7-Jul-02 22:05 
GeneralProblem Pin
Anonymous15-Jun-01 0:03
memberAnonymous15-Jun-01 0:03 
GeneralRe: Problem Pin
Anonymous15-Oct-01 21:38
memberAnonymous15-Oct-01 21:38 
GeneralRe: Problem Pin
J Cardinal9-Apr-02 14:10
memberJ Cardinal9-Apr-02 14:10 

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.

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