This article describes the VC + + interface Programming An MFC example, based on the Htcontrol Control class Chtdlgbase dialog box base class main file code. This program can complete the dynamic creation of the frame form, form appearance (customer area and non-customer area), adjust the size of the form, Invalid child window control, and other functions.
The specific implementation code is as follows:
/****************************************************************************
|
Copyright (c) 2012, | /#if!defined (__chtdlgbase1_h__) # Define __CHTDLGBASE1_H__ class Afx_class_export Chtdlgbase1:public CDialog {declare_dynamic (CHTDlgBase1) Public:/**** ************************************************************************
| function function: Create modal dialog box | | Input Parameters: | | SzName: Form Title | | Dwstyle: Form Properties | | dwExStyle: Form Extension Properties | | pMainWnd: If this form is the main form, pass &m_pmainwnd | | Output parameters: none | | Return Value: 0 indicates successful creation, 0 represents failure | |
Description: | /int_ptr Createmodaldlg (char* szName , DWORD dwstyle, DWORD dwExStyle = NULL, cwnd** pmainwnd = NULL); /****************************************************************************
| function function: Creating modeless dialog Box | | Input Parameters: | | SzName: Form Title | | Dwstyle: Form Properties | | dwExStyle: Form Extension Properties | | pMainWnd: If this form is the main form, pass &m_pmainwnd | | Output parameters: none | | Return Value: 0 indicates successful creation, 0 represents failure | |
Description: | /INT_PTR Createmodallessdlg (char*
SzName, DWORD dwstyle, DWORD dwExStyle = NULL, cwnd** pMainWnd = null); /****************************************************************************
| function function: Make form rectangular area Invalid | | Input Parameters: | | Lprect: Invalid rectangle, null indicates invalid entire form region | | Binvalidatechildren: Is the subform on the lprect area also invalid? | Output parameters: none | | return value: None |
|
Description: | /void InvalidateRect (Lpcrect lprect,
BOOL Binvalidatechildren = FALSE);
Public://form width, the form size changes after the value update int m_iwindowwidth;
The form is high, the form size changes after the value updates int m_iwindowheight;
Form Customer area width, the form size changes after the value update int m_iclientwidth;
Form client area is high, the form size changes after the value update int m_iclientheight;
int m_iminwindowwidth;
int m_iminwindowheight;
The maximum form width, which defaults to 0, which means that the screen is covered with int m_imaxwindowwidth;
The maximum form height, which defaults to 0, which means that the screen is covered with int m_imaxwindowheight;
TRUE: Modal dialog box FALSE: Modeless dialog box, not directly assigned to BOOL M_bmodal;
TRUE: Press mouse move on form, form follow move FALSE: Form does not follow move, you can directly assign BOOL M_blbtnmovewindow in a derived class;
It is not directly assigned to BOOL m_bshowwindowflag111;
Public:chtdlgbase1 ();
Virtual ~chtdlgbase1 ();
afx_msg int OnCreate (lpcreatestruct lpcreatestruct);
afx_msg BOOL OnEraseBkgnd (cdc* PDC);
afx_msg void OnGetMinMaxInfo (minmaxinfo* lpmmi);
afx_msg void Onshowwindow (BOOL bshow, UINT nstatus); afx_msg void Onnccalcsize (BOOL bcalcvalidrects, Nccalcsize_params* LPNCSP);
afx_msg lresult Onnchittest (CPoint point);
afx_msg void OnClose ();
afx_msg void OnActivate (UINT nstate, cwnd* pwndother, BOOL bminimized);
afx_msg void Onactivateapp (BOOL bactive, DWORD dwthreadid);
afx_msg void OnDestroy ();
afx_msg void OnLButtonDown (UINT nflags, CPoint point);
afx_msg void OnLButtonDblClk (UINT nflags, CPoint point);
afx_msg void Onncpaint ();
afx_msg BOOL OnNcActivate (bool bactive);
afx_msg void OnLButtonUp (UINT nflags, CPoint point);
afx_msg BOOL onnccreate (lpcreatestruct lpcreatestruct);
afx_msg void OnNcDestroy ();
afx_msg void Onnclbuttondblclk (UINT nhittest, CPoint point);
afx_msg void Onnclbuttondown (UINT nhittest, CPoint point);
afx_msg void Onnclbuttonup (UINT nhittest, CPoint point);
afx_msg void OnSize (UINT ntype, int cx, int cy);
Declare_message_map () protected:virtual void OnOK ();
virtual void OnCancel ();
Hicon M_hicon;
private:cwnd** M_ppmainwnd;
};
#endif//!__chtdlgbase1_h__
This instance code has certain reference value in VC + + project development, hope can bring certain help to everybody's project development.