-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStaticTypeWord.cpp
More file actions
118 lines (96 loc) · 2.64 KB
/
StaticTypeWord.cpp
File metadata and controls
118 lines (96 loc) · 2.64 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
// StaticTypeWord.cpp : 实现文件
//
#include "stdafx.h"
#include "TypeWord.h"
#include "StaticTypeWord.h"
// CStaticTypeWord
IMPLEMENT_DYNAMIC(CStaticTypeWord, CStatic)
CStaticTypeWord::CStaticTypeWord()
{
dwFlashCounts=0;
dwIndex=0;
dwPosx=dwPosy=10;
wcscpy(szCopyRight,_T("打字效果组件,\n支持中英文混合输出,\n换行使用\\n字符,\n文本结束使用\\0字符,\n CopyRight: singer\n 2009-03-05\n\0"));
}
CStaticTypeWord::~CStaticTypeWord()
{
}
void CStaticTypeWord::SetTypedWords(TCHAR *szWords)
{
wcscpy(szCopyRight,szWords);
}
void CStaticTypeWord::StartTpyeWords()
{
HBITMAP hBmp;
LOGFONT LogFont;
HFONT hFont;
ImgDC=this->GetDC();
hMemDC=CreateCompatibleDC(ImgDC->m_hDC);
hBmp=CreateCompatibleBitmap(ImgDC->m_hDC,178,157);
SelectObject(hMemDC,hBmp);
DeleteObject(hBmp);
SetTextColor(hMemDC,0x00ff00);//字体颜色选用绿色
SetBkMode(hMemDC,TRANSPARENT);
memset(&LogFont,0,sizeof(LogFont));
LogFont.lfHeight=12;
LogFont.lfCharSet=1;
wcscpy(LogFont.lfFaceName,_T("宋体"));
hFont=CreateFontIndirect(&LogFont); //创建逻辑字体
SelectObject(hMemDC,hFont); //选金内存设备描述表,准备使用
GetTextExtentPoint32(hMemDC,szCopyRight,1,&TextSize);//获取字体宽高
::SetTimer(this->m_hWnd,0x200,100,NULL);
}
// CTypeWordDlg 消息处理程序
void CStaticTypeWord::OnTimer(UINT_PTR nIDEvent)
{
if (dwFlashCounts==0)//不需要闪烁
{
PatBlt(hMemDC,dwPosx,dwPosy,TextSize.cx,TextSize.cy,BLACKNESS);//擦除上次的下划线
TextOut(hMemDC,dwPosx,dwPosy,&szCopyRight[dwIndex],1);//每次只打出一个字符
if (szCopyRight[dwIndex+1]=='\n')//需要换行
{
bIsStrOver=(szCopyRight[dwIndex+2]==0);//是否到达串尾,重新开始
//到达本行末尾时,锁定一下,实现"闪标效果"
bIsFlashing=TRUE;
dwFlashCounts=5;
}
else
TextOut(hMemDC,dwPosx+TextSize.cx,dwPosy,_T("_"),1);//下一个字符处打印一个'_'
if (szCopyRight[dwIndex]&0xff00)//汉字
dwPosx+=TextSize.cx;
else//英文字符,数字等
dwPosx+=TextSize.cx/2;
dwIndex++;
}
else//需要闪烁
{
if (bIsFlashing)
TextOut(hMemDC,dwPosx,dwPosy,_T("_"),1);//画下划线
else
PatBlt(hMemDC,dwPosx,dwPosy,TextSize.cx,TextSize.cy,BLACKNESS);//擦除下划线
bIsFlashing=!bIsFlashing;
if (--dwFlashCounts==0)
{
if (bIsStrOver)//信息已经显示完毕
{
dwPosy=TextSize.cy;
bIsStrOver=FALSE;
PatBlt(hMemDC,0,0,178,157,BLACKNESS);
dwIndex=0;
dwPosx=10;
}
else
{
PatBlt(hMemDC,dwPosx,dwPosy,TextSize.cx,TextSize.cy,BLACKNESS);//擦除下划线
bIsFlashing=FALSE;
dwPosy+=TextSize.cy+TextSize.cy;
dwPosx=10-TextSize.cx;
}
}
}
BitBlt(ImgDC->m_hDC,0,0,178,157,hMemDC,0,0,SRCCOPY);
}
BEGIN_MESSAGE_MAP(CStaticTypeWord, CStatic)
ON_WM_TIMER()
END_MESSAGE_MAP()
// CStaticTypeWord 消息处理程序