ETNoticeWnd.cpp
3.09 KB
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
// ETNoticeWnd.cpp : 实现文件
//
#include "stdafx.h"
#include "ETNoticeWnd.h"
#include "afxdialogex.h"
#include "resource.h"
const int SCROLLSPEED = -2;
// CETNoticeWnd 对话框
IMPLEMENT_DYNAMIC(CETNoticeWnd, CDialogEx)
CETNoticeWnd::CETNoticeWnd(CWnd* pParent /*=NULL*/)
: CDialogEx(CETNoticeWnd::IDD, pParent),
m_iTimerID(0), m_iCurPos(0),
m_iDelayTime(0), m_iIntervalTime(0),
m_sText(_T(""))
{
}
CETNoticeWnd::~CETNoticeWnd()
{
}
void CETNoticeWnd::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
//DDX_Control(pDX, IDC_EDIT_NOTICE, m_editNotice);
}
BEGIN_MESSAGE_MAP(CETNoticeWnd, CDialogEx)
ON_WM_TIMER()
ON_WM_HSCROLL()
ON_WM_PAINT()
ON_WM_SIZE()
ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
// CETNoticeWnd 消息处理程序
void CETNoticeWnd::SetWindowText(CString sText)
{
m_editNotice.SetWindowText(sText);
if (sText.IsEmpty())
{
CloseNoticeWnd();
ShowWindow(SW_HIDE);
}
else
{
ShowWindow(SW_SHOW);
m_sText = sText;
ReSizeEdit();
if (m_iTimerID == 0)
{
m_iTimerID = 1;
SetTimer(m_iTimerID, 100, NULL);
}
}
}
void CETNoticeWnd::CloseNoticeWnd()
{
m_editNotice.SetWindowText(_T(""));
ReSetState();
if (m_iTimerID != 0)
{
KillTimer(m_iTimerID);
}
}
void CETNoticeWnd::ReSetState()
{
m_iCurPos = 0;
m_iDelayTime = 0;
}
BOOL CETNoticeWnd::OnInitDialog()
{
CDialogEx::OnInitDialog();
SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
m_editNotice.SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
ReSizeEdit();
m_fontText.CreatePointFont(120, _T("微软雅黑"));
m_editNotice.SetTextFont(&m_fontText);
m_iIntervalTime = 100; //设置计时器间隔时间,单位毫秒
m_editNotice.EnableWindow(FALSE);
m_brushBKG.CreateSolidBrush(RGB(255, 0, 0));
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
void CETNoticeWnd::ReSizeEdit()
{
ReSetState();
CPaintDC dc(this);
dc.SelectObject(m_fontText);
CSize szText = dc.GetTextExtent(m_sText);
CRect rtClient;
GetClientRect(&rtClient);
m_editNotice.MoveWindow(rtClient.left, rtClient.Height() / 2 - szText.cy / 2, szText.cx, szText.cy);
}
void CETNoticeWnd::OnTimer(UINT_PTR nIDEvent)
{
if (m_iDelayTime < 3000)
{
m_iDelayTime += m_iIntervalTime;
return;
}
CRect rtEdit;
m_editNotice.GetWindowRect(&rtEdit);
ScreenToClient(&rtEdit);
if (m_iCurPos < (0 - rtEdit.Width()))
{
CRect rtClient;
GetClientRect(&rtClient);
int iMoveDistance = rtClient.Width() + rtEdit.Width();
ScrollWindow(iMoveDistance, 0);
m_iCurPos += iMoveDistance;
}
else
{
ScrollWindow(SCROLLSPEED, 0);
m_iCurPos += SCROLLSPEED;
}
CDialogEx::OnTimer(nIDEvent);
}
void CETNoticeWnd::OnPaint()
{
CPaintDC dc(this); // device context for painting
//CRect rtClient;
//GetClientRect(&rtClient);
//dc.FillSolidRect(rtClient, RGB(255, 0, 0)); //设置为红色背景
CDialogEx::OnPaint();
}
void CETNoticeWnd::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
UpdateWindow();
}
HBRUSH CETNoticeWnd::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
return m_brushBKG;
}