You are here:

C++/Changing a dialog box 's height...

Advertisement


Question
QUESTION: Hi Bill,

I am using MSC++6 which is part of Visual Studio 6 Professional.
My MFC dialog based program has multiple edit boxes, most of which are left invisible until the user calls for them. I would like to vary the dialog box's height to be relative to the amount of edit boxes showing. Can you give me some basic code and its location within the files of the program? I can fine tune the code once I see some working code and see its location. I've checked all my books and find nothing relating to changing the dialog box's height...

Thanks in advance for your help with this problem,
-Neil


ANSWER: Hi Neil,

SetWindowPos will change the window position and size.  Puzzling is there is no GetWindowPos.  But you can use GetWindowPlacement and SetWindowPlacement to get and set the current size and position.  These functions are good for restoring and saving window placement between program runs.

I've done dialogs with [ More ] buttons which double the height (just because it's convenient) hiding the [ Less ] stuff in the lower half.

Use GetWindowPlacement, change the rcNormalPosition.bottom in the returned structure, and call SetWindowPlacement.  It's pretty straight forward.  CWnd defines these functions making them easy to access.

Bill

---------- FOLLOW-UP ----------

QUESTION: Hi Bill,

Sorry to be a pain, but I'm having trouble getting this off the ground. Could you give me an example of some code that would utilize 'GetWindowPlacement', the 'WINDOWPLACEMENT' structure and how I would change the rcNormal.bottom?

Though there's a 'blurb' in one of my books concerning the above, there's no code examples to build from.

Thanks in advance for supporting my efforts to learn this process,
-Neil

ANSWER: This doubles the height of the window:

WINDOWPLACEMENT wndpl;
GetWindowPlacement( &wndpl );
wndpl.rcNormalPosition.bottom *= 2;
SetWindowPlacement( &wndpl );

Bill

---------- FOLLOW-UP ----------

QUESTION: Hi Bill, I guess that wndpl is the window handle...
How would I find the handle for my MFC dialog box?

-Neil

Answer
Not if you looked at the code I put in:

WINDOWPLACEMENT wndpl;

If this

WINDOWPLACEMENT wndpl;
GetWindowPlacement( &wndpl );
wndpl.rcNormalPosition.bottom *= 2;
SetWindowPlacement( &wndpl );

is used in any member function of a window (CDialog, CView, etc.) it works because these are member functions of a CWnd (which all windows derive from).

Bill

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Bill A

Expertise

I can answer questions about C++, programming algorithms, Windows programming in MFC (which is C++). I cannot answer questions about STL (templates) and I have no experience with Linux. I do enjoy reviewing code and critiquing it or finding problems in it. I will also gladly show better algorithms or methods if you want to take advantage of that.

Experience

I've developed a commercial embedded C compiler/assembler and IDE with debugger toolset, of which the IDE and debugger are written in C++. I work in the industry writing high tech embedded programs and Windows programs to communicate with the embedded devices.

Publications
Book: Embedded Systems Design using the Rabbit 3000 Microprocessor Authored Chapter 10 in its entirety.

Education/Credentials
BS Computer Engineering

©2016 About.com. All rights reserved.