Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Adjusting window sizes

Posted on 1998-08-10
6
Medium Priority
?
547 Views
Last Modified: 2013-11-20
How can one adjust the window sizes with code such as one does with the cursor/mouse, be it of the main (mainframe) window or of internal windows such as of the MDI type? The idea is to be able to:

  - Accompany the adjustments of the main window with
    child windows, when the user adjusts the main one

  - Be able to stop any window resizing altogether

Thanks in advance for your input!

RJV
0
Comment
Question by:RJV
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
psdavis earned 600 total points
ID: 1320499
Override your OnSize function.  Everytime your main window changes, you will get the WM_SIZE message.  If you want to stop the sizing, you can prohibit this function from calling it's base class.

Phillip

afx_msg void OnSize( UINT nType, int cx, int cy );

Parameters

nType   Specifies the type of resizing requested. This parameter can be one of the following values:

SIZE_MAXIMIZED   Window has been maximized.

SIZE_MINIMIZED   Window has been minimized.

SIZE_RESTORED   Window has been resized, but neither SIZE_MINIMIZED nor SIZE_MAXIMIZED applies.

SIZE_MAXHIDE   Message is sent to all pop-up windows when some other window is maximized.

SIZE_MAXSHOW   Message is sent to all pop-up windows when some other window has been restored to its former size.

cx   Specifies the new width of the client area.

cy   Specifies the new height of the client area.

Remarks

The framework calls this member function after the window's size has changed.

If the SetScrollPos or MoveWindow member function is called for a child window from OnSize, the bRedraw parameter of SetScrollPos or MoveWindow should be nonzero to cause the CWnd to be repainted.


0
 
LVL 7

Expert Comment

by:psdavis
ID: 1320500
Here's some more information for you.  The WM_GETMINMAXINFO message will allow you to set the sizes of the windows automatically for you...

Adding the WS_THICKFRAME windows style allows a window to be re-sized. By removing this from the Mainframe window's styles, you can prevent this window from being resized. Further, the MINMAXINFO structure stores the maximum and minimum tracking size of a window. The WM_GETMINMAXINFO message is sent to a window when the size or position of that window is about to change. An application can over-ride the handler for this message to set a window's default minimum or maximum tracking size.


MORE INFORMATION


You can prevent the Mainframe window of an AppWizard-generated SDI application from being resized by following these steps:

Modify the IDR_MAINFRAME menu to add a top-level menu item (F&reeze!) with an ID of ID_FREEZE.
Add a public Boolean data member (say, BOOL freezeState) to the CMainFrame class to keep track of the current state of the application. Initialize freezeState to FALSE in the constructor of the CMainFrame class.
Provide a command handler for the 'Freeze' menu item as follows:
void CMainFrame::OnFreeze() {

      char* lpszFreeze = "F&reeze!";
      char* lpszUnFreeze = "&UnFreeze!";
      CMenu* pmenu = GetMenu();
      if (!freezeState)
      {

          freezeState = TRUE;
          pmenu->ModifyMenu(ID_FREEZE, MF_STRING, ID_FREEZE,
                                                       lpszUnFreeze);
          DWORD style = ::GetWindowLong(this->m_hWnd, GWL_STYLE);
// Remove the thick frame style and the Minimize, Maximize buttons

        style &= ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_THICKFRAME);
        ::SetWindowLong(this->m_hWnd, GWL_STYLE, style);
} else {
       freezeState = FALSE;
       pmenu->ModifyMenu(ID_FREEZE, MF_STRING, ID_FREEZE,
                                                      lpszFreeze);
       DWORD style = ::GetWindowLong(this->m_hWnd, GWL_STYLE);
// Add the thick frame style and the Minimize, Maximize buttons

      style |= (WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_THICKFRAME);
      ::SetWindowLong(this->m_hWnd, GWL_STYLE, style);
      }
      DrawMenuBar();
}
Provide a handler for the WM_GETMINMAXINFO message as follows:
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) {

      if (freezeState)
      {
          RECT rc;

          GetWindowRect(&rc);
          lpMMI->ptMaxSize.x = rc.right - rc.left;
          lpMMI->ptMaxSize.y = rc.bottom - rc.top;
          lpMMI->ptMaxPosition.x = rc.left;
          lpMMI->ptMaxPosition.y = rc.top;
          lpMMI->ptMinTrackSize.x = rc.right - rc.left;
          lpMMI->ptMinTrackSize.y = rc.bottom - rc.top;
          lpMMI->ptMaxTrackSize.x = rc.right - rc.left;
          lpMMI->ptMaxTrackSize.y = rc.bottom - rc.top;
      }

      CFrameWnd::OnGetMinMaxInfo(lpMMI);
}
If the mainframe is maximized, disable the Freeze menu option because there is no point in making the window non-resizable because a maximized window cannot be resized anyway:
void CMainFrame::OnSize(UINT nType, int cx, int cy) {

      CFrameWnd::OnSize(nType, cx, cy);
      CMenu* pmenu = GetMenu();

      if (nType == SIZE_MAXIMIZED)
          pmenu->EnableMenuItem(ID_FREEZE, MF_DISABLED|MF_GRAYED);
      else
          pmenu->EnableMenuItem(ID_FREEZE, MF_ENABLED);

      DrawMenuBar();
}

NOTE: The steps to prevent the Mainframe window of an MDI application from being resized should be identical to the steps listed in this article. However, because there is more than one menu resource in an MDI application, you may want to design your application to add the 'Freeze' menu item to more than one menu resource.
 
Phillip
0
 

Author Comment

by:RJV
ID: 1320501
Phillip,

Please correct me if I'm wrong, but aren't your suggestions dependent on events? Namely, if the user does the changing. How, however, does one do one's own changing, to simulate that of the user?

RJV

0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 7

Expert Comment

by:psdavis
ID: 1320502
AHhhh.....  It would help if I would read the question. :)

You could do several SetWindowPos commands in a row.  (e.g. Decreasing the x and increasing the cx simultaneously)  After every SetWindowPos call, the window should redraw.

CWnd::SetWindowPos
BOOL SetWindowPos( const CWnd* pWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags );

Return Value

Nonzero if the function is successful; otherwise 0.

Parameters

pWndInsertAfter   Identifies the CWnd object that will precede this CWnd object in the Z-order. This parameter can be a pointer to a CWnd or a Pointer to one of the following values:

wndBottom   Places the window at the bottom of the Z-order. If this CWnd is a topmost window, the window loses its topmost status; the system places the window at the bottom of all other windows.

wndTop   Places the window at the top of the Z-order.

wndTopMost   Places the window above all nontopmost windows. The window maintains its topmost position even when it is deactivated.

wndNoTopMost   Repositions the window to the top of all nontopmost windows (that is, behind all topmost windows). This flag has no effect if the window is already a nontopmost window.

See the "Remarks" section for this function for rules about how this parameter is used.

x   Specifies the new position of the left side of the window.

y   Specifies the new position of the top of the window.

cx   Specifies the new width of the window.

cy   Specifies the new height of the window.

Phillip
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1320503
Also check out the OnSizing function, here you can stop the resizing of the window before it happens.

Phillip
0
 

Author Comment

by:RJV
ID: 1320504
Thanks, Phillip!

0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

670 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