xref: /MusicPlayer2/MusicPlayer2/LyricsWindow.cpp (revision f6e57922066e258d96270dbad8a21f4d0d0d85e3)
1 // LyricsWindow.cpp : 实现文件
2 //
3 
4 #include "stdafx.h"
5 #include "LyricsWindow.h"
6 
7 // CLyricsWindow
8 
9 const Gdiplus::REAL TRANSLATE_FONT_SIZE_FACTOR = 0.88f;		//歌词翻译文本大小占歌词文本大小的比例
10 
11 IMPLEMENT_DYNAMIC(CLyricsWindow, CWnd)
12 
13 CLyricsWindow::CLyricsWindow()
14 {
15 	HDC hDC=::GetDC(NULL);
16 	m_hCacheDC=::CreateCompatibleDC(hDC);
17 	::ReleaseDC(NULL,hDC);
18 	//---------------------------------
19 	m_nHighlight=NULL ; //高亮歌词的百分比 0--100
20 	m_TextGradientMode=LyricsGradientMode_Two ; //普通歌词渐变模式
21 	m_pTextPen=NULL ; //普通歌词边框画笔
22 	m_HighlightGradientMode=LyricsGradientMode_Two ; //高亮歌词渐变模式
23 	m_pHighlightPen=NULL ; //高亮歌词边框画笔
24 	m_pShadowBrush=NULL ; //阴影画刷,GDIPlus画刷
25 	m_nShadowOffset=1 ; //阴影偏移
26 	m_pFont=NULL ; //GDIPlus字体
27 	m_FontStyle=NULL ;
28 	m_FontSize=NULL ;
29 	m_pTextFormat=NULL;
30 	//---------------------------------
31 	m_pFontFamily=new Gdiplus::FontFamily();
32 	m_pTextFormat=new Gdiplus::StringFormat();
33 	m_pTextFormat->SetFormatFlags(Gdiplus::StringFormatFlagsNoWrap);//不换行
34 	m_pTextFormat->SetAlignment(Gdiplus::StringAlignmentCenter); //置水平对齐方式
35 	m_pTextFormat->SetLineAlignment(Gdiplus::StringAlignmentNear); //置垂直对齐方式
36 	//---------------------------------
37 	//SetLyricsFont(L"微软雅黑", 40, Gdiplus::FontStyle::FontStyleRegular);
38 	//SetLyricsColor(Gdiplus::Color::Red,Gdiplus::Color(255,172,0),LyricsGradientMode_Three);
39 	//SetLyricsBorder(Gdiplus::Color::Black,1);
40 	SetLyricsShadow(Gdiplus::Color(150,0,0,0),1);
41 	//SetHighlightColor(Gdiplus::Color(255,100,26),Gdiplus::Color(255,255,0),LyricsGradientMode_Three);
42 	//SetHighlightBorder(Gdiplus::Color::Black,1);
43 
44 }
45 
46 CLyricsWindow::~CLyricsWindow()
47 {
48 	if(m_pTextPen){
49 		delete m_pTextPen;
50 		m_pTextPen=NULL;
51 	}
52 	if(m_pHighlightPen){
53 		delete m_pHighlightPen;
54 		m_pHighlightPen=NULL;
55 	}
56 	if(m_pShadowBrush){
57 		delete m_pShadowBrush;
58 		m_pShadowBrush=NULL;
59 	}
60 	if(m_pFontFamily){
61 		delete m_pFontFamily;
62 		m_pFontFamily=NULL;
63 	}
64 	if(m_pTextFormat){
65 		delete m_pTextFormat;
66 		m_pTextFormat=NULL;
67 	}
68 	if(m_pFont){
69 		delete m_pFont;
70 		m_pFont=NULL;
71 	}
72 }
73 
74 
75 BEGIN_MESSAGE_MAP(CLyricsWindow, CWnd)
76 	ON_WM_LBUTTONDOWN()
77 END_MESSAGE_MAP()
78 
79 
80 
81 BOOL CLyricsWindow::Create(int nHeight)
82 {
83 	return CLyricsWindow::Create(_T("CometLyricsWindow"), -1, nHeight);
84 }
85 BOOL CLyricsWindow::Create(LPCTSTR lpszClassName)
86 {
87 	return CLyricsWindow::Create(lpszClassName,-1,-1);
88 }
89 BOOL CLyricsWindow::Create(LPCTSTR lpszClassName,int nWidth,int nHeight)
90 {
91 	if(!RegisterWndClass(lpszClassName))
92 	{
93 		TRACE("Class Registration Failedn");
94 	}
95 
96 	//--------------------------------------------
97 	//取出桌面工作区域
98 	RECT rcWork;
99 	SystemParametersInfo (SPI_GETWORKAREA,NULL,&rcWork,NULL);
100 	int nWorkWidth=rcWork.right-rcWork.left;
101 	int nWorkHeight=rcWork.bottom-rcWork.top;
102 	//未传递宽度、高度参数时设置个默认值
103 	if(nWidth<0)nWidth=nWorkWidth*2/3;      //默认宽度为桌面宽度的2/3
104 	if(nHeight<0)nHeight=150;
105 	//设置左边、顶边位置,让窗口在屏幕下方
106 	int x=rcWork.left+( (nWorkWidth-nWidth)/2 );
107 	int y=rcWork.bottom-nHeight;
108 	//--------------------------------------------
109 	DWORD dwStyle=WS_POPUP|WS_VISIBLE|WS_THICKFRAME;
110 	DWORD dwExStyle=WS_EX_TOOLWINDOW|WS_EX_TOPMOST|WS_EX_LAYERED;
111     BOOL rtn = CWnd::CreateEx(dwExStyle, lpszClassName, NULL, dwStyle, x, y, nWidth, nHeight, NULL, NULL);
112 
113     return rtn;
114 }
115 BOOL CLyricsWindow::RegisterWndClass(LPCTSTR lpszClassName)
116 {
117 	HINSTANCE hInstance=AfxGetInstanceHandle();
118 	WNDCLASSEX wndcls;
119 	memset(&wndcls,0,sizeof(WNDCLASSEX));
120 	wndcls.cbSize=sizeof(WNDCLASSEX);
121 	if(GetClassInfoEx(hInstance,lpszClassName,&wndcls))
122 	{
123 		return TRUE;
124 	}
125 	if(GetClassInfoEx(NULL,lpszClassName,&wndcls))
126 	{
127 		return TRUE;
128 	}
129 
130 	wndcls.style=CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;
131 	wndcls.lpfnWndProc=::DefWindowProc;
132 	wndcls.hInstance=hInstance;
133 	wndcls.hIcon=NULL;
134 	wndcls.hCursor=::LoadCursor(NULL,IDC_ARROW);
135 	wndcls.hbrBackground=(HBRUSH)(COLOR_BTNFACE+1);
136 	wndcls.lpszMenuName=NULL;
137 	wndcls.lpszClassName=lpszClassName;
138 	if(!RegisterClassEx(&wndcls))
139 	{
140 		return FALSE;
141 	}
142 	return TRUE;
143 }
144 
145 
146 //更新歌词(歌词文本,高亮进度百分比)
147 void CLyricsWindow::UpdateLyrics(LPCTSTR lpszLyrics,int nHighlight)
148 {
149     m_lpszLyrics = lpszLyrics;
150     UpdateLyrics(nHighlight);
151 }
152 //更新高亮进度(高亮进度百分比)
153 void CLyricsWindow::UpdateLyrics(int nHighlight)
154 {
155 	m_nHighlight=nHighlight;
156 	if(m_nHighlight<0)
157 		m_nHighlight=0;
158 	if(m_nHighlight>1000)
159 		m_nHighlight=1000;
160 	Draw();
161 }
162 
163 void CLyricsWindow::UpdateLyricTranslate(LPCTSTR lpszLyricTranslate)
164 {
165 	m_strTranslate = lpszLyricTranslate;
166 }
167 
168 //重画歌词窗口
169 void CLyricsWindow::Draw()
170 {
171 	//CRect rcWindow;
172 	GetWindowRect(m_rcWindow);
173 	m_nWidth= m_rcWindow.Width();
174 	m_nHeight= m_rcWindow.Height();
175     CRect rcClient;
176     GetClientRect(rcClient);
177     m_frameSize.cx = (m_rcWindow.Width() - rcClient.Width()) / 2;
178     m_frameSize.cy = (m_rcWindow.Height() - rcClient.Height()) / 2;
179 
180 	//----------------------------------
181 	BITMAPINFO bitmapinfo;
182 	bitmapinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
183 	bitmapinfo.bmiHeader.biBitCount = 32;
184 	bitmapinfo.bmiHeader.biHeight = m_nHeight;
185 	bitmapinfo.bmiHeader.biWidth = m_nWidth;
186 	bitmapinfo.bmiHeader.biPlanes = 1;
187 	bitmapinfo.bmiHeader.biCompression=BI_RGB;
188 	bitmapinfo.bmiHeader.biXPelsPerMeter=0;
189 	bitmapinfo.bmiHeader.biYPelsPerMeter=0;
190 	bitmapinfo.bmiHeader.biClrUsed=0;
191 	bitmapinfo.bmiHeader.biClrImportant=0;
192 	bitmapinfo.bmiHeader.biSizeImage = bitmapinfo.bmiHeader.biWidth * bitmapinfo.bmiHeader.biHeight * bitmapinfo.bmiHeader.biBitCount / 8;
193 	HBITMAP hBitmap=CreateDIBSection (m_hCacheDC,&bitmapinfo, 0,NULL, 0, 0);
194 	HBITMAP hOldBitmap = (HBITMAP)SelectObject (m_hCacheDC,hBitmap);
195 	//----------------------------------
196 	Gdiplus::Graphics* pGraphics=new Gdiplus::Graphics(m_hCacheDC);
197 	pGraphics->SetSmoothingMode (Gdiplus::SmoothingModeAntiAlias);
198 	pGraphics->SetTextRenderingHint (Gdiplus::TextRenderingHintAntiAlias);
199 
200     PreDrawLyric(pGraphics);
201     bool bDrawTranslate = m_bShowTranslate && !m_strTranslate.IsEmpty();
202     if (m_bDoubleLine && !m_strNextLyric.IsEmpty() && !bDrawTranslate)
203         DrawLyricsDoubleLine(pGraphics);
204     else
205         DrawLyrics(pGraphics);
206     AfterDrawLyric(pGraphics);
207 
208 	delete pGraphics;
209 	//----------------------------------
210 	//设置透明窗口
211 	CPoint DestPt(0,0);
212 	CSize psize(m_nWidth,m_nHeight);
213 	BLENDFUNCTION blendFunc32bpp;
214 	blendFunc32bpp.AlphaFormat = AC_SRC_ALPHA;
215 	blendFunc32bpp.BlendFlags = 0;
216 	blendFunc32bpp.BlendOp = AC_SRC_OVER;
217 	blendFunc32bpp.SourceConstantAlpha = m_alpha;
218 	HDC hDC=::GetDC(m_hWnd);
219 	::UpdateLayeredWindow(m_hWnd,hDC,NULL,&psize,m_hCacheDC,&DestPt,0,&blendFunc32bpp,ULW_ALPHA);
220 	//----------------------------------
221 	//释放资源
222 	::SelectObject (m_hCacheDC,hOldBitmap);
223 	::DeleteObject(hBitmap);
224 	::ReleaseDC(m_hWnd,hDC);
225 }
226 
227 void CLyricsWindow::DrawLyricText(Gdiplus::Graphics* pGraphics, LPCTSTR strText, Gdiplus::RectF rect, bool bDrawHighlight, bool bDrawTranslate)
228 {
229 	Gdiplus::REAL fontSize = bDrawTranslate ? m_FontSize * TRANSLATE_FONT_SIZE_FACTOR : m_FontSize;
230 	if (fontSize < 1)
231 		fontSize = m_FontSize;
232 
233     Gdiplus::REAL textWidth = rect.Width;
234     Gdiplus::REAL highlighWidth = rect.Width * m_nHighlight / 1000;
235 
236     if (!bDrawHighlight && !bDrawTranslate)
237     {
238         if (rect.X < 0)
239             rect.X = 0;
240     }
241     else
242     {
243         //如果文本宽度大于控件宽度,就要根据分割的位置滚动文本
244         if (textWidth > m_nWidth)
245         {
246             //如果分割的位置(歌词进度)剩下的宽度已经小于控件宽度的一半,此时使文本右侧和控件右侧对齐
247             if (textWidth - highlighWidth < m_nWidth / 2)
248             {
249                 rect.X = m_nWidth - textWidth;
250             }
251             //分割位置剩下的宽度还没有到小于控件宽度的一半,但是分割位置的宽度已经大于控件宽度的一半时,需要移动文本使分割位置正好在控件的中间
252             else if (highlighWidth > m_nWidth / 2)
253             {
254                 rect.X = m_nWidth / 2 - highlighWidth;
255             }
256             //分割位置还不到控件宽度的一半时,使文本左侧和控件左侧对齐
257             else
258             {
259                 rect.X = 0;
260             }
261         }
262     }
263 
264 	//-----------------------------------------------------------
265 	//画出阴影
266 	if (m_pShadowBrush) {
267 		Gdiplus::RectF layoutRect(0, 0, 0, 0);
268 		layoutRect = rect;
269 		layoutRect.X = layoutRect.X + m_nShadowOffset;
270 		layoutRect.Y = layoutRect.Y + m_nShadowOffset;
271 		Gdiplus::GraphicsPath* pShadowPath = new Gdiplus::GraphicsPath(Gdiplus::FillModeAlternate);//创建路径
272 		pShadowPath->AddString(strText, -1, m_pFontFamily, m_FontStyle, fontSize, layoutRect, m_pTextFormat); //把文字加入路径
273 		pGraphics->FillPath(m_pShadowBrush, pShadowPath);//填充路径
274 		delete pShadowPath; //销毁路径
275 	}
276 
277 	//-----------------------------------------------------------
278 	//画出歌词
279 	Gdiplus::GraphicsPath* pStringPath = new Gdiplus::GraphicsPath(Gdiplus::FillModeAlternate);//创建路径
280 	pStringPath->AddString(strText, -1, m_pFontFamily, m_FontStyle, fontSize, rect, m_pTextFormat); //把文字加入路径
281 	if (m_pTextPen) {
282 		pGraphics->DrawPath(m_pTextPen, pStringPath);//画路径,文字边框
283 	}
284 	Gdiplus::Brush* pBrush = CreateGradientBrush(m_TextGradientMode, m_TextColor1, m_TextColor2, rect);
285 	pGraphics->FillPath(pBrush, pStringPath);//填充路径
286 	delete pBrush;//销毁画刷
287 	if(bDrawHighlight)
288 		DrawHighlightLyrics(pGraphics, pStringPath, rect);
289 	delete pStringPath; //销毁路径
290 }
291 
292 //绘制歌词
293 void CLyricsWindow::DrawLyrics(Gdiplus::Graphics* pGraphics)
294 {
295     int lyricHeight = m_nHeight - m_toobar_height;
296 	//先取出文字宽度和高度
297 	Gdiplus::RectF layoutRect(0,0,0,0);
298 	Gdiplus::RectF boundingBox;
299 	pGraphics->MeasureString (m_lpszLyrics, -1, m_pFont,layoutRect, m_pTextFormat,&boundingBox, 0, 0);
300     boundingBox.Width += 1;     //测量到的文本宽度加1,以防止出现使用某些字体时,最后一个字符无法显示的问题
301 	//计算歌词画出的位置
302 	Gdiplus::RectF dstRect;		//文字的矩形
303 	Gdiplus::RectF transRect;	//翻译文本的矩形
304     bool bDrawTranslate = m_bShowTranslate && !m_strTranslate.IsEmpty();
305 	if(!bDrawTranslate)
306 	{
307         switch (m_alignment)
308         {
309         case Alignment::LEFT:
310             dstRect = Gdiplus::RectF(0, m_toobar_height + (lyricHeight - boundingBox.Height) / 2, boundingBox.Width, boundingBox.Height);
311             break;
312         case Alignment::RIGHT:
313             dstRect = Gdiplus::RectF(m_nWidth - boundingBox.Width, m_toobar_height + (lyricHeight - boundingBox.Height) / 2, boundingBox.Width, boundingBox.Height);
314             break;
315         //居中
316         default:
317             dstRect = Gdiplus::RectF((m_nWidth - boundingBox.Width) / 2, m_toobar_height + (lyricHeight - boundingBox.Height) / 2, boundingBox.Width, boundingBox.Height);
318         }
319     }
320 	else
321 	{
322 		Gdiplus::RectF transBoundingBox;
323 		pGraphics->MeasureString(m_strTranslate, -1, m_pFont, layoutRect, m_pTextFormat, &transBoundingBox, 0, 0);
324         transBoundingBox.Width += 1;     //测量到的文本宽度加1,以防止出现使用某些字体时,最后一个字符无法显示的问题
325         Gdiplus::REAL translateHeight = transBoundingBox.Height * TRANSLATE_FONT_SIZE_FACTOR;
326 		Gdiplus::REAL translateWidth = transBoundingBox.Width * TRANSLATE_FONT_SIZE_FACTOR;
327 		Gdiplus::REAL gapHeight = boundingBox.Height * 0.2f;	//歌词和翻译之间的间隙
328 		Gdiplus::REAL height = boundingBox.Height + gapHeight + translateHeight;
329         switch (m_alignment)
330         {
331         case Alignment::LEFT:
332             dstRect = Gdiplus::RectF(0, m_toobar_height + (lyricHeight - height) / 2, boundingBox.Width, boundingBox.Height);
333             transRect = Gdiplus::RectF(0, dstRect.GetBottom() + gapHeight, translateWidth, translateHeight);
334             break;
335         case Alignment::RIGHT:
336             dstRect = Gdiplus::RectF((m_nWidth - boundingBox.Width), m_toobar_height + (lyricHeight - height) / 2, boundingBox.Width, boundingBox.Height);
337             transRect = Gdiplus::RectF((m_nWidth - translateWidth), dstRect.GetBottom() + gapHeight, translateWidth, translateHeight);
338             break;
339         default:
340 		    dstRect = Gdiplus::RectF((m_nWidth - boundingBox.Width) / 2, m_toobar_height + (lyricHeight - height) / 2, boundingBox.Width, boundingBox.Height);
341 		    transRect = Gdiplus::RectF((m_nWidth - translateWidth) / 2, dstRect.GetBottom() + gapHeight, translateWidth, translateHeight);
342             break;
343         }
344 	}
345 
346 	DrawLyricText(pGraphics, m_lpszLyrics, dstRect, m_lyric_karaoke_disp);
347 	if (bDrawTranslate)
348 		DrawLyricText(pGraphics, m_strTranslate, transRect, false, true);
349 }
350 
351 void CLyricsWindow::DrawLyricsDoubleLine(Gdiplus::Graphics* pGraphics)
352 {
353     int lyricHeight = m_nHeight - m_toobar_height;
354     static bool bSwap = false;
355     if (m_lyricChangeFlag)      //如果歌词发生了改变,则交换当前歌词和下一句歌词的位置
356         bSwap = !bSwap;
357     //先取出文字宽度和高度
358     Gdiplus::RectF layoutRect(0, 0, 0, 0);
359     Gdiplus::RectF boundingBox;
360     pGraphics->MeasureString(m_lpszLyrics, -1, m_pFont, layoutRect, m_pTextFormat, &boundingBox, 0, 0);
361     boundingBox.Width += 1;     //测量到的文本宽度加1,以防止出现使用某些字体时,最后一个字符无法显示的问题
362     Gdiplus::RectF nextBoundingBox;
363     pGraphics->MeasureString(m_strNextLyric, -1, m_pFont, layoutRect, m_pTextFormat, &nextBoundingBox, 0, 0);
364     nextBoundingBox.Width += 1; //测量到的文本宽度加1,以防止出现使用某些字体时,最后一个字符无法显示的问题
365     //计算歌词画出的位置
366     Gdiplus::RectF dstRect;		//文字的矩形
367     Gdiplus::RectF nextRect;	//下一句文本的矩形
368 
369     dstRect = Gdiplus::RectF(0, m_toobar_height + (lyricHeight / 2 - boundingBox.Height) / 2, boundingBox.Width, boundingBox.Height);
370     nextRect = Gdiplus::RectF(m_nWidth - nextBoundingBox.Width, dstRect.Y + lyricHeight / 2, nextBoundingBox.Width, nextBoundingBox.Height);
371 
372     if (bSwap)
373     {
374         std::swap(dstRect.Y, nextRect.Y);
375         nextRect.X = 0;
376         dstRect.X = m_nWidth - dstRect.Width;
377     }
378 
379     DrawLyricText(pGraphics, m_lpszLyrics, dstRect, true);
380     DrawLyricText(pGraphics, m_strNextLyric, nextRect, false);
381 }
382 
383 //绘制高亮歌词
384 void CLyricsWindow::DrawHighlightLyrics(Gdiplus::Graphics* pGraphics,Gdiplus::GraphicsPath* pPath, Gdiplus::RectF& dstRect)
385 {
386 	if(m_nHighlight<=0)return;
387 	Gdiplus::Region* pRegion=NULL;
388 	if(m_nHighlight<1000){
389 		Gdiplus::RectF CliptRect(dstRect);
390 		CliptRect.Width=CliptRect.Width * m_nHighlight / 1000;
391 		pRegion=new Gdiplus::Region(CliptRect);
392 		pGraphics->SetClip(pRegion, Gdiplus::CombineModeReplace);
393 	}
394 	//--------------------------------------------
395 	if(m_pHighlightPen){
396 		pGraphics->DrawPath (m_pHighlightPen,pPath);//画路径,文字边框
397 	}
398 	Gdiplus::Brush* pBrush = CreateGradientBrush(m_HighlightGradientMode, m_HighlightColor1,m_HighlightColor2,dstRect);
399 	pGraphics->FillPath (pBrush,pPath);//填充路径
400 	delete pBrush;//销毁画刷
401 	//--------------------------------------------
402 	if(pRegion){
403 		pGraphics->ResetClip();
404 		delete pRegion;
405 	}
406 }
407 
408 //创建渐变画刷
409 Gdiplus::Brush* CLyricsWindow::CreateGradientBrush(LyricsGradientMode TextGradientMode,Gdiplus::Color& Color1,Gdiplus::Color& Color2, Gdiplus::RectF& dstRect)
410 {
411 	Gdiplus::PointF pt1;
412 	Gdiplus::PointF pt2;
413 	Gdiplus::Brush* pBrush=NULL;
414 	switch (TextGradientMode)
415 	{
416 	case LyricsGradientMode_Two://两色渐变
417 		{
418 			Gdiplus::PointF point1(dstRect.X,dstRect.Y);
419 			Gdiplus::PointF point2(dstRect.X,dstRect.Y+dstRect.Height);
420 			pBrush=new Gdiplus::LinearGradientBrush(point1,point2,Color1,Color2);
421 			((Gdiplus::LinearGradientBrush*)pBrush)->SetWrapMode(Gdiplus::WrapModeTileFlipXY);
422 			break;
423 		}
424 
425 	case LyricsGradientMode_Three://三色渐变
426 		{
427 			Gdiplus::PointF point1(dstRect.X,dstRect.Y);
428 			Gdiplus::PointF point2(dstRect.X,dstRect.Y+dstRect.Height/2);
429 			pBrush=new Gdiplus::LinearGradientBrush(point1,point2,Color1,Color2);
430 			((Gdiplus::LinearGradientBrush*)pBrush)->SetWrapMode(Gdiplus::WrapModeTileFlipXY);
431 			break;
432 		}
433 
434 	default://无渐变
435 		{
436 			pBrush=new Gdiplus::SolidBrush(Color1);
437 			break;
438 		}
439 	}
440 	return pBrush;
441 }
442 
443 //设置歌词颜色
444 void CLyricsWindow::SetLyricsColor(Gdiplus::Color TextColor1)
445 {
446 	CLyricsWindow::SetLyricsColor(TextColor1,Gdiplus::Color::Black,LyricsGradientMode_None);
447 }
448 void CLyricsWindow::SetLyricsColor(Gdiplus::Color TextColor1,Gdiplus::Color TextColor2,LyricsGradientMode TextGradientMode)
449 {
450 	m_TextColor1=TextColor1;
451 	m_TextColor2=TextColor2;
452 	m_TextGradientMode=TextGradientMode;
453 
454 }
455 //设置歌词边框
456 void CLyricsWindow::SetLyricsBorder(Gdiplus::Color BorderColor, Gdiplus::REAL BorderWidth)
457 {
458 	if(m_pTextPen){
459 		delete m_pTextPen;
460 		m_pTextPen=NULL;
461 	}
462 	if(BorderColor.GetA()>0 && BorderWidth>0)
463 		m_pTextPen=new Gdiplus::Pen(BorderColor,BorderWidth);
464 }
465 //设置高亮歌词颜色
466 void CLyricsWindow::SetHighlightColor(Gdiplus::Color TextColor1)
467 {
468 	CLyricsWindow::SetHighlightColor(TextColor1,Gdiplus::Color::Black,LyricsGradientMode_None);
469 }
470 void CLyricsWindow::SetHighlightColor(Gdiplus::Color TextColor1,Gdiplus::Color TextColor2,LyricsGradientMode TextGradientMode)
471 {
472 	m_HighlightColor1=TextColor1;
473 	m_HighlightColor2=TextColor2;
474 	m_HighlightGradientMode=TextGradientMode;
475 
476 }
477 //设置高亮歌词边框
478 void CLyricsWindow::SetHighlightBorder(Gdiplus::Color BorderColor, Gdiplus::REAL BorderWidth)
479 {
480 	if(m_pHighlightPen){
481 		delete m_pHighlightPen;
482 		m_pHighlightPen=NULL;
483 	}
484 	if(BorderColor.GetA()>0 && BorderWidth>0)
485 		m_pHighlightPen=new Gdiplus::Pen(BorderColor,BorderWidth);
486 }
487 //设置歌词阴影
488 void CLyricsWindow::SetLyricsShadow(Gdiplus::Color ShadowColor,int nShadowOffset)
489 {
490 	if(m_pShadowBrush){
491 		delete m_pShadowBrush;
492 		m_pShadowBrush=NULL;
493 	}
494 	if(ShadowColor.GetA()>0 && nShadowOffset>0){
495 		m_nShadowOffset=nShadowOffset;
496 		m_pShadowBrush=new Gdiplus::SolidBrush(ShadowColor);
497 	}else{
498 		m_nShadowOffset=0;
499 	}
500 }
501 //设置歌词字体
502 void CLyricsWindow::SetLyricsFont(const WCHAR * familyName, Gdiplus::REAL emSize,INT style, Gdiplus::Unit unit)
503 {
504 	if(m_pFont){
505 		delete m_pFont;
506 		m_pFont=NULL;
507 	}
508 	Gdiplus::FontFamily family(familyName,NULL);
509 	Gdiplus::Status lastResult = family.GetLastStatus();
510 	if (lastResult != Gdiplus::Ok)
511 	{
512 		HFONT hFont=(HFONT)GetStockObject(DEFAULT_GUI_FONT);
513 		LOGFONTW lf;
514 		ZeroMemory(&lf,sizeof(LOGFONTW));
515 		GetObjectW(hFont,sizeof(LOGFONTW),&lf);
516 		Gdiplus::FontFamily family2(lf.lfFaceName,NULL);
517 		m_pFont=new Gdiplus::Font(&family2,emSize,style,unit);
518 	}else{
519 		m_pFont=new Gdiplus::Font(&family,emSize,style,unit);
520 	}
521 	 //----------------
522 	//保存一些字体属性,加入路径时要用到
523 	m_pFont->GetFamily (m_pFontFamily);
524 	m_FontSize=m_pFont->GetSize ();
525 	m_FontStyle=m_pFont->GetStyle ();
526 
527 
528 
529 }
530 
531 void CLyricsWindow::SetLyricDoubleLine(bool doubleLine)
532 {
533 	m_bDoubleLine = doubleLine;
534 }
535 
536 void CLyricsWindow::SetNextLyric(LPCTSTR lpszNextLyric)
537 {
538 	m_strNextLyric = lpszNextLyric;
539 }
540 
541 void CLyricsWindow::SetShowTranslate(bool showTranslate)
542 {
543     m_bShowTranslate = showTranslate;
544 }
545 
546 void CLyricsWindow::SetAlpha(int alpha)
547 {
548     m_alpha = alpha;
549 }
550 
551 const CString& CLyricsWindow::GetLyricStr() const
552 {
553     return m_lpszLyrics;
554 }
555 
556 void CLyricsWindow::SetLyricChangeFlag(bool bFlag)
557 {
558     m_lyricChangeFlag = bFlag;
559 }
560 
561 void CLyricsWindow::SetAlignment(Alignment alignment)
562 {
563 	m_alignment = alignment;
564 }
565 
566 void CLyricsWindow::SetLyricKaraokeDisplay(bool karaoke_disp)
567 {
568     m_lyric_karaoke_disp = karaoke_disp;
569 }
570 
571 void CLyricsWindow::OnLButtonDown(UINT nFlags, CPoint point)
572 {
573 
574 	CWnd::OnLButtonDown(nFlags, point);
575 	//ReleaseCapture();
576 	//SendMessage(WM_NCLBUTTONDOWN,HTCAPTION,NULL);
577 }
578