用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
- 下一篇: 给缺少Python项目实战经验的人,赶紧