?
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.

568 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