📄 jwstatic.cpp
字号:
// JWStatic.cpp : implementation file
//
#include "stdafx.h"
#include "Static.h"
#include "JWStatic.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//#include "../Common/UIManager.h"
//extern CUIManager* GetGlobalUIManager();
/////////////////////////////////////////////////////////////////////////////
// CJWStatic
CJWStatic::CJWStatic()
{
m_strText = L"";
nRollTextCounter = 0;
nWindowLen = 0;
iBmpLeft = iBmpTop = 0;
}
CJWStatic::~CJWStatic()
{
}
BEGIN_MESSAGE_MAP(CJWStatic, CStatic)
//{{AFX_MSG_MAP(CJWStatic)
ON_WM_PAINT()
ON_WM_TIMER()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CJWStatic message handlers
void CJWStatic::OnPaint()
{
//CPaintDC dc(this); // device context for painting
/* PAINTSTRUCT ps;
CDC* pDC = BeginPaint(&ps);
ASSERT(pDC);
BITMAP bm;
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);
m_bkbmp = new CBitmap();
m_bkbmp->LoadBitmap(IDB_BK);
CBitmap *pBmpOld=(CBitmap *)dcMem.SelectObject(m_bkbmp);
m_bkbmp->GetObject(sizeof(bm),(LPVOID)&bm);
//CRect rcClient;
//GetClientRect(rcClient);
pDC->BitBlt(0,0,rcClient.right-rcClient.left, rcClient.bottom-rcClient.top,&dcMem, 20,60,SRCCOPY);
dcMem.SelectObject(pBmpOld);
pDC->SetBkMode(TRANSPARENT);
//CString strText;
//GetWindowText(strText);
pDC->SetTextColor(m_crText);
pDC->DrawText(m_strText, rcClient, 0);
m_bkbmp->DeleteObject();
EndPaint(&ps);*/
PAINTSTRUCT ps;
CDC* pDC = BeginPaint(&ps);
ASSERT(pDC);
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);
CRect rcClient;
GetClientRect(rcClient);
//m_bkbmp.LoadBitmap(IDB_BK);
dcMem.SelectObject(m_bkbmp);
dcMem.SetBkMode(TRANSPARENT);
//CString strText;
//GetWindowText(strText);
pDC->DrawText(m_strText, rcClient, 0);
pDC->BitBlt(0,0,rcClient.right-rcClient.left, rcClient.bottom-rcClient.top,&dcMem, 0, 0, SRCCOPY);
dcMem.DeleteDC();
m_bkbmp.DeleteObject();
EndPaint(&ps);
}
BOOL CJWStatic::RollText()
{
TCHAR ch;
m_strText="";
for(int i=0 ; i< nWindowLen; )
{
if( i > szText.GetLength()-1) break;
ch = szText.GetAt(nRollTextCounter+i);
m_strText+=ch;
i++;
}
nRollTextCounter += 2;
if(nRollTextCounter >= szText.GetLength() - nWindowLen)
nRollTextCounter = 0;
CRect rcClient;
GetClientRect(rcClient);
InvalidateRect(&rcClient,TRUE);
return TRUE;
}
void CJWStatic::OnTimer(UINT nIDEvent)
{
if( 1 == nIDEvent ) RollText();
CStatic::OnTimer(nIDEvent);
}
BOOL CJWStatic::SetRollText()
{
SetTimer(1,500,NULL);
return TRUE;
}
int CJWStatic::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CStatic::OnCreate(lpCreateStruct) == -1)
return -1;
CString strTemp;
// 初始化需要动态显示的字符
GetWindowText(szText);
//CRect rcClient;
GetClientRect( &rcClient );
nWindowLen = rcClient.Width();
// 从液晶像素得到字符数,估计4个像素 = 一个字符宽度
nWindowLen = nWindowLen/4;
for(int i = 0; i < nWindowLen; i++)
{
strTemp += L" ";
}
//nWindowLen : 显示窗口的宽度。
szText = strTemp + szText + strTemp;
return 0;
}
/*
BOOL CJWStatic::CreateByID(UINT nWndID, CWnd *hParent)
{
JWGPSWNDATTR attr;
g_pUIManager->GetWindowAttributes(nWndID, attr);
m_bkbmp.LoadBitmap( (LPCTSTR)attr.strWndPic1 ); //static的父窗口的背景图。
iBmpLeft = attr.rc.left;
iBmpTop = attr.rc.top;
if (!Create(attr.szName, attr.style, attr.rc, hParent))
{
TRACE0("Failed to Create Static.\n");
return FALSE;
}
return TRUE;
}*/
void CJWStatic::SetTextColor(COLORREF crText)
{
m_crText=crText;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -