ETNoticeWnd.cpp
2.55 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
// 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_sText(_T(""))
{
}
CETNoticeWnd::~CETNoticeWnd()
{
}
void CETNoticeWnd::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT_NOTICE, m_editNotice);
DDX_Control(pDX, IDC_EDIT_NOTICE_MARK, m_editMark);
}
BEGIN_MESSAGE_MAP(CETNoticeWnd, CDialogEx)
ON_WM_HSCROLL()
ON_WM_SIZE()
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();
}
}
void CETNoticeWnd::CloseNoticeWnd()
{
m_editNotice.SetWindowText(_T(""));
}
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(100, _T("微软雅黑"));
m_editNotice.SetTextFont(&m_fontText);
m_fontMark.CreateFont(100, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_BOLD, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
NULL); // lpszFac
m_editMark.SetFont(&m_fontMark);
m_editMark.SetWindowText(L"!");
m_editNotice.EnableWindow(FALSE);
m_editMark.EnableWindow(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
void CETNoticeWnd::ReSizeEdit()
{
CPaintDC dc(this);
dc.SelectObject(m_fontText);
CSize szText = dc.GetTextExtent(m_sText);
CRect rtClient;
GetClientRect(&rtClient);
m_editNotice.MoveWindow(rtClient.right - szText.cx, rtClient.Height() / 2 - szText.cy / 2 - 1, szText.cx, szText.cy);
const int kMarkWidth = 10;
m_editMark.MoveWindow(rtClient.right - szText.cx - kMarkWidth - 1, rtClient.Height() / 2 - szText.cy / 2 - 1, kMarkWidth, szText.cy);
}
void CETNoticeWnd::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
UpdateWindow();
}