⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colorwnd.cpp

📁 客户端: 这是一个完整的基于Wince 4.1图形图象,网络通讯(C/S)模式下的商用程序源代码包.
💻 CPP
字号:
// ColorWnd.cpp : implementation file
//

#include "stdafx.h"

#include "ColorWnd.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CColorWnd

CColorWnd::CColorWnd()
{
}

CColorWnd::~CColorWnd()
{
}


BEGIN_MESSAGE_MAP(CColorWnd, CStatic)
	//{{AFX_MSG_MAP(CColorWnd)
	ON_WM_CREATE()
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CColorWnd message handlers

int CColorWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CStatic::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	m_bkcolor=RGB(0,0,0);
	m_fgcolor=RGB(255,0,0);
	m_text_str=TEXT("");
	return 0;
}

void CColorWnd::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	//CClientDC dc(this);
	RECT rect;
	//GetWindowRect(&rect);
	GetClientRect(&rect);

	int w,h;
	w=rect.right-rect.left+1;
	h=rect.bottom-rect.top+1;

    CBrush brush;
	brush.CreateSolidBrush(m_bkcolor);
	CBrush *oldbrush=dc.SelectObject(&brush);
	dc.Rectangle(0,0,w-1,h-1);
	dc.SelectObject(oldbrush);
	brush.DeleteObject();
	//居中显示文本,系统缺省字体,颜色(前景色和背景色)
	if(m_text_str.GetLength()>0)
	{ 
 
	  RECT rect;
	  GetClientRect(&rect);
	  
	  int cw,ch;
	  cw=rect.right-rect.left+1;
	  ch=rect.bottom-rect.top+1;

	  int w,h; 
	  w=GetFontSizeW(dc.GetSafeHdc(),m_text_str.GetBuffer(m_text_str.GetLength()) ,m_text_str.GetLength()); 
	  h=GetFontSizeH(dc.GetSafeHdc(),m_text_str.GetBuffer(m_text_str.GetLength()) ,m_text_str.GetLength()); 
	  
	  int x,y;
	  x=cw>w?(cw-w)/2:0;
	  y=ch>h?(ch-h)/2:0;
	  
	  dc.SetTextColor(m_fgcolor); 
	  dc.SetBkColor(m_bkcolor);//注意其背景色同窗体色  
	  dc.TextOutA(x,y,m_text_str.GetBuffer(m_text_str.GetLength()) ,m_text_str.GetLength()); 
	  //MemDC.TextOutA(X, Y*dwCharY,ch,1);
	}
	// Do not call CStatic::OnPaint() for painting messages
}

void CColorWnd::SetBkColor(COLORREF m_color)
{
  m_bkcolor=m_color;
  Invalidate();
}
void CColorWnd::SetFgColor(COLORREF m_color)
{
  m_fgcolor=m_color;
  Invalidate();
}
void CColorWnd::SetText(CString str)
{
	m_text_str=str;
    Invalidate();
}
CString CColorWnd::GetText(void)
{
	CString str;
    this->GetWindowText(str);
    return str;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -