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

📄 dialogid.cpp

📁 485通讯接口模块的编程应用
💻 CPP
字号:
// DialogID.cpp : implementation file
//

#include "stdafx.h"
#include "DK20DieselizeDynamotor.h"
#include "DialogID.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDialogID dialog
extern BOOL  bChinese ;
CDialogID::CDialogID(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogID::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDialogID)
	m_strID1 = _T("");
	m_strID2 = _T("");
	m_strID3 = _T("");
	//}}AFX_DATA_INIT
}


void CDialogID::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialogID)
	DDX_Control(pDX, IDC_BTN_OK, m_btnOK);
	DDX_Text(pDX, IDC_EDIT1, m_strID1);
	DDX_Text(pDX, IDC_EDIT2, m_strID2);
	DDX_Text(pDX, IDC_EDIT3, m_strID3);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDialogID, CDialog)
	//{{AFX_MSG_MAP(CDialogID)
	ON_WM_PAINT()
	ON_BN_CLICKED(IDC_BTN_OK, OnBtnOk)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogID message handlers

void CDialogID::OnPaint() 
{
	CPaintDC dc(this); 
	CRect rcClient ;   
	GetClientRect(&rcClient)  ; 
	CDC memDc ; 
	memDc.CreateCompatibleDC(&dc)  ; 
	CBitmap bitmap1 ; 
	bitmap1.CreateCompatibleBitmap(&dc , rcClient.Width(),rcClient.Height())  ; 
	
	CBitmap *oldBitmp1 = memDc.SelectObject(&bitmap1)  ; 
	
	memDc.FillSolidRect(&rcClient , RGB(173,211,198)) ; 
    
	CRect rc2(0 , 0 , 500, 20) ;
	DrawGradientFill(&memDc , &rc2 , RGB(244,198,255) ,RGB(198,255,249),5) ;

	memDc.SetTextColor(RGB(0,0,0)) ; 
	memDc.SetBkMode(TRANSPARENT)   ; 

	CRect rcn(100,100,120,120);
	if (bChinese)
	{
		memDc.DrawText(_T("请输入主机编号!"), &rc2 , DT_CENTER |DT_VCENTER	);
		memDc.DrawText(_T("1#"), &rcn , DT_CENTER |DT_VCENTER	);
		m_btnOK.SetWindowText("确定");
	}
	else
	{
		memDc.DrawText(_T("Please enter DieselID !"), &rc2 , DT_CENTER |DT_VCENTER	);
		m_btnOK.SetWindowText("OK");
	}
	
	dc.BitBlt(0,0,rcClient.Width() , rcClient.Height() , &memDc , 0,0,SRCCOPY) ; 
	memDc.SelectObject(oldBitmp1)  ; 
	bitmap1.DeleteObject() ; 
	memDc.DeleteDC() ; 
		
	DeleteObject(oldBitmp1)  ; oldBitmp1 =NULL ; 
	ReleaseDC(&dc) ; 
}

void CDialogID::DrawGradientFill(CDC *pDC, CRect *pRect, COLORREF crStart, COLORREF crEnd, int nSegments)
{
	COLORREF cr;
	int nR = GetRValue(crStart);
	int nG = GetGValue(crStart);
	int nB = GetBValue(crStart);
	
	int neB = GetBValue(crEnd);
	int neG = GetGValue(crEnd);
	int neR = GetRValue(crEnd);
	
	if(nSegments > pRect->Height())
		nSegments = pRect->Height();
	
	int nDiffR = (neR - nR);
	int nDiffG = (neG - nG);
	int nDiffB = (neB - nB);
	
	int ndR = 256 * (nDiffR) / (max(nSegments,1));
	int ndG = 256 * (nDiffG) / (max(nSegments,1));
	int ndB = 256 * (nDiffB) / (max(nSegments,1));
	
	nR *= 256;
	nG *= 256;
	nB *= 256;
	
	neR *= 256;
	neG *= 256;
	neB *= 256;
	
	int nCY = pRect->Height() / max(nSegments,1),  nTop = pRect->top , nBottom =nTop;
	
	CPen *hpen =(CPen*) pDC->SelectStockObject(NULL_PEN);
	for (int i = 0; i < nSegments; i++, nR += ndR, nG += ndG, nB += ndB)
	{
		if (i == (nSegments - 1))
			nTop = pRect->bottom;
		else
			nTop +=  nCY;
		
		cr = RGB(nR / 256, nG / 256, nB / 256);
		
		CBrush br(cr);
		CBrush* pbrOld = pDC->SelectObject(&br);
		
		pDC->Rectangle(pRect->left, nTop+1, pRect->right , nBottom);
		pDC->SelectObject(pbrOld);
		br.DeleteObject() ; 
		DeleteObject(pbrOld)  ; 
		pbrOld =NULL ; 
		
		
		nBottom = nTop ; 
		
	}
	pDC->SelectObject(hpen)  ; 
	DeleteObject(hpen)  ; 
	hpen = NULL ; 
}

void CDialogID::OnBtnOk() 
{
	UpdateData(true);
	if (!m_strID1.IsEmpty() && !m_strID2.IsEmpty() && !m_strID3.IsEmpty() )
	{
		strIDN1 = m_strID1 ;
		strIDN2 = m_strID2 ;
		strIDN3 = m_strID3 ;
		tBeginTime = CTime::GetCurrentTime();
		CDialog::OnOK();
	}
	else
	{
		if (bChinese)
			AfxMessageBox("柴油机编号不能为空!请确认。");
		else
			AfxMessageBox("DiselID is empty !") ;
	}

	
	
}

⌨️ 快捷键说明

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