setting the size of a client window

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?
zaphordAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
Use the following functions.

::AdjustWindowRect
::AdjustWindowRectEx
CWnd::GetStyle
CWnd::GetExStyle
0
zaphordAuthor Commented:
Adjusted points to 75
0
zaphordAuthor Commented:
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

chensuCommented:
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
zaphordAuthor Commented:
Adjusted points to 100
0
zaphordAuthor Commented:
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
chensuCommented:
Are you sure fathwin is the window you want? What about

this->GetParentFrame()

or ::AfxGetMainWnd()?
0
zaphordAuthor Commented:
I just tried both of them. I got the same results.
0
Bill NolanOwner, Lead Technology ProgrammerCommented:
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
zaphordAuthor Commented:
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
Bill NolanOwner, Lead Technology ProgrammerCommented:
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
zaphordAuthor Commented:
I'm afraid so. I still get a client window smaller then the one I wanted.
0
zaphordAuthor Commented:
Adjusted points to 150
0
migelCommented:
Hi!
What about ResizeParentToFit()?
0
zaphordAuthor Commented:
ResizeParentToFit is not a member of CView (my base class)
0
migelCommented:
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
zaphordAuthor Commented:
I tried using it, got a non-squere client area.
0
migelCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zaphordAuthor Commented:
Thanks, it has solved my problem
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.