CEditView : : PreCreateWindow (cs) ; // Now specify the new window style . cs.style &;= ~ (ES_AUTOHSCROLL |WS_HSCROLL); return bResult ; } 18、通用控件的显示窗口 MFC 提供了几个 CView 派生的视窗类, 封装了通用控件的功能,但仍然使用工 作框
文档显示窗口体系结构:CEditView 封装了编辑控件,CTreeView 保持了树 列
表控件,CListView 封装了列表显示窗口控件,CRichEditView 可以处理多种编 辑 控件。 19、移动窗口 调用 CWnd : : SetWindowPos 并指定 SWP_NOSIZE 标志。目的位置与父窗口有关 (顶层窗口与屏幕有关)。调用 CWnd : : MoveWindow 时必须要指定窗口的大小。 //Move window to positoin 100 , 100 of its parent window . SetWindowPos (NULL, 100 , 100 , 0 , 0 , SWP_NOSIZE |SWP_NOAORDER); 20、重置窗口的大小 调用 CWnd: : SetWindowPos 并指定 SWP_NOMOVE 标志, 也可调用 CWnd : : MoveWindow 但必须指定窗口的位置。 // Get the size of the window . Crect reWindow ; GetWindowRect (reWindow ); //Make the window twice as wide and twice as tall . SetWindowPos (NULL , 0 , 0 , reWindow . Width ( ) *2, reWindow . Height () * 2, SWP_NOMOVE |SWP_NOZORDER ); 21、如何创建一个不规则形状的窗口 可以使用新的 SDK 函数 SetWindowRgn。该函数将绘画和鼠标消息限定在窗口的 一个指定的区域,实际上使窗口成为指定的不规则形状。 使用 AppWizard 创建一个基于对的应用程序并使用资源编辑器从主对话资
源中 删除所在的缺省控件、标题以及边界。 给对话类增加一个 CRgn 数据成员,以后要使用该数据成员建立窗口区域。 Class CRoundDlg : public CDialog { … private : Crgn m_rgn : // window region … } ; 修改 OnInitDialog 函数建立一个椭圆区域并调用 SetWindowRgn 将该区域分配给 窗口: 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 ; } 通过建立区域和调用 SetWindowRgn,已经建立一个不规则形状的窗口,下面 的例子程序是修改 OnPaint 函数使窗口形状看起来象一个球形体。 voik CRoundDlg : : OnPaint ( ) { CPaintDC de (this) ; // device context for painting . //draw ellipse with out any border dc. SelecStockObject (NULL