?
Solved

setting the size of a client window

Posted on 2000-02-12
19
Medium Priority
?
398 Views
Last Modified: 2013-11-20
Hi

I am writing an image processing program which uses MFC doc/view model on SDI.
What I want to do is that every time I load a file i change the size of the client window.
I understand that it should also change the size of the main frame.
Does anyone have any suggestions?
0
Comment
Question by:zaphord
  • 11
  • 3
  • 3
  • +1
19 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 2515495
Use the following functions.

::AdjustWindowRect
::AdjustWindowRectEx
CWnd::GetStyle
CWnd::GetExStyle
0
 

Author Comment

by:zaphord
ID: 2516005
Adjusted points to 75
0
 

Author Comment

by:zaphord
ID: 2516006
I'm affraid it didn't work.

Here is what I wrote:

      CWnd *fathwin=this->GetParent();
      
      RECT rect;
      rect.bottom=100;
      rect.left=100;
      rect.right=400;
      rect.top=400;
      ::AdjustWindowRect (&rect,fathwin->GetStyle(),true);
      //CalcWindowRect(&rect);
      //fathwin->CalcWindowRect (&rect);
      fathwin->SetWindowPos(NULL,rect.left,rect.top,rect.right,rect.bottom,SWP_NOZORDER|SWP_NOMOVE|SWP_NOREDRAW);
      RECT rct;
      GetClientRect(&rct);

I got a different size.
I also tried using the Ex version :

::AdjustWindowRectEx (&rect,fathwin->GetExStyle(),true,true);

still to no avail.

do you have any idea why it doesn't work?

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
LVL 23

Expert Comment

by:chensu
ID: 2516779
Using CWnd::CalcWindowRect is easier. Use rect.Width() and rect.Height() instead of rect.right and rect.bottom for the 4th and 5th parameters of SetWindowPos because SetWindowPos expects the width and height.

0
 

Author Comment

by:zaphord
ID: 2519639
Adjusted points to 100
0
 

Author Comment

by:zaphord
ID: 2519640
I tried the following:

void CInterfaceView::OnInitialUpdate()
{
      CView::OnInitialUpdate();
      
      CRect rect(0,0,200,200);

      CWnd *fathwin=this->GetParent();
      
      fathwin->CalcWindowRect (&rect);
      fathwin->SetWindowPos(NULL,0,0, rect.Width(), rect.Height() ,SWP_NOZORDER|SWP_NOMOVE|SWP_NOREDRAW);
      RECT rct;
      GetClientRect(&rct);

      
      
}

However I found out that :
rect.top=0
rect.bottom=159
rect.left=0
rect.right=196
and this is not a 200*200 as I asked the program.

I know I can calculate th offset and then call the SetWindowPos again, but I'm looking for the  normal way to do it, and not to hack my way through it.
0
 
LVL 23

Expert Comment

by:chensu
ID: 2521444
Are you sure fathwin is the window you want? What about

this->GetParentFrame()

or ::AfxGetMainWnd()?
0
 

Author Comment

by:zaphord
ID: 2522224
I just tried both of them. I got the same results.
0
 
LVL 7

Expert Comment

by:Bill Nolan
ID: 2522432
Possibly try using the m_hWndMDIClient member of the application's main frame window, and then applying CWnd::MoveWindow() or another of the above functions to resize it.
0
 

Author Comment

by:zaphord
ID: 2522525
a. My program is SDI.
b. thus I didn't find any m_hWndMDIClient member of the main frame. (my main frame is subclassed from CFrameWnd)
0
 
LVL 7

Expert Comment

by:Bill Nolan
ID: 2523009
Oh, sorry about that.  But no luck with MoveWindow()?  You might also try sizing the frame window to something very small, then adding your file.  
0
 

Author Comment

by:zaphord
ID: 2523171
I'm afraid so. I still get a client window smaller then the one I wanted.
0
 

Author Comment

by:zaphord
ID: 2526157
Adjusted points to 150
0
 
LVL 12

Expert Comment

by:migel
ID: 2527758
Hi!
What about ResizeParentToFit()?
0
 

Author Comment

by:zaphord
ID: 2528110
ResizeParentToFit is not a member of CView (my base class)
0
 
LVL 12

Expert Comment

by:migel
ID: 2530704
Hm
May be this code will help you:

void CInterfaceView::OnInitialUpdate()
{
CView::OnInitialUpdate();
CRect rect(0,0,200,200);
CWnd *fathwin=this->GetParent();

CRect rectQuery(0, 0, 32767, 32767);
CRect rectClient;
fathwin->GetClientRect(&rectClient);
// lets calc toolbars area!
fathwin->RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery,                  &rectQuery, &rectQuery, FALSE);
// calc offsets to hold toolbars
int dx = rectClient.Width() - rectQuery.Width();
int dy = rectClient.Height()-rectQuery.Height();
// and add it to the wanted area
rect.bottom += dy;
rect.right += dx;
fathwin->CalcWindowRect (&rect);
fathwin->SetWindowPos(NULL,0,0, rect.Width(), rect.Height() ,SWP_NOZORDER|SWP_NOMOVE|SWP_NOREDRAW);
RECT rct;
GetClientRect(&rct);
}
0
 

Author Comment

by:zaphord
ID: 2538225
I tried using it, got a non-squere client area.
0
 
LVL 12

Accepted Solution

by:
migel earned 450 total points
ID: 2539560
Ok I check this code and found that it must be like this:
{
      CView::OnInitialUpdate();
      CRect rect(0,0,200,200);
      CWnd *fathwin=this->GetParentFrame();
      CRect rectQuery(0, 0, 32767, 32767);
      CRect rectClient;
      fathwin->GetClientRect(&rectClient);
      // lets calc toolbars area!
      fathwin->RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &rectQuery, NULL, TRUE);
      // calc offsets to hold toolbars
      int dx = rectClient.Width() - rectQuery.Width();
      int dy = rectClient.Height()- rectQuery.Height();
      // and add it to the wanted area
      rect.bottom += dy+GetSystemMetrics(SM_CYMENU); // since CWnd::calcWindowRect assume that we haven`t MENU :-(
      rect.right += dx;
      CalcWindowRect (&rect,CWnd::adjustOutside); //add our specific border space
      fathwin->CalcWindowRect (&rect,CWnd::adjustOutside);
      fathwin->SetWindowPos(NULL,0,0, rect.Width(), rect.Height() ,SWP_NOZORDER|SWP_NOMOVE|SWP_NOREDRAW);
      RECT rct;
      GetClientRect(&rct);
}
0
 

Author Comment

by:zaphord
ID: 2540067
Thanks, it has solved my problem
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

601 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