[MFC] dialog window resizing control onsize/onsizing

Source: Internet
Author: User


Reference: http://www.360doc.com/content/08/1210/09/799_2090143.shtml

Reference: MSDN

Owed by: Spring Night rain Http://blog.csdn.net/chunyexiyu reprint please indicate source

one key to resizing a window is to make a different response depending on the direction of the adjustment.

For example, from the left, when you adjust to the minimum value, you cannot proceed with the adjustment, and you need to restore the location according to the right boundary.

0. Enable dialog box as an Adjustable dialog box

In the dialog box properties, Appearance-->border, select resizing

1. The size limit of the dialog box, preset to allow the user to adjust the size range , for example: the usual lower limit for we think need to ensure that the window information display normal minimum value

MinWidth =;

MinHeight =;

2. Responding to resizing messages

onsize function is changed after processing, the window size has changed

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

onsizing in response to a user's drag when the window has not changed size

Cwnd::onsizing The framework calls this member function to indicate that the user is resizing the rectangle.

3. Detailed description of response onsizing

Onsizing (UINT fwside, LPRECT prect)

Onsizing in response to the user's drag, at which time the window has not changed size; According to the incoming parameter fwside determine the direction of user adjustment, according to the incoming outgoing parameter prect to determine the size of the adjustment.

3.1 parameter Description:

Fwside: Indicates which side to move, the value (1-8) is left to drag, drag on the right, drag on the top, drag down the bottom, drag on the left, drag on the right, drag down the left, and drag under the right.

Left:1 right:2 top:3 bottom:6 left+right:3 right+top:5 left+bottom:7 right+bottom:8

Prect: Drag the formed Rectangle window, as pointer variable, change the structure will affect the size of the window, thus affecting the results of the adjustment

You can define four macros to use, specifically whether there is a definition in MFC, I did not find, so I define the

#define MOVE_LEFT 1
#define Move_right 2
#define MOVE_TOP 3
#define MOVE_BOTTOM 6

3.2 Controlling the size of windows in Onsizing: using incoming outgoing parameters prect control

A. Response adjustment: Depending on the direction of the user adjustment, when the user selects the width from the left, we also adjust from the left side, so does the same height.

B. Size limit: Adjust the CRect value that the incoming prect points to when the size of the move exceeds the limit we set

  If the window width reaches the minimum value
  if (fwside = = Move_right | | fwside = = move_right + Move_top | | fwside = move_right + move_bottom)
  {
      Prect->right = prect->left + MinWidth  ;
  }
  else
  {
      prect->left = Prect->right-minwidth  ;
  }
  
   if (fwside = = Move_bottom | | fwside = = move_bottom + Move_left | | fwside = move_bottom + move_right)
   {
      PRECT-&G T;bottom = Prect->top + minheight;
   }
   else
   {
      prect->top = prect->bottom-minheight;
   }

4. Adjust the size of each control as needed in the OnSize function

The OnSize function is post-processing and the window size has changed, and we need to adjust the size of the components in the dialog to fit the window size. For example: Widen the edit window a bit

if (Message for tuning message && component built) if (NType = = size_restored &&:: IsWindow (M_edit))

Component Adjustment GetDlgItem (Idc_edit)->movewindow (xxxx)

}

(Because the first onsize message will precede InitDialog, the component is not yet built and the component cannot be adjusted, so the condition is added to this iswindow)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.