Resizing an SDI application window

Posted on 1999-09-23
Medium Priority
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?
Question by:JamieR
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 31

Expert Comment

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,


Author Comment

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

Expert Comment

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

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.



Accepted Solution

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


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

CRect rToolBar;
CRect rStatBar;


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

m_ToolBar and m_StatusBar are member of your main frame.

Author Comment

ID: 2070710

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;
  rect->bottom += (tool.bottom - tool.top);

// add the status bar height
if (m_wndStatusBar.IsWindowVisible())
  RECT 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);

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

718 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