由于需求,需要写个类似QQ迷你资讯首页的东西,就花了一点时间写了写,软件效果截图如下:
程序的主要核心代码如下:
程序的全部源代码下载地址:http://download.csdn.net/download/jczmdeveloper/6953161
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
void
CMiniNewsDlg::DrawDialog()
{ m_nFrameCY = GetSystemMetrics(SM_CYFIXEDFRAME); //获取对话框边框的高度
m_nFrameCX = GetSystemMetrics(SM_CXDLGFRAME); //获取对话边框的宽度
if (GetStyle()&WS_BORDER) //获取对话框是否有边框
{
m_nBorderCY = GetSystemMetrics(SM_CYBORDER) + m_nFrameCY;
m_nBorderCX = GetSystemMetrics(SM_CXBORDER) +m_nFrameCX;
}
else
{
m_nBorderCY = m_nFrameCY;
m_nBorderCX = m_nFrameCX;
}
m_nTitleBarCY = GetSystemMetrics(SM_CYCAPTION) + m_nBorderCY; //计算标题栏高度
m_nTitleBarCX =m_nBorderCX;
CRect winRect,factRect;
GetWindowRect(&winRect);
factRect.CopyRect(CRect(0,0,winRect.Width(),winRect.Height()));
CWindowDC windowsDC( this ); //获取窗口设备上下文
//获取整个MFC窗口的高度和宽度
m_nWinWidth = winRect.Width();
m_nWinHeight = winRect.Height();
//绘制对话框标题栏位图
DisplayBmp(0,0,m_nWinWidth,m_nTitleBarCY,IDB_LEFTTITLE);
//绘制对话框标题栏左端的logo图标
DisplayBmp(3,0,26,m_nTitleBarCY,IDB_APPICON);
//绘制对话框左边框位图
DisplayBmp(0,m_nTitleBarCY,m_nBorderCX,m_nWinHeight-m_nBorderCY,IDB_LEFTBAR);
//绘制对话框底边框位图
DisplayBmp(m_nBorderCX,m_nWinHeight-m_nBorderCX,m_nWinWidth-2*m_nBorderCX,m_nBorderCX,IDB_BOTTOMBAR);
//绘制对话框左边框位图
DisplayBmp(m_nWinWidth-m_nBorderCX,m_nTitleBarCY,m_nBorderCX,m_nWinHeight-m_nBorderCY,IDB_RIGHTBAR);
//给对话框绘制最小化按钮
DisplayBmp(m_nWinWidth-26*2-5,0,26,26,IDB_MINBTN1);
//给对话框绘制关闭按钮
DisplayBmp(m_nWinWidth-26-5,0,26,26,IDB_CLOSEBTN1);
DrawTitleText();
ReleaseDC(&windowsDC);
} //=====================在指定位置显示bmp位图图像 void
CMiniNewsDlg::DisplayBmp( int
x, int y, int w, int h, int nID)
{ CRect winRC;
CDC* pDC=GetWindowDC();
CDC memDC;
memDC.CreateCompatibleDC(pDC);
BITMAPINFO bmpInfo;
CBitmap bmp;
GetWindowRect(&winRC);
bmp.LoadBitmap(nID);
bmp.GetObject( sizeof (BITMAPINFO),&bmpInfo);
int
nBmpCX = bmpInfo.bmiHeader.biWidth;
int
nBmpCY = bmpInfo.bmiHeader.biHeight;
memDC.SelectObject(bmp);
pDC->StretchBlt(x,y,w,h,
&memDC,0,0,nBmpCX,nBmpCY,SRCCOPY); //在窗口中绘制位图
bmp.DeleteObject();
ReleaseDC(pDC);
} void
CMiniNewsDlg::SetTitleText(CString strTitle)
{ this ->m_strTitle = strTitle + "-小蔡电脑助手" ;
} //绘制标题栏标题文本内容 void
CMiniNewsDlg::DrawTitleText()
{ CDC* pDC= GetWindowDC();
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(255,255,255));
pDC->SetTextAlign(TA_CENTER);
CRect rect;
GetClientRect(&rect);
CSize szText = pDC->GetTextExtent(m_strTitle);
CFont* font,*fOldFont;
font = new
CFont;
font->CreateFont(12,0,0,0,FW_BOLD,FALSE,FALSE,0,ANSI_CHARSET,
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_SWISS,_T( "宋体" ));
fOldFont = pDC->SelectObject(font);
CRect winRect;
GetWindowRect(&winRect);
pDC->TextOut(winRect.Width()/2,6.5,m_strTitle);
pDC->SelectObject(fOldFont);
ReleaseDC(pDC);
} void
CMiniNewsDlg::OnNcPaint()
{ // TODO: 在此处添加消息处理程序代码
DrawDialog();
// 不为绘图消息调用 CDialog::OnNcPaint()
} void
CMiniNewsDlg::OnActivate( UINT
nState, CWnd* pWndOther, BOOL
bMinimized)
{ CDialog::OnActivate(nState, pWndOther, bMinimized);
OnNcPaint();
// TODO: 在此处添加消息处理程序代码
} void
CMiniNewsDlg::OnNcMouseMove( UINT
nHitTest, CPoint point)
{ // TODO: 在此添加消息处理程序代码和/或调用默认值
CRect minRC,moreRC,closeRC,winRC,cleanRC,toolkitRC,shoppingRC;
GetWindowRect(&winRC);
closeRC.CopyRect(CRect(m_nWinWidth-26,0,m_nWinWidth-26+26,26));
minRC.CopyRect(CRect(m_nWinWidth-26*2,0,m_nWinWidth-26*2+26,26));
point.Offset(-winRC.left,-winRC.top); //由于point为屏幕坐标,这里将其转换为窗口坐标
if (closeRC.PtInRect(point)) //鼠标在关闭按钮上时,更改按钮显示的位图
{
m_bMouseOnCloseBtn = TRUE;
m_bMouseOnMinBtn =FALSE;
m_bMouseOnMoreBtn = FALSE;
DisplayBmp(m_nWinWidth-26-5,0,26,26,IDB_CLOSEBTN2);
DisplayBmp(m_nWinWidth-26*2-5,0,26,26,IDB_MINBTN1);
}
else
if (minRC.PtInRect(point)) //鼠标在最小化按钮上时,更改按钮显示的位图
{
m_bMouseOnMinBtn =TRUE;
m_bMouseOnCloseBtn = FALSE;
DisplayBmp(m_nWinWidth-26-5,0,26,26,IDB_CLOSEBTN1);
DisplayBmp(m_nWinWidth-26*2-5,0,26,26,IDB_MINBTN2);
}
CDialog::OnNcMouseMove(nHitTest, point);
} void
CMiniNewsDlg::OnNcLButtonUp( UINT
nHitTest, CPoint point)
{ // TODO: 在此添加消息处理程序代码和/或调用默认值
if (m_bMouseOnCloseBtn)
{
this ->SendMessage(WM_CLOSE);
}
if (m_bMouseOnMinBtn)
{
this ->ShowWindow(SW_MINIMIZE);
m_bMouseOnMinBtn = FALSE;
}
CDialog::OnNcLButtonUp(nHitTest, point);
} void
CMiniNewsDlg::OnNcMouseLeave()
{ // 该功能要求使用 Windows 2000 或更高版本。
// 符号 _WIN32_WINNT 和 WINVER 必须 >= 0x0500。
// TODO: 在此添加消息处理程序代码和/或调用默认值
DisplayBmp(m_nWinWidth-26*2-5,0,26,26,IDB_MINBTN1);
DisplayBmp(m_nWinWidth-26-5,0,26,26,IDB_CLOSEBTN1);
m_bMouseOnMinBtn =FALSE;
m_bMouseOnCloseBtn = FALSE;
CDialog::OnNcMouseLeave();
} void
CMiniNewsDlg::OnNcLButtonDown( UINT
nHitTest, CPoint point)
{ // TODO: 在此添加消息处理程序代码和/或调用默认值
if (!(m_bMouseOnMinBtn||m_bMouseOnCloseBtn))
CDialog::OnNcLButtonDown(nHitTest, point);
} HBRUSH
CMiniNewsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT
nCtlColor)
{ HBRUSH
hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: 在此更改 DC 的任何属性
HBRUSH
brush=CreateSolidBrush(m_bkColor);
switch (nCtlColor)
{
case
CTLCOLOR_STATIC:
pDC->SetBkMode(TRANSPARENT);
//设置背景为透明
pDC->SetTextColor(RGB(255,255,255)); //设置字体颜色
pDC->SetBkColor(m_bkColor);
//pWnd->SetFont(cFont); //设置字体
hbr = ( HBRUSH )brush;
//创建画刷
break ;
case
CTLCOLOR_BTN:
pDC->SetBkMode(TRANSPARENT);
//设置背景为透明
pDC->SetTextColor(RGB(255,255,255)); //设置字体颜色
pDC->SetBkColor(m_bkColor);
//pWnd->SetFont(cFont); //设置字体
hbr = ( HBRUSH )brush;
//创建画刷
break ;
}
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
return
hbr;
} |
程序的全部源代码下载地址:http://download.csdn.net/download/jczmdeveloper/6953161