?
Solved

Resizing an SDI application window

Posted on 1999-09-23
6
Medium Priority
?
820 Views
Last Modified: 2013-11-20
I want to resize the client area of my app to a specific size. However, the status bar and tool bar may (or may not) be visible at the time. GetClientRect seems to include the area in the control bars. How do I resize my window so that the visible client area is a specific size?
0
Comment
Question by:JamieR
6 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 2069243
Hi JamieR,

See help for CalcWindowRect() which can be used to calculate a windows size when given the client rect.

hope that helps,

ZOPPO
0
 
LVL 1

Author Comment

by:JamieR
ID: 2069359
This doesn't seem to take into account the size of the status bar, toolbar and the menu.
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2069396
GetClientRect() on the frame counts the area which may be occupied by the toolbars, status bars, and the view.

GetClientRect() on the view counts only the view. If the view is actually a CScrollView and features scroll bars, the client rect of the view does _not_ include those scroll bars. If the scroll bars aren't there, GetClientRect() doesn't account for their possible size and returns the whole area of the view.

Your question isn't clear--you seem disappointed that GetClientRect() doesn't account for the space where your status bar and tool bar might appear, but it turns out that space really is a part of your client area. Do you mean to say that you really want the view's size to be constant? Or that you want the frame's cinet area size to be constant? Maybe you actually want the frame's _entire_ size to be constant.

..B ekiM

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:JamieR
ID: 2069534
I wish to set the client area (excluding toolbars, status bars, scroll bars - i.e. the white bit of the view) to a particular size so that I can fit and display an image in it.

Supplying the image size to CFrameWnd::CalcWindowRect I obtain the frame size and I then call CFrameWnd::SetWindowPos, but I cannot see the entire image when the toolbar or status bar is active. Hence I assume that CalcWindowRect is not taking the status and toolbars into account.

Jamie


0
 
LVL 1

Accepted Solution

by:
alex1234 earned 300 total points
ID: 2070451
CRect r;
int iMyWidth;
int iMyHeight;

GetClientRect(r);

iMyWidth = r.Width() - GetSystemMetrics(SM_CXVSCROLL);
iMyHeight = r.Height - GetSystemMetrins(SM_CYHSCROLL);

CRect rToolBar;
CRect rStatBar;

m_ToolBar.GetClientRect(rToolBar);
m_StatusBar.GetClientRect(rStatBar);

iMyHeight -= rToolBar.Height() + rStatBar.Height();

m_ToolBar and m_StatusBar are member of your main frame.
0
 
LVL 1

Author Comment

by:JamieR
ID: 2070710
Alex,

Yes. Here's what I did in the CFrameWnd code:

rect.left = 0;
rect.top = 0;
rect.right = image.width;
rect.height = image.height;

// get the view window size
m_wndView.CalcWindowRect(rect, CWnd::adjustOutside);

// add the toolbar height
if (m_wndToolBar.IsWindowVisible())
{
  RECT tool;
  m_wndToolBar.GetWindowRect(&tool);
  rect->bottom += (tool.bottom - tool.top);
}

// add the status bar height
if (m_wndStatusBar.IsWindowVisible())
{
  RECT status;

  m_wndStatusBar.GetWindowRect(&status);
  rect->bottom += (status.bottom - status.top);
}

  // get the frame window size
::AdjustWindowRectEx(rect, GetStyle(), TRUE, GetExStyle());

SetWindowPos(NULL, 0, 0, rect->right - rect->left, rect->bottom - rect->top, SWP_NOZORDER | SWP_NOMOVE);
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question