用VC++制作变形窗体
首先,我们要建立一个基于对话框的工程distort,这样生成了三个类,即CAboutDlg , CDistort , CDistortDlg ,我们将要进行大改动的是CDistortDlg类,因此我们给出此文件的原代码,有改动的地方 我们用粉色字表出,并加人注释。
| // distortDlg.h : header file // #if !defined(AFX_DISTORTDLG_H__B21CDC69_5A48_11D7_A464_00055DE445C1__INCLUDED_) #if _MSC_VER > 1000
class CDistortDlg : public CDialog // Dialog Data // ClassWizard generated virtual function overrides // Implementation // Generated message map functions
private: //窗体初始的矩形对象 {{AFX_INSERT_LOCATION}} #endif // !defined(AFX_DISTORTDLG_H__B21CDC69_5A48_11D7_A464_00055DE445C1 |
下一步,我们先将对话框的属性中的stype设为popup ,而Border设为none,如图:
在此类的实现文件中,我们就将系统自动生成的函数略去了,只写出有改动的地方
| // distortDlg.cpp : implementation file // #include "stdafx.h" #if def _DEBUG /// class CAboutDlg : public CDialog ON_WM_NCHITTEST()
BOOL CDistortDlg::OnInitDialog() // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. CMenu* pSysMenu = GetSystemMenu(FALSE); // Set the icon for this dialog. The framework does this automatically // TODO: Add extra initialization here //-------------------------set time---------------------------- |
其中椭圆效果是通过 int SetWindowRgn(HRGN hRgn,BOOL bRedraw);
而参数 hRgn 是窗体区的句柄, 参数 bRedraw 是决定是否要重画窗体,在本例中Windows 向窗体发送 WM_PAINT消息,从而调用 OnPaint()函数,
下面我们来修改此函数
| void CDistortDlg::OnPaint() { CPaintDC dc(this); if (IsIconic()) { // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle // Draw the icon //获得客户区的尺寸 CBrush *pBrushOld; //定义画刷,在此你可以更改颜色 //下面编写实现窗体任意托动的函数 HCURSOR CDistortDlg::OnQueryDragIcon() UINT CDistortDlg::OnNcHitTest(CPoint point) //下面编写定时器实数 //若想结果n次变化后正好便为圆形,则设此值为 1.035 void CDistortDlg::OnTimer(UINT nIDEvent) CRect rectWnd; //确定窗体区域中心 //分情况处理各种定时事件 //确定窗体的矩形大小 //释放对象 //创建椭圆区域 SetWindowRgn((HRGN)m_rgn,TRUE); if(nCount==10)//设置变化次数,此为10次 |
希望大家通过对本例的实践,初步了解 MFC 的对话框机制 (细节请参见《Vicual c++ 高级编程》)
总结
以上是生活随笔为你收集整理的用VC++制作变形窗体的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: (亲试有效)如何完美更换WordPres
- 下一篇: Visual C++中的ODBC编程实例