| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 966 人关注过本帖
标题:[原创]桌面变形窗体
只看楼主 加入收藏
风动
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2007-6-25
收藏
 问题点数:0 回复次数:4 
[原创]桌面变形窗体

*/ --------------------------------------------------------------------------------------
*/ 出自: 编程中国 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;
}


上面是我程序的部分代码,由于原程序太大,传不上去,想看的我直接发邮箱吧!哈哈!

搜索更多相关主题的帖子: 窗体 中国 include cpp 
2007-07-20 23:27
余来
Rank: 6Rank: 6
等 级:贵宾
威 望:26
帖 子:956
专家分:18
注 册:2006-8-13
收藏
得分:0 
看了,从部分代码分析可以知道就是一个多边行窗口的制作,楼主可以近一步改进,因为每次都需要重新建立一个CRgn,因此效率上不行,可以实现定义一些CRgn,然后SetTimer,最后在OnTimer函数中 一个一个设置

2007-07-20 23:49
冰的热度
Rank: 2
等 级:禁止访问
威 望:5
帖 子:404
专家分:0
注 册:2006-12-2
收藏
得分:0 
我晚来一步,又让版主抢先了,版主说的不错,同意

科学是永恒之迷...... 我的博客http://blog..cn/u/1267727974 阅读我的blog,懂与不懂都是收获!
2007-07-21 17:46
风动
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2007-6-25
收藏
得分:0 

谢谢斑竹的提醒,哈哈!我愿意立即改正!希望斑竹多赐教!


打框架,做需求分析---敲代码的前提
2007-07-21 21:12
yorkyogurt
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-3-27
收藏
得分:0 
我觉得用MASK制作的更漂亮一些!!

2007-08-12 21:41
快速回复:[原创]桌面变形窗体
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017832 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved