Solved

Adjusting window sizes

Posted on 1998-08-10
6
521 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
  • 4
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
psdavis earned 150 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 7

Expert Comment

by:psdavis
Comment Utility
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
Comment Utility
Also check out the OnSizing function, here you can stop the resizing of the window before it happens.

Phillip
0
 

Author Comment

by:RJV
Comment Utility
Thanks, Phillip!

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 122
building a service to accessed via telnet client, want colors ? 4 78
mapBully challenge 6 88
Path of Workbook 3 44
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now