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

📄 rectbutton.cpp

📁 使用vc++技术实现光电机串口通信管理程序
💻 CPP
字号:
// RectButton.cpp : implementation file
//

#include "stdafx.h"
#include "PCM120.h"
#include "RectButton.h"
#include "DlgStateDisplay.h"
#include "DlgAllStaSet.h"
#include "RectView.h"
#include "MainFrm.h"



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

/////////////////////////////////////////////////////////////////////////////
// CRectButton

CRectButton::CRectButton()
{
}

CRectButton::~CRectButton()
{
}


BEGIN_MESSAGE_MAP(CRectButton, CButton)
	//{{AFX_MSG_MAP(CRectButton)
	ON_WM_LBUTTONDBLCLK()
	ON_WM_PAINT()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOVE()
	ON_WM_DESTROY()
	ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRectButton message handlers

void CRectButton::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
//	AfxMessageBox(m_strText);
//	CCheckState::bAuto=false;
//	CRectView::bFresh=true;
	CRectView::bFresh=false;
	CDlgStateDisplay dldisplay;
	dldisplay.strStaDisName=m_strText;
	dldisplay.DoModal();
//	CButton::OnLButtonDblClk(nFlags, point);
}

void CRectButton::OnPaint() 
{
	
	CPaintDC dc(this); // device context for painting
	CRect rect,rectmin;
	GetClientRect(rect);
	CBrush edgebrush(RGB(0,0,0));
	dc.FrameRect(rect,&edgebrush);
	CBitmap testbit;
	testbit.LoadBitmap(148);
	CBrush cbrush;
	cbrush.CreatePatternBrush(&testbit);	
//	dc.FrameRect(rect,&cbrush);
	
	rectmin = rect;
	rectmin.DeflateRect(1,1);
	dc.FillSolidRect(rectmin,m_crBackground);
	dc.FillRect(rectmin,&cbrush);
	dc.DrawText(m_strText,rectmin,DT_BOTTOM|DT_LEFT|DT_VCENTER|DT_CENTER|DT_WORDBREAK);
}

BOOL CRectButton::Create(LPCTSTR lpszText,CRect cRect,COLORREF crbk,CWnd* pParentWnd,UINT nID)
{
	m_strText = lpszText;
	m_crBackground = crbk;	
	BOOL bOk = CButton::Create(NULL,WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW,cRect,pParentWnd,nID);
	return bOk;

}

void CRectButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	OnPaint();	
}

void CRectButton::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(CMainFrame::bSet==1)
	{
		CDlgAllStaSet dlgalstaset;
		CString strPath;
		char Get[255];
		dlgalstaset.GetModulePath(strPath,NULL);
		strPath+="PCM120networksetup.ini";
		GetPrivateProfileString("general","StationCnt","0",Get,255,strPath);
		int iCntSta =atoi(Get);
		CString strNa;
		for(int i=1;i<=iCntSta;i++)
		{
			strSect.Format("station%d",i);
			GetPrivateProfileString(strSect,"stationname","0",Get,255,strPath);
			strNa=(LPCTSTR)Get;
			if(strNa.Compare(m_strText)==0)
			{
				i=iCntSta+1;
				GetPrivateProfileString(strSect,"posionx",0,Get,255,strPath);
				CRectView::LCx=atol(Get);
				GetPrivateProfileString(strSect,"posiony",0,Get,255,strPath);
				CRectView::LCy=atol(Get);
				CRectView::bFresh=false;			

			}
		}
	}
	else
	{
		
	}

	CButton::OnLButtonDown(nFlags, point);
}

void CRectButton::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(CMainFrame::bSet==1)
	{
		CDlgAllStaSet dlgalstaset;
		CString strPath,strSet;
		char Get[255];
		dlgalstaset.GetModulePath(strPath,NULL);
		strPath+="PCM120networksetup.ini";
		LONG lx,ly;
		GetPrivateProfileString(strSect,"posionx",0,Get,255,strPath);
		
		lx=point.x+atol(Get);
		strSet.Format("%d",lx);
		WritePrivateProfileString(strSect,"posionx",strSet,strPath);
		GetPrivateProfileString(strSect,"posiony",0,Get,255,strPath);
		
		ly=point.y+atol(Get);
		strSet.Format("%d",ly);	
		WritePrivateProfileString(strSect,"posiony",strSet,strPath);
		strSet.Format("%d",lx+80);
		WritePrivateProfileString(strSect,"posionp",strSet,strPath);
		strSet.Format("%d",ly+80);
		WritePrivateProfileString(strSect,"posionq",strSet,strPath);
		CRectView::bFresh=true;
	}
	else
	{
		CRectView::bFresh=false;	
	}
	
	
	CButton::OnLButtonUp(nFlags, point);
} 

void CRectButton::OnMove(int x, int y) 
{
	CButton::OnMove(x, y);
	
	// TODO: Add your message handler code here
	
}

void CRectButton::OnDestroy() 
{
	CButton::OnDestroy();
	
	// TODO: Add your message handler code here
	
}
void CRectButton::DelButton()
{
		OnDestroy() ;
}

void CRectButton::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default

	CButton::OnMouseMove(nFlags, point);
}

⌨️ 快捷键说明

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