?
Solved

Visual C++ Question On Frame Startupsize

Posted on 1998-08-26
6
Medium Priority
?
243 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 200 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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

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