How to create an irregular shape window

zhaozj2021-02-11  180

How to create an irregular shape window

The new SDK function setWindowRGN can be used. This function defines the drawing and mouse message to a specified area of ​​the window, in fact, enables the window to be a specified irregular shape. Create a dialog-based application with AppWizard and remove the default controls, titles, and boundaries from the resource editor from the primary dialog resource. Add a CRGN data member to the dialogue, and then use the data member to establish a window area. Class CRoundDlg: public CDialog {... private: Crgn m_rgn: // window region ...} OnInitDialog function creates a modified elliptical area and call SetWindowRgn allocations of the window: BOOL CRoundDlg:: OnInitDialog () {CDialog:: OnInitDialog () / / Get size of dialog CRect rcDialog;... GetClientRect (rcDialog) // Create region and assign to window m_rgn CreateEllipticRgn (0, 0, rcDialog.Width (), rcDialog.Height ()) SetWindowRgn (GetSafeHwnd (), (HRGN ) M_ rgn, true); return true} The window of an irregular shape is created by establishing a region and calling setWindowRGN. The following example is a modified ONPAINT function to make the window shape look like a sphere.

voik CRoundDlg:: OnPaint () {CPaintDC de (this) // device context for painting // draw ellipse with out any border dc SelecStockObject (NULL_PEN) // get the RGB colour components of the sphere color COLORREF color = RGB (.. 0, 0, 255) BYTE byRed = GetRValue (color) BYTE byGreen = GetGValue (color) BYTE byBlue = GetBValue (color) // get the size of the view window Crect rect GetClientRect (rect) // get minimun number of units int nUnits = min (rect.right, rect.bottom) // calculate he horiaontal and vertical step size float fltStepHorz = (float) rect.right / nUnits float fltStepVert = (float) rect.bottom / nUnits int nEllipse = nUnits / 3 / / calculate how many todraw int nIndex // current ellipse that is being draw CBrush brush // bursh used for ellipse fill color CBrush * pBrushOld // previous brush that was selected into dc // draw ellipse, gradually moving towards upper-rightcorner for ( NINDEX = 0 Nindes < Nellipse Nindes ) {// Creat Solid Brush Brush. Creatsolidbrush (RGB ((Nindex) * BYRED) / NELLIPSE). (NINDEX * BYGREEN) / NELLIPSE), ((Nindex * Byblue) / Nellipse))))))))))))) // SELECT Brush Into DC PBRUSHOLD = DC .SelectObject (& BRHSH) // Draw Ellipse Dc .ellipse (int) Fltstepharz * 2, (int) Fltstepvert * Nindex, Rect. Right - ((int) Fltstephaz * Nindex) 1, Rect. Bottom - (INT) Fltstepvert * (NINDEX * 2)) 1) // Delete the brush brush.delecteObject ()}} finally processes the WM_NCHITTEST message to move the window when the window is hit. UINT CRoundDlg:: OnNchitTest (Cpoint point) {// Let user move window by clickign anywhere on thewindow UINT nHitTest = CDialog:.:? OnNcHitTest (point) rerurn (nHitTest = = HTCLIENT) HTCAPTION: nHitTest}

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

New Post(0)