Wm_nccalcsize Message Processing

Source: Internet
Author: User

M_nccalcsize Message Processing
Objective
There are many ways to specify the application's caption height and border width. The most common of these are the following two types of methods:
The first kind: Create no title bar application, in the customer area to make a portion of the space with a picture to draw a title bar, people "mistakenly think" is the title bar.
The second kind: processing the wm_nccalcsize message received by the application, changing the client area in the window to get the appropriate title bar height.
Can not say which method is good, which method is bad, in fact, the first approach is simple, but also can do very beautiful, but the uncomfortable point is that every time the customer area is always calculated when the coordinates of the starting position; The second method is a bit cumbersome (in fact, not troublesome), but a bit good, customer area is not responsible for redrawing , the location is not calculated when responding to WM_PAINT messages.
"The second Kind"
To get the most accurate and comprehensive information to go to Ms's lair to find the en version of (Google what the most annoying), do not be afraid of a sentence to see (my English level () << CET-4 (425), I can read, certainly no one to understand it).
WParam:
If WParam is TRUE, it specifies so the application should indicate which part of the client area contains valid Informat Ion. The system copies the valid information to the specified area within the new client area.
If WParam is FALSE, the application does isn't need to indicate the valid part of the client area.
LParam:
If WParam is TRUE, LParam points to a NCCALCSIZE_PARAMS structure that contains information a application can use to Cal Culate the new size and position of the client rectangle.
If WParam is FALSE, the LParam points to a RECT structure. On entry, the structure contains the proposed window rectangle for the window. On exit, the structure should contain the screens coordinates of the corresponding window client area.
This is msnd on the previous paragraph: meaning that if wparam is true, you need to specify an available client area in the new rectangle, or if the wparam is false the application does not specify a client area in the new rectangle.
I understand this: when the window is created, the wparam is false, and the other condition is true.
"True Case"
Imagine: The window starts at position A, and suddenly moves to position B.



At this time windows will send a wm_nccalcsize message to the window notifying the application window of the location or size of the change, and the application should specify the location of the new non-client and client areas. Message specific content is:
Message:wm_nccalcsize
Wparam:true
LParam: A pointer to a three rectangle (Nccalcsize_params *). Here is the NCCALCSIZE_PARAMS structure:
typedef struct TAGNCCALCSIZE_PARAMS {
RECT Rgrc[3];
Pwindowpos Lppos;
} nccalcsize_params, *lpnccalcsize_params;
Here's a description of MSDN:
Rgrc
RECT
An array of rectangles. The meaning of the array of rectangles changes during the processing of the wm_nccalcsize message.
When the window procedure receives the WM_NCCALCSIZE message, the first rectangle contains the new coordinates of a window That had been moved or resized, that's, it is the proposed new window coordinates. The second contains the coordinates of the window before it was moved or resized. The third contains the coordinates of the window ' s client area before the window is moved or resized. If The window is a child window, the coordinates was relative to the client area of the parent window. If The window is a top-level window, the coordinates was relative to the screen origin.
When the window procedure returns, the first rectangle contains the coordinates of the new client rectangle resulting from The move or resize. The second rectangle contains the valid destination rectangle, and the third rectangle contains the valid source rectangle . The last of the rectangles is used
Simple translation (see through):
When the window processing receives the WM_NCCALCSIZE message, the first rectangle contains the new coordinates after the move or after resizing (that is, the coordinates of b), which is the suggested coordinates. The second rectangle contains the coordinates before moving or resizing (that is, a coordinate), and the third rectangle contains the coordinates of the customer area before moving (that is, the customer area coordinates in a coordinate).
Before processing this message (that is, after wm_nccalcsize processing is complete), the first rectangle should contain the coordinates of the new client area (that is, the customer area coordinates in b coordinates), the second rectangle contains the available target rectangle (b coordinate), and the third coordinate contains the source rectangle (a coordinate). The following two rectangles are also used. Nutshell:
Before we deal with this: the first rectangle is B, the second rectangle is a, the third rectangle is AC,
What we're dealing with: The first rectangle is BC, the second rectangle is B, and the third is rectangle a.
So I wrote down the C processing code:
int xframe = 2; /* Thickness of left and right borders */
int yframe = 2; /* Thickness of bottom border */
int nthight = 40; /* Height of title bar */
Nccalcsize_params * p; /*true is the pointer */
RECT * RC; /*false is the pointer */
RECT Arect;
RECT Brect;
RECT Bcrect;


if (WParam = = TRUE)
{
p = (nccalcsize_params *) LParam;


/* Copy a B rectangle position */
Copyrect (&arect,&p->rgrc[1]);
Copyrect (&brect,&p->rgrc[0]);


/* Specify the position of the BC rectangle */
Bcrect.left = Brect.left + xframe;
Bcrect.top = Brect.top + nthight;
Bcrect.right = Brect.right-xframe;
Bcrect.bottom = Brect.bottom-yframe;


/* Each rectangle is normalized to BC B a*/
Copyrect (&p->rgrc[0],&bcrect);
Copyrect (&p->rgrc[1],&brect);
Copyrect (&p->rgrc[2],&arect);
}
Above is to deal with the case of wparam to true, and then look back to the case of false, that is, when initializing, we know that just when the initialization is not a->b but from no rectangle to have a rectangle.
"False Case"
At this point, lparam is pointing to a rectangle, the rectangle is the current position of the window x, we are going to return the XC, also is to return X into XC, the following is given C code:
Else
{
rc = (RECT *) LParam;


Rc->left = Rc->left + xframe;
Rc->top = Rc->top + nthight;
Rc->right = rc->right-xframe;
Rc->bottom = rc->bottom-yframe;
}


At this point, wm_nccalcsize explanation is complete. Custom height of the window design (according to the QQ style painting):


[Email protected]
Niesongsong
Shenyang
to the
The entire function is written:


Case Wm_nccalcsize:
Procnccalcsize (Hwnd,message,wparam,lparam);




int Procnccalcsize (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM)
{
int xframe = 2; /* Thickness of left and right borders */
int yframe = 2; /* Thickness of bottom border */
int nthight = 40; /* Height of title bar */
Nccalcsize_params * p;
RECT * RC;


RECT Arect;
RECT Brect;
RECT Bcrect;


if (WParam = = TRUE)
{
p = (nccalcsize_params *) LParam; /* Rectangle is b A AC, the target is changed to BC B a*/


Copyrect (&arect,&p->rgrc[1]);
Copyrect (&brect,&p->rgrc[0]);


/* Specify the position of the BC rectangle */
Bcrect.left = Brect.left + xframe;
Bcrect.top = Brect.top + nthight;
Bcrect.right = Brect.right-xframe;
Bcrect.bottom = Brect.bottom-yframe;


/* Each rectangle is returned to position */
Copyrect (&p->rgrc[0],&bcrect);
Copyrect (&p->rgrc[1],&brect);
Copyrect (&p->rgrc[2],&arect);
}
Else
{
rc = (RECT *) LParam;


Rc->left = Rc->left + xframe;
Rc->top = Rc->top + nthight;
Rc->right = rc->right-xframe;
Rc->bottom = rc->bottom-yframe;
}
return GetLastError ();
}

Wm_nccalcsize Message Processing

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.