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

📄 signalprogress.cpp

📁 GSM通讯串口类,通过RS232串口与GSM MODEM连接,发送短信.
💻 CPP
字号:
// signalprogress.cpp : implementation file
//

#include "stdafx.h"
#include "..\resource.h"
#include "signalprogress.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSignalProgress

CSignalProgress::CSignalProgress()
{
	RegisterWindowClass();

	m_bmpSignal.LoadBitmap(IDB_SIGNAL);
	m_bmpNoSignal.LoadBitmap(IDB_NO_SIGNAL);

	m_dblNowValue = 0.0;

}

CSignalProgress::~CSignalProgress()
{
}


BEGIN_MESSAGE_MAP(CSignalProgress, CWnd)
	//{{AFX_MSG_MAP(CSignalProgress)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CSignalProgress message handlers

BOOL CSignalProgress::RegisterWindowClass(void)
{
	WNDCLASS wndcls;
    HINSTANCE hInst = AfxGetInstanceHandle();

    if (!(::GetClassInfo(hInst, SIGNALPROGRESS_CLASSNAME, &wndcls)))
    {
        // otherwise we need to register a new class
        wndcls.style            = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
        wndcls.lpfnWndProc      = ::DefWindowProc;
        wndcls.cbClsExtra       = wndcls.cbWndExtra = 0;
        wndcls.hInstance        = hInst;
        wndcls.hIcon            = NULL;
        wndcls.hCursor          = NULL;
        wndcls.hbrBackground    = (HBRUSH) (COLOR_3DFACE + 1);
        wndcls.lpszMenuName     = NULL;
        wndcls.lpszClassName    = SIGNALPROGRESS_CLASSNAME;

        if (!AfxRegisterClass(&wndcls)) {
            AfxThrowResourceException();
            return FALSE;
        }
    }

    return TRUE;
}

BOOL CSignalProgress::Create(const RECT& rect, CWnd* pParentWnd, UINT nID, DWORD dwStyle)
{
	// TODO: Add your specialized code here and/or call the base class
	ASSERT(pParentWnd->m_hWnd);
	
	if (!CWnd::Create(SIGNALPROGRESS_CLASSNAME, NULL, dwStyle, rect, pParentWnd, nID))
		return FALSE;

	return TRUE;
}

void CSignalProgress::OnDraw(CDC* pDC)
{
	CRect RectClient;
	GetClientRect(RectClient);
	CBrush brushBK(RGB(0, 0, 0));
	CDC MemDC;

	pDC->SetBkColor(RGB(0, 0, 0));
	pDC->SetTextColor(RGB(0, 255, 0));


	MemDC.CreateCompatibleDC(pDC);
	CBitmap* pOldBmp = MemDC.SelectObject(&m_bmpNoSignal);
	int left = (RectClient.Width() - 33) / 2;
	int bottom = RectClient.Height() - 20;
	bottom -= (bottom % 3);

	for (int i = 6; i <= bottom; i += 3)
		pDC->BitBlt(left, i, 33, 2, &MemDC, 0, 0, SRCCOPY);

	CString strTmp;
	strTmp.Format(_T("%d"), (UINT)(m_dblNowValue * 100));
	strTmp += '%';
	CRect RectTmp(0, bottom + 4, RectClient.Width(), RectClient.Height());
	pDC->FillRect(RectTmp, &CBrush(RGB(0, 0, 0)));
	pDC->DrawText(strTmp, RectTmp, DT_CENTER | DT_SINGLELINE | DT_TOP);

	int top = (int)((bottom / 3) * m_dblNowValue);

	if (top <= 1 && m_dblNowValue != 0)
		top = 2;

	bottom += 3;
	MemDC.SelectObject(&m_bmpSignal);
	for (int j = 0; j < top - 1; j++)
		pDC->BitBlt(left, bottom -= 3, 33, 2, &MemDC, 0, 0, SRCCOPY);

	MemDC.SelectObject(pOldBmp);
}

void CSignalProgress::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	CRect RectClient;
	GetClientRect(RectClient);
	CBrush brushBK(RGB(0, 0, 0));
	dc.FillRect(RectClient, &brushBK);
	OnDraw(&dc);
	// Do not call CWnd::OnPaint() for painting messages
}


void CSignalProgress::CalculateValue(const UINT& newValue)
{
	if (newValue >=0 && newValue <= 0x1F)
		m_dblNowValue = (double)newValue / SIGNALMAX;
	else
		m_dblNowValue = 0;

	CClientDC dc(this);
	OnDraw(&dc);
}

⌨️ 快捷键说明

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