Solved

Visual C++ Question On Frame Startupsize

Posted on 1998-08-26
6
213 Views
Last Modified: 2010-04-10
I  am writing an application thatis a frae based application.  I created a dialog that goes inside the frame when the program starts.  However when the program starts my  dialog is larger then the frame.  I have to use the frame's scroll barsto see the whole dialog.  

I would like the frame to be autosized to my dialog.  How can I do this without compromising the size of the dialog inside the frame.

Thanks
0
Comment
Question by:larockd
  • 3
  • 2
6 Comments
 

Expert Comment

by:dst
ID: 1171299
You could read the size of the dialog every time it resizes and then set the size of the frame acording to that.
0
 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
ID: 1171300
1. Use GetWindowRect to get the size of the dialog box.
2. Use AdjustWindowRectEx to calculate the required size of the frame window rectangle.
3. Use SetWindowPos to resize the frame window.
0
 

Author Comment

by:larockd
ID: 1171301
I have a few questions about this.  I thought I would be able to handle it, but I guess not.

When my program starts the frame is displayed on screen in the CWgrzcontApp::InitInstance() function.  I tried adding the code you suggested after the line

m_pMainWnd->ShowWindow(SW_SHOW);   // MFC APP WIZZARD CODE
m_pMainWnd->UpdateWindow();    // MFC APP WIZZARD CODE
 
1.)  Where does the program actually load the dialog that goes into the frame?
2.)  I added the following code after the above two lines.  Where did I go wrong?

      LPRECT pLprect;  
      GetWindowRect(pLprect);
*** I get an error here GetWindowRect takes more than one parameter.  Which is true for the API call , but not the MFC call.

      AdjustWindowRectEx(pLprect);

Q: I know the above function call is incorrect, but I am at a loss because I am unable to provide the required info to it..  I am not sure whereand how to obtain a pointer to my client window which would be the dialog.

 
 SetWindowPos( const CWnd* pWndInsertAfter, pLprect.left, pLprect.top, pLprect.right, pLprect.bottom, SWP_SHOWWINDOW );

Q: Now with this function, I am wondering where I obtain the height and width values.  I assumed it was from the LPRECT structure, but that structure does not provide that info, Unless it is the right / bottom?

I do appreciate any help.

Thanks
Darrell
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 23

Expert Comment

by:chensu
ID: 1171302
>1.)  Where does the program actually load the dialog that goes into the frame?
This is a question I should ask you. Where do you create the dialog box? I think it should be the OnCreate of the frame window.

>2.)  I added the following code after the above two lines.  Where did I go wrong?

Add it into the OnCreate of the frame window.

>I get an error here GetWindowRect takes more than one parameter.  Which is true for the API call , but not the MFC call.

Because you are calling GetWindowRect in the member function of the derived CWinApp class and GetWindowRect is not a member of CWinApp, the compiler thinks GetWindowRect is a global function like ::GetWindowRect, which takes two parameters.

>LPRECT pLprect;   GetWindowRect(pLprect);

This will definitely cause a GPF because pLprect is an uninitialized pointer.

In the OnCreate of the frame window:

CRect rect;
yourDialog.GetWindowRect(&rect);

>Q: I know the above function call is incorrect, but I am at a loss because I am unable to provide the required info to it..  I am not sure whereand how to obtain a pointer to my client window which would be the dialog.

In the OnCreate of the frame window:

CRect rect;
::AdjustWindowRectEx(&rect, this->GetStyle(), TRUE, this->GetExStyle());

>Q: Now with this function, I am wondering where I obtain the height and width values.  I assumed it was from the LPRECT structure, but that structure does not provide that info, Unless it is the right / bottom?

In the OnCreate of the frame window again:

this->SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(), SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER);

0
 

Author Comment

by:larockd
ID: 1171303
Sorry It took so long to respond.  I started back to night school trying to get my CS degree and I work all day long.  Today, being a holiday I have time to catch up.

I searched my program to find where the dialog is created and I have not been able to find exactly where it is created.

I searched through theapplication with "find" to locate any  instances of the dialog and it traced itto an enum
E:\CCLASS\wgrzcont\wgrzcontView.h(22):      enum { IDD = IDD_WGRZCONT_FORM };

Then I traced a call to CRecordview such as the following
E:\CCLASS\wgrzcont\wgrzcontView.cpp(37):      : CRecordView(CWgrzcontView::IDD)
I think this is where the dialog is loading any idea's?

This is a basic application that is manipulating an access database I am trying to get working.

Any thoughts on if the dialog is loading from there ( the crecordview call)?  Now in that function should I place the code to resize the frame to the dialog?

Thanks.  I do appreciate your time with this.  Please answer at your leisure..  If you want more points to help me further just say the word and I will get them to you.

Darrell
0
 
LVL 23

Expert Comment

by:chensu
ID: 1171304
So the only problem you are having is to get the window handle of the dialog box. The dialog box you mentioned is actually the formview. You seem to be using the document/view architecture. Right? There is no explicit create function for the view. You may override the CWnd::OnParentNotify of the frame window to get the window handle. Or, override the OnCreate of the view. Once you get the handle, you may send a message to the frame window to do the resizing.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

786 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