How to pack some non-customer districts of the window and control their size

zhaozj2021-02-17  62

1. Sometimes, we need the title bar of the packaging window, and do not want the window's non-customer area to control refresh, such as a border, menu.

Parameters from WM_NCPAINT WPARAM can get the area that needs to be refreshed:

HRGN = (hrgn) wparam; // handle of update region

Therefore, the WndProc function can be overloaded, and the area occupied by the title bar is removed in this area, the BCB code is as follows:

Case WM_NCPAINT: {

HRGN HRGNSRC; // Handle To Src Windowdc Update Region HRGN HRGNCAPTION; // Handle To Combine Region HRGN HRGNNEW; // Handle To New Windowdc Update Region HRGNSRC = (HRGN) msg.wparam

TRect * winrect = new TRect (); GetWindowRect (ParentForm-> Handle, winrect); TRect rc; rc = TRect (winrect-> left, winrect-> top, winrect-> right, winrect-> top GetSystemMetrics (SM_CYCAPTION) 3); hRgnCaption = CreateRectRgnIndirect (& rc); hRgnNew = CreateRectRgnIndirect (& rc); if ((WORD)! hrgnSrc> 1 && RectInRegion (hrgnSrc, & rc)) {DeleteObject (hRgnNew); DeleteObject (hRgnCaption); DeleteObject (hrgnSrc); delete winrect; break;} if ((WORD) hrgnSrc> 1) {CombineRgn (hRgnNew, hrgnSrc, hRgnCaption, RGN_DIFF);} else {HRGN hRgnAll = :: CreateRectRgnIndirect (winrect); CombineRgn (hRgnNew, hRgnAll, hRgnCaption, RGN_DIFF) ; DeleteObject (hRgnAll);} Msg.Result = DefWindowProc (ParentForm-> Handle, Msg.Msg, (int) hRgnNew, Msg.LParam); DrawCaption (); // custom draw caption DeleteObject (hRgnNew); DeleteObject (hRgnCaption) DeleteObject (HRGNSRC); Delete WinRect; Return;} 2. How to adjust the width of the title bar

In other words, it is to adjust the size of the window customer area, and naturally modify the size of the non-client area. We can process the WM_NCCALCSIZE message, note that this method does not apply to the window with the main menu of the window.

WM_NCCALCSIZE parameter WPARAM and LPARAM meanings:

fCalcValidRects = (BOOL) wParam; // valid area flag lpncsp = (LPNCCALCSIZE_PARAMS) lParam; // points to size calculation data or lpncsp = (LPRECT) lParam; // points to new window coordinates specific code:

case WM_NCCALCSIZE: {// calculate window's client bool fCalcValidRects = (bool) Msg.WParam; if (fCalcValidRects) {RECT rtSave; CopyRect (& rtSave, (LPRECT) Msg.LParam); rtSave.top = TitleHeight - GetSystemMetrics (SM_CYCAPTION) - Yedge; if (Haveborder) {RTSAVE.LEFT = 4 -Xedge; rtsave.right- = 4- xedge; rtsave.bottom - = 4- yedge;} copyRect (lprect) msg.lparam, & rtsave);} else { RECT rtSave; LPRECT prtClt; LPNCCALCSIZE_PARAMS pNC; pNC = (LPNCCALCSIZE_PARAMS) Msg.LParam; prtClt = & (pNC-> rgrc [0]); CopyRect (& rtSave, prtClt); CopyRect (& (pNC-> rgrc [2]) & (PNC-> RGRC [1])); (PNC-> RGRC [2]). TOP = TitleHeight - getSystemMetrics - Yedge; RTSAVE.TOP = TitleHEHEIGHT - GetSystemMetrics (SM_CYCAPTION) -YEDGE-1; if; IF (Haveborder) {(PNC-> RGRC [2]). Left = 4 -xedge; (PNC-> RGRC [2]). Right- = 4- xedge; (PNC-> RGRC [2]). Bottom - = 4- yedge; rtsave.right = 4 -xedge; rtsave.right- = 4- xedge; rtsave.bottom - = 4- yedge;} CopyRect (PrtCLT, & RTSAVE);} Break;}

转载请注明原文地址:https://www.9cbs.com/read-29291.html

New Post(0)