Modifer form with VC ++

xiaoxiao2021-03-06  63

Modifer form with VC

First, we must establish a dialog-based engineering discharge, which generates three classes, caboutdlg, cdistort, cdistortdlg, we will make a big change is the CDistortDLG class, so we give the original code of this file, change Place We use a pink word, and add a comment.

// distortDlg.h:! Header file // #if defined (AFX_DISTORTDLG_H__B21CDC69_5A48_11D7_A464_00055DE445C1__INCLUDED _) # define AFX_DISTORTDLG_H__B21CDC69_5A48_11D7_A464_00055DE445C1__INCLUDED_ #if _MSC_VER> 1000 # pragma once # endif // _MSC_VER> 1000 // CDistortDlg dialog class CDistortDlg: public CDialog {// Constructionpublic: CDistortDlg (CWnd * pParent = NULL); // standard constructor // Dialog Data {{AFX_DATA (CDistortDlg) enum {IDD = IDD_DISTORT_DIALOG}; // NOTE: the ClassWizard will add data members here}} AFX_DATA // ClassWizard generated virtual function overrides // {{AFX_VIRTUAL (CDistortDlg) protected: virtual void DoDataExchange (CDataExchange * pDX); // DDX / DDV support}} AFX_VIRTUAL // Implementationprotected: HICON m_hIcon; // Generated message map functions // {{AFX_MSG (CDistortDlg) virtual BOOL OnInitDialog (); afx_msg void OnSysCommand (UINT nID, LPARAM lParam); afx_msg void OnPaint (); afx_msg HCURSOR OnQueryDragIcon ();}} aFX_MSG // any part WM_NCTHITEST overload message, a single laser can move dialog box afx_msg Uint Onnchittest (CPoint P Oint); // timer, enable the form to deform the AFX_MSG Void ONTIMER (Uint NideEvent); // Close the timer AFX_MSG void onDestroy () when the dialog is revoked; declare_MESSAGE_MAP () private: // Form Initial rectangular object CRECT M_RECTWND; // Set the area CRGN M_RGN;}; {{AFX_INSERT_LOCATION}} #ENDIF / / /! DEFINED (AFX_DISTDLG_H_1D7_A464_00055DE445C1_A464_0005555555c1_A464_00055DE445C1__inCluded_)

Next, let's first set the Stype in the properties of the dialog to popup, and Border is set to none, as shown in the figure:

In this type of implementation file, we will ignore the function generated by the system, only the change in the change

// distortDlg.cpp: implementation file // #include "stdafx.h" #include "distort.h" #include "distortDlg.h" #if def _DEBUG # define new DEBUG_NEW # undef THIS_FILEstatic char THIS_FILE [] = __FILE __; # Endif //// Caboutdlg Dialog Used for App About Class Caboutdlg: Public CDialog {// Slightly Send the system automatically generated class member ... // This is a message macro map begin_MESSAGE_MAP (CDistortDLG, CDIALOG) {{{ AFX_MSG_MAP (CDistortDlg) ON_WM_SYSCOMMAND () ON_WM_PAINT () ON_WM_QUERYDRAGICON () ON_WM_NCHITTEST () ON_WM_TIMER ()}} AFX_MSG_MAPEND_MESSAGE_MAP () // Here we will have to be added to the dialog procedures are generally overloaded virtual function OnInitDiolog (), which is a message response function , // WM_INITDIALOG message processing #define EVENT_REDRAW 0 BOOL CDistortDlg :: OnInitDialog () {CDialog :: OnInitDialog ();. // Add "About ..." menu item to system menu // IDM_ABOUTBOX must be in the system command range .ASSERT ((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT (IDM_ABOUTBOX <0xF000); CMenu * pSysMenu = GetSystemMenu (FALSE); if (! pSysMenu = NULL) {CString strAboutMenu; strAboutMenu.LoadString (IDS_ABOUTBOX); if (! StraboutMenu.isempty ()) {psysmenu-> appendmenu (mf_separator); psysm enu-> AppendMenu (MF_STRING, IDM_ABOUTBOX, strAboutMenu);.}} // Set the icon for this dialog The framework does this automatically // when the application's main window is not a dialogSetIcon (m_hIcon, TRUE); // Set big iconSetIcon (m_hicon, false); // SET SMALL ICON / / TODO: ADD Extra Initialization Here // Gets size getClientRect (M_RectWnd) of the dialog customer area; // Create the size m_rgn.createellipticRGN of the Form dialog customer area (0, 0, M_RectWnd.right, M_RectWnd.Bottom; // Set the Heavy Picture Window Timer, redraw a setWindowRgn ((hrgn) m_RGN, TRUE every 0.1 second; this-> settimer (event_redraw, 100, null); // ------------------------- SET TIME ----------------------- ----- Return True; // Return True UnsS you set the focus to a control

The ellipse effect is through int setWindowRGN (HRGN HRGN, BOOL BREDRAW); the parameter hrgn is the handle of the form area, the parameter BREDRAW is determined whether to select the form, in this case, Windows sends a WM_PAINT message to the form, thus calling Onpaint () function, let's modify this function.

Void cdistortdlg :: onpaint () {CPAINTDC DC (this); if (ISICONIC ()) {// device context for Painting SendMessage (WM_ICONERASEBKGND, (WPARAM) dc.getsafehdc (), 0); // Center icon in Client Rectangleint CXICON = getSystemMetrics (SM_CXICON); int Cyicon = getSystemMetrics (SM_CYICON); CRECT RECT; GetClientRect (& Re); int x = (Rect.width () - CXICON 1) / 2; int y = (Rect.Height () - Cyicon 1) / 2; // Draw the icondc.drawicon (x, y, m_hicon);} else {// add by myself -------------------- ------------------------------ Dc.selectStockObject (null_pen); // Drawing unbounded ellipse // get customers CRECT RECT; GetClientRect (Rect); CBRUSH * PBRUSHOLD; CBRUSH brushnew; // Define brush brush, you can change color brushnew.createsolidbrush (RGB (204, 255, 66)); // Select draw brush as a drawing device PBRUSHOLD = dc.selectObject (& brushnew); // Draw an ellipse Dc.ellipse (Rect); // Restore the brush, and release dc.selectObject (PBRUSHOLD); brushnew.deleteObject ();}} // Subscription Implementation Form Raw function hcursor cdistortdlg :: ONQUERYDRAGICON () {Return (hcursor) m_hicon;} uint cdistortdlg :: ONNCHITTEST (CPOINT POINT) {uint nhittest = cDialog :: ONNCHITTEST (POINT); Return (NHITTES) T == htclient)? HTCAPTION: NHITTEST;} // The following preparation timer real estumes // If the result is the result is a circular, set this value to 1.035 # define multi 1.1 void cdistortdlg :: ONTIMER (uint NidEvent) {static ncount = 0; // Form change number, each time I increase 1static border = 1; // Indicates to become larger or becoming static double DMULTI = 1; // Form change multiple CRECT RECTWND; CPOINT PTMIDDLE, PTTopleft, PTBTMRIGHT; / / Determine Form Region Center PTMIDDLE = M_RectWnd.centerpoint (); // Sub-casement Processing Various Timers Switch (NidEvent) {Case Event_redRAW: Ncount ; if (Border == 1) {// Indication Big DMULTI * = MULTI;} else {// Indicates small DMULTI / = MULTI;} / / Determine the rectangular size of the form PTTopleft.x = (long) (ptmiddle.x-m_recTwnd.Width () / (2 * DMulti )); pttopleft.y = (line) (ptmiddle.y-m_recTwnd.Height () / 2); pTBTMRIGHT.X = (long) (PTMIDDLE.X

m_rectwnd.width () / (2 * DMULTI)); ptbtmright.y = (long) (PTMIDDLE.Y M_RECTWND.HEIGHT () / 2); RectWnd.seTRect (PTTopleft, PTBTMRight); // Release Object M_Rgn.Detach (); // Create an ellipse area m_rgn.createelllipticRgn (pttopleft.x, pttopleft.y, ptbtmright.x, ptbtmright.y); setWindowRGN ((hrgn) m_RGN, true); if (ncount == 10) // set changes The number of times, this is 10 times {ncount = 0; border = (border == 1)? - 1: 1; // 10 times reverse change} Break;} cdialog :: Ontimer (Nidevent);} The last effect Photo:

I hope that through the practice of this example, I will initially understand the MFC dialog box mechanism (see "Vicual C Advanced Programming")

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

New Post(0)