The original author name Zhang Enhanced
This section describes the implementation of a dialog box for the self-painted background, any shape in the VC.
Reader Rating 7 rating number 2
The body program section is shown below: The implementation of the effect can usually pass through two methods: 1. Processing the WM_PRINT implementation. 1 Create a dialog-based EXE project DEMO, everything uses the default settings. 2 Change dialogue resources: IDD_DEMO_DLG, set the Border of the Style style to NONE. Import the BMP resource required for background, ID name IDB_BACKGND. Add a variable m_bmgbg in the cdemodlg's header; 3 Add the following code to load the resource: m_bmgbg.loadbitmap (IDB_BACKGND); 4 Process the onpaint (), function, implement the background image.
void CDemoDlg :: OnPaint () {CPaintDC dc (this); // device context for painting CRect rect; GetClientRect (& rect); if (IsIconic ()) {SendMessage (WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc (), 0) ; // Center icon in client rectangle int cxicon = getSystemMetrics; int Cyicon = getSystemMetrics (SM_CYICON); int x = (Rect.width () - CXICON 1) / 2; int y = (Rect.Height () - Cyicon 1) / 2; // Draw the icon dc.drawicon (x, y, m_hicon);} Else // The following is the processing part of the program {if (m_bmgbg.getsafehandle ()) {CDC DcMemory; DcMemory.createCompatiBLEDC (& DC); cBitmap * PoldBMP = DCMEMORY.SELECTOBJECT (& m_bmgbg); Bitmap Bmp; BMGBG.GetBitmap; DC.Bitblt (0, 0, Rect.width (), Rect.Height (), & DcMemory, 0, 0 , SRCCOPY); DCMemory.selectObject (PoldBMP); DcMemory.deletedc (); dc.selectObject (m_font); dc.setbkmode (transparent); Dc.SetTextColor (RGB (64, 64, 64)); dc.Textout (8 , 8, "Desktop Tube "); DC.TextOut (10, 45," Enter you here to place to the most layered window: "); CRGN RGN; Rgn.createroundRectRgn (Rect.Creater Support, Rect.Right, Rect.Bottom , 10, 10); SetwindowRGN ((HRGN) RGN (TRUE); CRGN RGN2; Rgn2.createroundRectRgn (Rect.CreateroundRectrgn (Rect.Right, Rect.TOP, Rect.right, Rect.Bottom, 10, 10); DC.framergn (& RGN2, & Clush (RGB (106, 106, 106)), 1, 1);} // cdialog :: onpaint ();}} 5 Responsive Drag Effects in response to mouse events. Handle WM_NCHITTEST events.
OnNcHitTest (CPoint point) code is as follows: UINT CSetTopDlg :: OnNcHitTest (CPoint point) {CRect rect; GetWindowRect (rect); rect.bottom = rect.top 25; UINT nHitTest = CDialog :: OnNcHitTest (point); if (nHitTest == htclient && rect.ptinRect (Point)) Return Htcaption; Else Return Nhittest;} This is as simple as the figure. The text is complete:
Interface Demo Demo.gif