QQ登录

只需一步,快速开始

384上位机VC MFC编写不规则窗口日历

[ 复制链接 ]

384上位机VC MFC编写不规则窗口日历

384上位机VC MFC编写不规则窗口日历

编写不规则界面日历
功能展示
在操作系统上都有日历小挂件,可以放在桌面上方便我们查看年月日等信息,我们当前例程也实现日历小程序的编写,效果如图,程序运行就会显示日历界面,界面为不规则形状;

要点提示
不规则界面的实现主要通过两函数完成,CRgn类的CombineRgn()函数准备一个不规则形状,再通过SetWindowRgn((HRGN)rgn,TRUE);来设置窗体的区域形状;
SetWindowRgn 函数是设置了一个窗口的区域.只有被包含在这个区域内的地方才会被重绘,而不包含在区域内的其他区域系统将不会显示
int SetWindowRgn( HWND hWnd, // handle to window whose window region is to be set HRGN hRgn, // handle to region BOOL bRedraw // window redraw flag ); hWnd ,窗口的句柄。hRgn指向的区域.函数起作用后将把窗体变成这个区域的形状. bRedraw,这个参数是用于设置 当函数起作用后,窗体是不是该重绘一次. true 则重绘,false 则相反.

实现功能
1.新建基于对话框的应用程序 ,准备一背景位图,插入到工程,例程中ID为IDB_BITMAP1
2.设置主窗口资源为无边框,添加函数PreTranslateMessage()实现窗口可拖拽功能
BOOL CGkbc8Dlg:reTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_LBUTTONDOWN && pMsg->hwnd == m_hWnd)
{
CPoint point;
GetCursorPos(&point);
PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
}
return CDialog:reTranslateMessage(pMsg);
}
3.添加函数OnCtlColor()实现日历背景的填充,在OnPaint()调用自定义函数DrawCalendar();实现日历的绘制
HBRUSH CGkbc8Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
//<>
CBitmap BKGround;
BKGround.LoadBitmap(IDB_BITMAP1);
if (nCtlColor==CTLCOLOR_DLG)
{
CBrush Brush(&BKGround); //定义一个位图画刷
CRect rect;
GetClientRect(rect);
pDC->SelectObject(&Brush); //选中画刷
pDC->FillRect(rect,&Brush); //填充客户区域
return Brush;
}
else
hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
//<>
return hbr;
}
4.在主对话框头文件及源文件分别添加一结构体及一数组
struct CustomDate{
int Year; //年
int Month; //月
int Day; //日
BOOL IsRunYue; //是否闰月
};
DWORD LunarInfo[]={
0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,
0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0x095b0,0x14977,
0x04970,0x0a4b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970,
0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0x0c950,
0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0x0a950,0x0b557,
0x06ca0,0x0b550,0x15355,0x04da0,0x0a5d0,0x14573,0x052d0,0x0a9a8,0x0e950,0x06aa0,
0x0aea6,0x0ab50,0x04b60,0x0aae4,0x0a570,0x05260,0x0f263,0x0d950,0x05b57,0x056a0,
0x096d0,0x04dd5,0x04ad0,0x0a4d0,0x0d4d4,0x0d250,0x0d558,0x0b540,0x0b5a0,0x195a6,
0x095b0,0x049b0,0x0a974,0x0a4b0,0x0b27a,0x06a50,0x06d40,0x0af46,0x0ab60,0x09570,
0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0x0ab60,0x096d5,0x092e0,
0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0x0abb7,0x025d0,0x092d0,0x0cab5,
0x0a950,0x0b4a0,0x0baa4,0x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930,
0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530,
0x05aa0,0x076a3,0x096d0,0x04bd7,0x04ad0,0x0a4d0,0x1d0b6,0x0d250,0x0d520,0x0dd45,
0x0b5a0,0x056d0,0x055b2,0x049b0,0x0a577,0x0a4b0,0x0aa50,0x1b255,0x06d20,0x0ada0
};
再在主对话框头文件添加11个自定义函数及一成员变量,函数过多过长,就不贴出。
void DrawCalendar();
CString GetWeekString(int week); //获得星期字符串
CustomDate GetLunar(CustomDate date); //输入公历日期,返回农历日期
char* GetLunarString (CustomDate date); //返回农历字符串
LONG DaysFrom1900(CustomDate Date); //计算与1900年相差的天数
int YearDays(int year); //农历y年的总天数
int MonthDays(UINT year,UINT month); //传回农历 y年m月的总天数
int LeapMonth(UINT year); // 传回农历 y年闰哪个月 1-12 , 没闰传回 0
int LeapDays(int year); //传回农历 y年闰月的天数
int GetMonthDays(int year,int month); //各月天数返回
BOOL LeapYear(int year); //判断是否闰年
char m_slunar[100];//用于存储农历信息
我们来演示下功能实现的整个过程

请点击此处下载

请先注册会员后在进行下载

已注册会员,请先登录后下载

文件名称:384.上位机VC MFC编写不规则窗口日历.zip 
文件大小:186.57 KB  售价:11金币
下载权限: 不限 以上或 VIP会员   [购买捐助会员]   [充值积分]   有问题联系我

  

如果您认可,可联系功能定制!

  

如果您着急,充值会员可直接联系发您资料!

  

QQ联系我

微信扫扫联系我

  

  

您的支持是我们创作的动力!  

  

您可花点闲钱积分自助任意充值

  

成为VIP会员 全站资源任意下载永久更新!




回复

使用道具 举报

快速回复 返回列表 客服中心 搜索