We help IT Professionals succeed at work.

Visual C++ Question On Frame Startupsize

larockd
larockd asked
on
Medium Priority
251 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
Comment
Watch Question

dst

Commented:
You could read the size of the dialog every time it resizes and then set the size of the frame acording to that.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
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

Commented:
>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);

Author

Commented:
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

Commented:
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.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.