// Copyright (C) Recursion Company. All rights reserved.
#include "stdafx.h"
#include "vol_user_app_info.h"
BEGIN_MESSAGE_MAP (CVWnd_LabelFC, CWnd)
//{{AFX_MSG_MAP(CVWnd_LabelFC)
ON_WM_PAINT ()
ON_WM_SETFONT ()
ON_MESSAGE (MWM_LABEL_MESSAGE, OnLabelMessage)
ON_WM_GETDLGCODE ()
//}}AFX_MSG_MAP
END_MESSAGE_MAP ()
void CVWnd_LabelFC::OnConstruct ()
{
m_clrText = CLR_DEFAULT;
m_clrBack = CLR_DEFAULT;
m_enHorzAlignMode = VHAM_LEFT;
m_enVertAlignMode = VVAM_VCENTER;
m_blpMutiLines = FALSE;
m_enBackPicPaintMode = VPPM_LEFT_TOP;
m_bDrawBackGround = FALSE;
}
BOOL CVWnd_LabelFC::CreateControl (CVolNativeWndCreateParam* pCreateParam)
{
pCreateParam->m_dwStyle &= ~WS_TABSTOP;
if (m_bDrawBackGround == FALSE)
{
pCreateParam->m_dwExStyle |= WS_EX_TRANSPARENT;
}
return CWnd::CreateEx (pCreateParam->m_dwExStyle, VolRegisterWndClass (_T ("VolLabel")),
pCreateParam->m_szCaption, pCreateParam->m_dwStyle,
pCreateParam->m_nLeft, pCreateParam->m_nTop, pCreateParam->m_nWidth, pCreateParam->m_nHeight,
pCreateParam->m_pParentWnd->GetSafeHwnd (), (HMENU)pCreateParam->m_nID);
}
void CVWnd_LabelFC::TakeOverBackBitmap (HBITMAP hBitmap)
{
m_bmpBack.DeleteObject ();
m_bmpBack.Attach (hBitmap);
if (m_hWnd != NULL)
Invalidate (FALSE);
}
UINT CVWnd_LabelFC::OnGetDlgCode ()
{
return DLGC_STATIC;
}
void CVWnd_LabelFC::OnSetFont (CFont* pFont, BOOL bRedraw)
{
LOGFONT infFont;
if (pFont != NULL && pFont->GetLogFont (&infFont))
{
m_fntDraw.DeleteObject ();
m_fntDraw.CreateFontIndirect (&infFont);
if (bRedraw)
Invalidate (FALSE);
}
}
void CVWnd_LabelFC::OnPaint ()
{
CPaintDC dcPaint (this);
CRect rtClipBox;
dcPaint.GetClipBox (&rtClipBox);
if (rtClipBox.IsRectEmpty ())
return;
CRect rtClient;
GetClientRect (&rtClient);
CRgn rgnPaint;
rtClipBox &= rtClient;
rgnPaint.CreateRectRgn(rtClipBox.left, rtClipBox.top, rtClipBox.right, rtClipBox.bottom);
dcPaint.SelectClipRgn(&rgnPaint);
if (m_bDrawBackGround)
{
// 绘制底图
VolDrawBitmap(m_enBackPicPaintMode, &dcPaint, m_bmpBack, rtClient, rtClipBox, &rgnPaint);
// 填充底色
if ((HRGN)rgnPaint != NULL)
dcPaint.FillRgn(&rgnPaint, &CBrush(GetRealBackColor(m_clrBack)));
}
CString str;
GetWindowText (str);
if (str.IsEmpty ())
return;
const TCHAR* szCaption = str;
if (m_fntDraw.m_hObject == NULL)
m_fntDraw.CreateStockObject (DEFAULT_GUI_FONT);
CFont* pOldFont = dcPaint.SelectObject (&m_fntDraw);
UINT uFormat = DT_NOCLIP;
if (m_enHorzAlignMode == VHAM_HCENTER)
uFormat |= DT_CENTER;
else if (m_enHorzAlignMode == VHAM_RIGHT)
uFormat |= DT_RIGHT;
else
uFormat |= DT_LEFT;
if (m_blpMutiLines)
uFormat |= DT_WORDBREAK | DT_VCENTER;
else if (m_enVertAlignMode == VVAM_VCENTER)
uFormat |= DT_VCENTER | DT_SINGLELINE;
else if (m_enVertAlignMode == VVAM_BOTTOM)
uFormat |= DT_BOTTOM | DT_SINGLELINE;
else
uFormat |= DT_TOP | DT_SINGLELINE;
dcPaint.SetBkMode (TRANSPARENT);
dcPaint.SetTextColor (GetRealTextColor (m_clrText));
dcPaint.DrawText (szCaption, &rtClient, uFormat);
dcPaint.SelectObject (pOldFont);
CWnd::OnPaint();
}
LRESULT CVWnd_LabelFC::OnLabelMessage (WPARAM wParam, LPARAM lParam)
{
if (m_pEventListener != NULL)
return (LRESULT)m_pEventListener->OnLabelMsg ((INT_P)wParam, (INT_P)lParam);
else
return 0;
}
评论0