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

📄 mainfrm.cpp

📁 使用VC编写的GPRS通讯代码,可用于GPRS MODEM收发数据
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "vc_demo.h"
#include "time.h"
#include "SettingDlg.h"
#include "senddatadlg.h"
#include "WordThread.h"

#include "MainFrm.h"
#include "gprsdll.h"
#include "vc_demoView.h"
#include "gprsdll.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_COMMAND(ID_MICLEAR, OnMiclear)
	ON_COMMAND(ID_MIOFFLINE, OnMioffline)
	ON_COMMAND(ID_MIREFRESHTABLE, OnMirefreshtable)
	ON_COMMAND(ID_MISENDDATA, OnMisenddata)
	ON_COMMAND(ID_MISTARTSERVICE, OnMistartservice)
	ON_COMMAND(ID_MISTOPSERVICE, OnMistopservice)
	ON_COMMAND(ID_QUIT, OnQuit)
	ON_WM_CLOSE()
	ON_COMMAND(ID_MIANSWER, OnMianswer)
	ON_COMMAND(ID_MISHOWDATA, OnMishowdata)
	ON_COMMAND(ID_SHOWMENU, OnShowmenu)
	ON_COMMAND(ID_HELPCONTENT, OnHelpcontent)
	ON_WM_TIMER()
	ON_UPDATE_COMMAND_UI(ID_MISTARTSERVICE, OnUpdateMistartservice)
	ON_UPDATE_COMMAND_UI(ID_MIOFFLINE, OnUpdateMistopservice)
	ON_UPDATE_COMMAND_UI(ID_MIANSWER, OnUpdateMianswer)
	ON_COMMAND(ID_MISERVERSETTING, OnMiserversetting)
	ON_UPDATE_COMMAND_UI(ID_SHOWMENU, OnUpdateShowmenu)
	ON_COMMAND(ID_MIOFFLINEALL, OnMiofflineall)
	ON_COMMAND(ID_MIVIEWWORD, OnMiviewword)
	ON_UPDATE_COMMAND_UI(ID_MIVIEWWORD, OnUpdateMiviewword)
	ON_UPDATE_COMMAND_UI(ID_MIREFRESHTABLE, OnUpdateMistopservice)
	ON_UPDATE_COMMAND_UI(ID_MISENDDATA, OnUpdateMistopservice)
	ON_UPDATE_COMMAND_UI(ID_MISTOPSERVICE, OnUpdateMistopservice)
	ON_UPDATE_COMMAND_UI(ID_MIOFFLINEALL, OnUpdateMistopservice)
	//}}AFX_MSG_MAP
	ON_UPDATE_COMMAND_UI_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnUpdateViewStyles)
	ON_COMMAND_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnViewStyle)
	ON_MESSAGE(ID_MISENDDATA,OnMisenddata)
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR, 
	ID_SEPARATOR, 
    ID_SEPARATOR 
	// status line indicator
	//ID_INDICATOR_CAPS,
	//ID_INDICATOR_NUM,
	//ID_INDICATOR_SCRL,
	//0x1234
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	m_bAutoMenuEnable=false;
	this->m_bServerRunning=false;	
    this->m_bAnswer=FALSE;
	this->m_viewword=TRUE;
	memset(this->m_userid,0x00,12);

	init_option(&m_option);
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	if (!m_wndMenuBar.Create(this) ||
		!m_wndMenuBar.LoadMenuBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // faile to create
	}

	if (!m_wndToolBar.CreateEx(this, 
		TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | TBSTYLE_LIST,
		WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY 
		| CBRS_SIZE_DYNAMIC
		)
		|| !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndMenuBar);
	DockControlBar(&m_wndToolBar);

	this->SetToolBarStyle();
	this->SetStatusBarStyle();

	return 0;
}

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
	CCreateContext* pContext)
{
	// create splitter window
	if (!m_wndSplitter.CreateStatic(this, 1, 2))
		return FALSE;
	if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftView), CSize(130, 100), pContext))
	{
		m_wndSplitter.DestroyWindow();
		return FALSE;
	}

	if (!m_wndSplitter2.CreateStatic(&m_wndSplitter,2,1,WS_VISIBLE | WS_CHILD | WS_BORDER,m_wndSplitter.IdFromRowCol(0,1)))
		return FALSE;
	if (!m_wndSplitter2.CreateView(0, 0, RUNTIME_CLASS(CVc_demoView), CSize(100, 200), pContext) ||
		!m_wndSplitter2.CreateView(1, 0, RUNTIME_CLASS(CBottomEditView), CSize(100, 100), pContext))
	{
		m_wndSplitter2.DestroyWindow();
		return FALSE;
	}
	return TRUE;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers

CVc_demoView* CMainFrame::GetRightPane()
{
	CWnd* pWnd = m_wndSplitter2.GetPane(0, 0);
	CVc_demoView* pView = DYNAMIC_DOWNCAST(CVc_demoView, pWnd);
	return pView;
}

CLeftView* CMainFrame::GetLeftPane()
{
	CWnd* pWnd = m_wndSplitter.GetPane(0, 0);
	CLeftView* pView = DYNAMIC_DOWNCAST(CLeftView, pWnd);
	return pView;
}

CBottomEditView* CMainFrame::GetBottompane()
{
	CWnd* pWnd = m_wndSplitter2.GetPane(1, 0);
	CBottomEditView* pView = DYNAMIC_DOWNCAST(CBottomEditView, pWnd);
	return pView;
}

void CMainFrame::OnUpdateViewStyles(CCmdUI* pCmdUI)
{
	// TODO: customize or extend this code to handle choices on the
	// View menu.

	CVc_demoView* pView = GetRightPane(); 

	// if the right-hand pane hasn't been created or isn't a view,
	// disable commands in our range

	if (pView == NULL)
		pCmdUI->Enable(FALSE);
	else
	{
		DWORD dwStyle = pView->GetStyle() & LVS_TYPEMASK;

		// if the command is ID_VIEW_LINEUP, only enable command
		// when we're in LVS_ICON or LVS_SMALLICON mode

		if (pCmdUI->m_nID == ID_VIEW_LINEUP)
		{
			if (dwStyle == LVS_ICON || dwStyle == LVS_SMALLICON)
				pCmdUI->Enable();
			else
				pCmdUI->Enable(FALSE);
		}
		else
		{
			// otherwise, use dots to reflect the style of the view
			pCmdUI->Enable();
			BOOL bChecked = FALSE;

			switch (pCmdUI->m_nID)
			{
			case ID_VIEW_DETAILS:
				bChecked = (dwStyle == LVS_REPORT);
				break;

			case ID_VIEW_SMALLICON:
				bChecked = (dwStyle == LVS_SMALLICON);
				break;

			case ID_VIEW_LARGEICON:
				bChecked = (dwStyle == LVS_ICON);
				break;

			case ID_VIEW_LIST:
				bChecked = (dwStyle == LVS_LIST);
				break;

			default:
				bChecked = FALSE;
				break;
			}

			pCmdUI->SetRadio(bChecked ? 1 : 0);
		}
	}
}


void CMainFrame::OnViewStyle(UINT nCommandID)
{
	// TODO: customize or extend this code to handle choices on the
	// View menu.
	CVc_demoView* pView = GetRightPane();

	// if the right-hand pane has been created and is a CVc_demoView,
	// process the menu commands...
	if (pView != NULL)
	{
		DWORD dwStyle = -1;

		switch (nCommandID)
		{
		case ID_VIEW_LINEUP:
			{
				// ask the list control to snap to grid
				CListCtrl& refListCtrl = pView->GetListCtrl();
				refListCtrl.Arrange(LVA_SNAPTOGRID);
			}
			break;

		// other commands change the style on the list control
		case ID_VIEW_DETAILS:
			dwStyle = LVS_REPORT;
			break;

		case ID_VIEW_SMALLICON:
			dwStyle = LVS_SMALLICON;
			break;

		case ID_VIEW_LARGEICON:
			dwStyle = LVS_ICON;
			break;

		case ID_VIEW_LIST:
			dwStyle = LVS_LIST;
			break;
		}

		// change the style; window will repaint automatically
		if (dwStyle != -1)
			pView->ModifyStyle(LVS_TYPEMASK, dwStyle);
	}
}

void CMainFrame::SetToolBarStyle()
{
	CImageList img;
	m_wndToolBar.GetToolBarCtrl().SetButtonWidth(40, 100);
	m_wndToolBar.GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);
    //m_wndToolBar.SetButtonStyle(8,TBSTYLE_CHECK);
	//m_wndToolBar.SetButtonStyle(4,m_wndToolBar.GetButtonStyle(4) 
	//	                           | TBSTYLE_DROPDOWN);

	img.Create(IDB_HOTTOOLBAR, 32, 0, RGB(244, 247, 14));
	m_wndToolBar.GetToolBarCtrl().SetHotImageList(&img);
	img.Detach();
	img.Create(IDB_COLDTOOLBAR, 32, 0, RGB(244, 247, 14));
	m_wndToolBar.GetToolBarCtrl().SetImageList(&img);
	img.Detach();
	
	for(int i = 0; i < m_wndToolBar.GetCount(); i++) 
	{ 
		UINT id = m_wndToolBar.GetItemID(i); 
		CString s;
	    if (!s.LoadString(id)) 
			continue;
	    int j = s.Find(_T('\n')); 
	    if(j < 0) continue;
	    s = s.Right(s.GetLength() - j - 1); 
	    m_wndToolBar.SetButtonText(i,s); 
	}

	CRect rect; 
	m_wndToolBar.GetItemRect(0,&rect); 
	m_wndToolBar.SetSizes(rect.Size(),CSize(32,32));
}

void CMainFrame::OnMiclear() 
{
	// TODO: Add your command handler code here
	CEdit &ce=this->GetBottompane()->GetEditCtrl();
	ce.SetWindowText("");
}

void CMainFrame::OnMioffline() 
{
/*
	char buf[64];

	if (11==strlen(m_userid))
	{
		sprintf(buf,"确认使  %s 下线吗?",this->m_userid);
	    if (IDYES==MessageBox(buf,"确认",MB_YESNO | MB_ICONINFORMATION))
		{
			do_close_one_user((unsigned char *)m_userid,NULL);
			this->RefreshUserTable();
		}
	}
*/
}

void CMainFrame::OnMirefreshtable() 
{
	this->RefreshUserTable();
}

void CMainFrame::OnMisenddata() 
{
	CTreeCtrl &tc=this->GetLeftPane()->GetTreeCtrl();
	CSendDataDlg sdd(NULL,&tc);
	sdd.SetUserId(this->m_userid);
	sdd.DoModal();
}

void CMainFrame::OnMistartservice() 
{
	char mess[512];
	BOOL bResult;

	bResult=DSStartService(m_option.m_iServerPort);

	if (bResult)
	{	   
		sprintf(mess,"厦门桑荣科技数据服务中心启动,侦听端口为%d\r\n",m_option.m_iServerPort);
		if ((m_option.m_bSysAutoPoll) && (m_option.m_iPollTimeInterval>0) && (m_option.m_iOffLineTime>0))
            this->SetTimer(1,(m_option.m_iPollTimeInterval)*1000,NULL);

		this->AddTextToEditView(mess,false);

		if (!StartRecv())
		{
			DSStopService();
			sprintf(mess,"启动接收线程失败,关闭数据中心服务\r\n");
			this->AddTextToEditView(mess,false);
		}
		else
		{
			sprintf(mess,"启动接收线程成功,系统就绪。\r\n");
			AddTextToEditView(mess,false);
		    this->m_bServerRunning=true;
		}

	}
	else

⌨️ 快捷键说明

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