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

📄 gprsdlg.cpp

📁 开发环境为EVC++,这个是一个我的一个简单的拨号程序,是通过串口接的GPRS模块,有开发WinCE下的同志可以以次入门
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// GPRSDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GPRS.h"

#include "GPRSDlg.h"

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

static long gBaudRate[]={
	1200,//0
	2400,//1
	4800,//2
	9600,//3
	14400,//4
	19200,//5
	38400,//6
	57600,//7
	115200//8
};
/////////////////////////////////////////////
DWORD ReadComPortThread(CGPRSDlg *pCGPRSDlg);//线程函数不能属于类中,要通过参数和类相关联 (this)

/////////////////////////////////////////////////////////////////////////////
// CGPRSDlg dialog

CGPRSDlg::CGPRSDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGPRSDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGPRSDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_bEnableBackGround=TRUE;//是否添加背景
	m_ComPortOpen=FALSE;
	m_ReadComPortThreadIsInit=FALSE;
	m_bIsShowComPort=TRUE;
}

void CGPRSDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGPRSDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGPRSDlg, CDialog)
	//{{AFX_MSG_MAP(CGPRSDlg)
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
	ON_WM_PAINT()
	ON_WM_DESTROY()

	ON_BN_CLICKED(ID_BTN_GPRSDIA,OnGprsButtonProc)
	ON_BN_CLICKED(ID_BTN_GPRSDIGITAL,OnGprsButtonProc)
	ON_BN_CLICKED(ID_BTN_GPRSOK,OnGprsButtonProc)
	ON_BN_CLICKED(ID_BTN_GPRSHALT,OnGprsButtonProc)
	ON_BN_CLICKED(ID_BTN_GPRSCLOSE,OnGprsButtonProc)
	

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGPRSDlg message handlers

BOOL CGPRSDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen
	CenterWindow(GetDesktopWindow());	// center to the hpc screen
	::SetWindowPos(this->m_hWnd,HWND_TOP,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),SWP_SHOWWINDOW);
	// TODO: Add extra initialization here
	m_bmpBackground.LoadBitmap(IDB_BITMAP_BACKGROUND);					// 窗体背景图片

	m_brush.CreateSolidBrush(RGB(194,200,198));// 生成刷子

	// TODO: Add extra initialization here
	OnPaint();//need first call
	CreateStatic();
	CreateButton();
	CreateComBox();
	CreateEdit();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CGPRSDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		//if(m_bEnableBackGround)
		{
			CPaintDC dc(this);				//对话框的dc
			CDC dcMem; 
			dcMem.CreateCompatibleDC(&dc);   //创建与对话框dc兼容的内存dc

			CRect rect;
			GetClientRect(&rect);

			BITMAP bitMap;
			m_bmpBackground.GetBitmap(&bitMap);

			CBitmap *pbmpOld=dcMem.SelectObject(&m_bmpBackground);		//将背景位图选入内存dc中
			dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,SRCCOPY);   //将内存dc中的位图拉伸显示在对话框的dc中
		}
	//	else
		//{
			//CDialog::OnPaint();
		//}
	}
}
void CGPRSDlg::CreateStatic()
{
	CRect rRect;
	int iCxScreen=0;
	int iCyScreen=0;
	int iStaticWidth;
	int iStaticHight;
	iCxScreen=GetSystemMetrics(SM_CXSCREEN);
	iCyScreen=GetSystemMetrics(SM_CYSCREEN);

	iStaticWidth=80;
	iStaticHight=20;

	//显示串口提示
	rRect.left=20;
	rRect.top=20;
	rRect.right=rRect.left+iStaticWidth;
	rRect.bottom=rRect.top+iStaticHight;

	m_StaticComPort=new CGprsStatic(IDB_BITMAP_BACKGROUND,FALSE);
	if (!m_StaticComPort->Create(_T(""), WS_CHILD | WS_VISIBLE, rRect, this))
	{
		MessageBox(_T("m_StaticComPort Fails!"));	
	}
	m_StaticComPort->SetTransparent(TRUE);//如果透明处理在调用它之前调用一次OnPaint
	m_StaticComPort->SetCaption(_T("Com Port:"),RGB(0,0,0),15,0);


	//显示波特率提示
	rRect.left=20;
	rRect.top=42;
	rRect.right=rRect.left+iStaticWidth;
	rRect.bottom=rRect.top+iStaticHight;

	m_StaticBaudRate=new CGprsStatic(IDB_BITMAP_BACKGROUND,FALSE);
	if (!m_StaticBaudRate->Create(_T(""), WS_CHILD | WS_VISIBLE, rRect, this))
	{
		MessageBox(_T("m_StaticComPort Fails!"));	
	}
	m_StaticBaudRate->SetTransparent(TRUE);
	m_StaticBaudRate->SetCaption(_T("Bard Rate:"),RGB(0,0,0),15,0);

	if(!m_bIsShowComPort)//不显示时
	{
		m_StaticComPort->ShowWindow(SW_HIDE);
		m_StaticBaudRate->ShowWindow(SW_HIDE);
	}
	//显示电话号码
	rRect.left=20;
	rRect.top=64;
	rRect.right=rRect.left+iStaticWidth;
	rRect.bottom=rRect.top+iStaticHight;

	m_StaticDiaNum=new CGprsStatic(IDB_BITMAP_BACKGROUND,FALSE);
	if (!m_StaticDiaNum->Create(_T("Dia Num:"), WS_CHILD | WS_VISIBLE, rRect, this))
	{
		MessageBox(_T("m_StaticDiaNum Fails!"));	
	}
	m_StaticDiaNum->SetTransparent(TRUE);
	m_StaticDiaNum->SetCaption(_T("Dia Num:"),RGB(0,0,0),15,0);


	//显示连接状态
	rRect.left=20;
	rRect.top=150;
	rRect.right=rRect.left+160;
	rRect.bottom=rRect.top+iStaticHight;

	m_StaticDiaState=new CGprsStatic(IDB_BITMAP_BACKGROUND,FALSE);
	if (!m_StaticDiaState->Create(_T("Dia Num:"), WS_CHILD | WS_VISIBLE, rRect, this))
	{
		MessageBox(_T("m_StaticDiaState Fails!"));	
	}
	m_StaticDiaState->SetTransparent(TRUE);
	m_StaticDiaState->SetCaption(_T(""),RGB(255,0,255),15,0);

}


void CGPRSDlg::OnDestroy() 
{
	CDialog::OnDestroy();

	if(m_StaticComPort!=NULL)
	{
		m_StaticComPort=NULL;
	}
	delete m_StaticComPort;

	if(m_StaticBaudRate!=NULL)
	{
		m_StaticBaudRate=NULL;
	}
	delete m_StaticBaudRate;

	if(m_ComPortbutton!=NULL)
	{
		m_ComPortbutton=NULL;
	}
	delete m_ComPortbutton;

	if(m_BaudRatebutton!=NULL)
	{
		m_BaudRatebutton=NULL;
	}
	delete m_BaudRatebutton;

	if(m_Okbutton!=NULL)
	{
		m_Okbutton=NULL;
	}
	delete m_Okbutton;

	if(m_GprsDiabutton!=NULL)
	{
		m_GprsDiabutton=NULL;
	}
	delete m_GprsDiabutton;

	if(m_GprsDigitalbutton!=NULL)
	{
		m_GprsDigitalbutton=NULL;
	}
	delete m_GprsDigitalbutton;

	if(m_ComPortComBox!=NULL)
	{
		m_ComPortComBox=NULL;
	}
	delete m_ComPortComBox;

	if(m_BaudRateComBox!=NULL)
	{
		m_BaudRateComBox=NULL;
	}
	delete m_BaudRateComBox;

	if(m_DiaNum!=NULL)
	{
		m_DiaNum=NULL;
	}
	delete m_DiaNum;

	if(m_StaticDiaNum!=NULL)
	{
		m_StaticDiaNum=NULL;
	}
	delete m_StaticDiaNum;

	if(m_GprsDiaHaltbutton!=NULL)
	{
		m_GprsDiaHaltbutton=NULL;
	}
	delete m_GprsDiaHaltbutton;

	if(m_StaticDiaState!=NULL)
	{
		m_StaticDiaState=NULL;
	}
	delete m_StaticDiaState;
}

HBRUSH CGPRSDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	//在这加一条是否为对话框的判断语句
//	if(nCtlColor ==CTLCOLOR_DLG)
	{
		return m_brush;  //返加刷子
    }
	return hbr;
}

void CGPRSDlg::CreateButton()
{
	CRect rRect;
	UINT  uiBtnStyle=WS_CHILD | WS_VISIBLE | WS_TABSTOP/*  |BS_PUSHBUTTON  | BS_OWNERDRAW*/ ;
	COLORREF	crBtnColor;
	crBtnColor = ::GetSysColor(COLOR_BTNFACE) + RGB(30, 30, 30);
	UINT uiStep=0;
	UINT uiWidth=80;
	UINT uiHight=20;
	
	uiStep=100;

	//----------------------Create Button----------------------------------//
	rRect.left=20+uiStep*0;
	rRect.top=120;
	rRect.right=rRect.left+uiWidth;
	rRect.bottom=rRect.top+uiHight;

	m_GprsDiabutton=new CUIButton;
	if(!(m_GprsDiabutton->Create(_T("GPRS DIA"),uiBtnStyle,rRect,this,ID_BTN_GPRSDIA)))
	{
		MessageBox(_T("Createm_GprsDiabutton  Fails!"));
	}
	m_GprsDiabutton->SetNormalTextColor(RGB(0,0,0));
//	m_GprsDiabutton->SetWindowText(_T("GPRS DIA"));
	
	///////////////////////////////////////////

⌨️ 快捷键说明

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