[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

Visual C++ Question On Frame Startupsize

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
larockd
Asked:
larockd
  • 3
  • 2
1 Solution
 
dstCommented:
You could read the size of the dialog every time it resizes and then set the size of the frame acording to that.
0
 
chensuCommented:
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
 
larockdAuthor 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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
chensuCommented:
>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
 
larockdAuthor 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
0
 
chensuCommented:
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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now