*/ --------------------------------------------------------------------------------------
*/ 出自: 编程中国 http://www.bc-cn.net
*/ 作者: 风动 E-mail:xidiankeda492@yahoo.com.cn QQ:305687910
*/ 时间: 2007-7-20 编程论坛首发
*/ 声明: 尊重作者劳动,转载请保留本段文字
*/ --------------------------------------------------------------------------------------
// distort1Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "distort1.h"
#include "distort1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDistort1Dlg dialog
CDistort1Dlg::CDistort1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CDistort1Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDistort1Dlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDistort1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDistort1Dlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDistort1Dlg, CDialog)
//{{AFX_MSG_MAP(CDistort1Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_WM_DESTROY()
ON_WM_CANCELMODE()
ON_WM_NCHITTEST()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDistort1Dlg message handlers
// 修改OnInitDialog函数建立一个椭圆区域
// 并调用SetWindowRgn将该区域分配给窗口
//定义定时器事件号
#define EVENT_REDRAW1 0
//初始化对话框窗体
BOOL CDistort1Dlg::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);
pSysMenu->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 dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, TRUE); // Set small icon
// TODO: Add extra initialization here
//获得对话框客户区的尺寸
GetClientRect(m_rectWnd);
//创建窗体区域并与窗体建立联系
m_rgn.CreateEllipticRgn(0,0,m_rectWnd.right,m_rectWnd.bottom);
SetWindowRgn((HRGN)m_rgn, TRUE);
//设置重画窗口的定时器
//每2秒重绘一次对话框
this->SetTimer(EVENT_REDRAW1,2000,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CDistort1Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CDistort1Dlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
if (IsIconic())
{
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
//重新编辑else块里的代码
//绘制一个不带边界的椭圆
dc.SelectStockObject(NULL_PEN);
//获得窗口客户区的尺寸
CRect rect;
GetClientRect(rect);
CBrush *pBrushOld;
CBrush brushNew;
//定义画刷
brushNew.CreateSolidBrush(RGB(0,0,255));
//选取画刷作为画图设备
pBrushOld = dc.SelectObject(&brushNew);
//绘制椭圆
dc.Ellipse(rect);
//将画刷还原,并释放所用的画刷
dc.SelectObject(pBrushOld);
brushNew.DeleteObject();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDistort1Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//定义椭圆长轴变化的倍数,变化10次后正好成为圆形
//简单计算后就可得到倍数约为1.035
#define MULTI 1.035
//定时时刻到了后,重新设置窗体区域
void CDistort1Dlg::OnTimer(UINT nIDEvent)
{
static nCount = 0; //窗体变化次数计数
static bOrder = 1; //确定窗体是变大还是变小
static double dMulti =1; //窗体的变化倍数
CRect rectWnd;
CPoint ptMiddle, ptTopLeft, ptBtmRight;
//确定窗体区域中心
ptMiddle = m_rectWnd.CenterPoint();
switch (nIDEvent) //分情况处理各种定时器事件
{
case EVENT_REDRAW1: //重绘窗体定时器事件
nCount++;
if(bOrder == 1)
{
//bOrder为1表示窗体变大
dMulti*= MULTI;
}
else
{
//否则表示窗体变小
dMulti/= MULTI;
}
//确定窗体所在区域的矩形大小
ptTopLeft.x = ptMiddle.x - m_rectWnd.Width()/(2*dMulti);
ptTopLeft.y = ptMiddle.y - m_rectWnd.Height()/2;
ptBtmRight.x = ptMiddle.x + m_rectWnd.Width()/(2*dMulti);
ptBtmRight.y = ptMiddle.y + m_rectWnd.Height()/2;
rectWnd.SetRect(ptTopLeft, ptBtmRight);
//释放区域对象,为下次创建做准备
m_rgn.Detach();
//根据前面确定的矩形区域创建椭圆区域
m_rgn.CreateEllipticRgn(ptTopLeft.x,ptTopLeft.y,
ptBtmRight.x,ptBtmRight.y);
//将窗体限制在该矩形区域内,第三个参数取TURE表示要重绘窗体
SetWindowRgn((HRGN)m_rgn, TRUE);
if(nCount == 10)
{
//若已经经过了10次变化,则反向变化
nCount = 0;
bOrder = (bOrder == 1) ? -1:1;
}
break;
}
CDialog::OnTimer(nIDEvent);
}
void CDistort1Dlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
}
//实现窗体的任意拖动
UINT CDistort1Dlg::OnNcHitTest(CPoint point)
{
//用户单击窗体的任何地方也能拖动窗口
UINT nHitTest = CDialog::OnNcHitTest(point);
return (nHitTest == HTCLIENT)?HTCAPTION:nHitTest;
}
上面是我程序的部分代码,由于原程序太大,传不上去,想看的我直接发邮箱吧!哈哈!