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

📄 mainfrm.cpp

📁 本目录内所有代码仅作指导用户编程之用,用户如果要作为 商业用途,建议使用正版软件进行编译. 开发环境说明: delphi demo : delphi 6.0 vc de
💻 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 "AddUserDlg1.h"

#include "MainFrm.h"
#include "vc_demoView.h"
#include "wcomm_dll.h"

#include "winsock2.h"
#include "GPRS_SMM.h"

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

#define NEWMENUITEM WM_USER+0x13
/*
int g_nCount = 0;
UINT pfnReadData(LPVOID pParam)
{
	char mess[512];
	data_record dr;
	CMainFrame* pt = (CMainFrame *)pParam;
	g_nCount = 0;
	SetWorkMode(1);   //0-use Window Messge, nonblock   1-block mode
	start_gprs_server((HWND)0x01,0x01,5003,mess);
	pt->AddTextToEditView(mess);
	while(g_nCount<10)//for (;;)
	{
		if (0 == do_read_proc(&dr,mess,true))
		{
			if (dr.m_data_len>=0)
				pt->AddTextToEditView(dr.m_userid);
			if (dr.m_data_len>0)
				pt->AddTextToEditView(dr.m_data_buf);
		}
        Sleep(20);
	}
	stop_gprs_server(mess);
	pt->AddTextToEditView(mess);
	return 1;
}
*/
/////////////////////////////////////////////////////////////////////////////
// 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_MESSAGE(RV_MESS,ProcessRvData)
	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_COMMAND(ID_USERINFOIN, OnUserinfoin)
	ON_COMMAND(ID_USERINFOOUT, OnUserinfoout)
	ON_COMMAND(ID_MENUSMSSTART, OnMenusmsstart)
	ON_COMMAND(ID_MENUSMSEXIT, OnMenusmsexit)
	ON_COMMAND(ID_Adduser, OnAdduser)
	ON_COMMAND(ID_DELETE_USER, OnDeleteUser)
	ON_UPDATE_COMMAND_UI(ID_Adduser, OnUpdateAdduser)
	ON_UPDATE_COMMAND_UI(ID_DELETE_USER, OnUpdateDeleteUser)
	ON_UPDATE_COMMAND_UI(ID_USERINFOIN, OnUpdateUserinfoin)
	ON_UPDATE_COMMAND_UI(ID_USERINFOOUT, OnUpdateUserinfoout)
	ON_COMMAND(ID_DISCONNECT_PPP, OnDisconnectPpp)
	ON_UPDATE_COMMAND_UI(ID_DISCONNECT_PPP, OnUpdateDisconnectPpp)
	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)
	ON_COMMAND(ID_STOP_TO_SEND, OnStopToSend)
	ON_UPDATE_COMMAND_UI(ID_STOP_TO_SEND, OnUpdateStopToSend)
	ON_COMMAND(ID_START_TO_SEND, OnStartToSend)
	ON_UPDATE_COMMAND_UI(ID_START_TO_SEND, OnUpdateStartToSend)
	ON_COMMAND(ID_DISCARD_DATA, OnDiscardData)
	ON_UPDATE_COMMAND_UI(ID_DISCARD_DATA, OnUpdateDiscardData)
	//}}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);
	this->m_IsAdduserDlg =FALSE;

	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);

	SetToolBarStyle();
	SetStatusBarStyle();
	AddToSysMenu();	

	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(255, 0, 255));
	m_wndToolBar.GetToolBarCtrl().SetHotImageList(&img);
	img.Detach();
	img.Create(IDB_COLDTOOLBAR, 32, 0, RGB(255, 0, 255));
	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];
	int iResult;

	//AddFilterIP(inet_addr("192.168.0.243"));
	//SetCustomIP(inet_addr("192.168.0.1"));	
	
	/*iResult=start_gprs_server(this->m_hWnd,
		                      RV_MESS,
							  m_option.m_iServerPort,
							  mess);*/
	iResult=start_net_service(this->m_hWnd,
		                      RV_MESS,
							  m_option.m_iServerPort,
							  mess);	

	if (iResult>=0)
	{	   
		if ((m_option.m_bSysAutoPoll) && (m_option.m_iPollTimeInterval>0) && (m_option.m_iOffLineTime>0))
            this->SetTimer(1,(m_option.m_iPollTimeInterval)*1000,NULL);

	    m_bServerRunning=true;
	}
	
	AddTextToEditView(mess,false);

	//AfxBeginThread(RUNTIME_CLASS(CWordThread));
}
void CMainFrame::OnMistopservice() 
{
	// TODO: Add your command handler code here
	char mess[512];

	if (m_option.m_bSysAutoPoll)
		this->KillTimer(1);

	do_close_all_user(mess);
	//this->AddTextToEditView(mess);
	//stop_gprs_server(mess);
	stop_net_service(mess);
	this->AddTextToEditView(mess,true);
	this->m_bServerRunning=false;

	this->GetRightPane()->ClearAllItem();
	this->GetLeftPane()->ClearAllItem();
}

void CMainFrame::OnQuit() 
{
	// TODO: Add your command handler code here
	this->OnClose();	
}

void CMainFrame::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	if (IDYES==MessageBox("确定要退出吗?","退出",MB_YESNO | MB_ICONINFORMATION))
	{
		if (m_bServerRunning)
		{
			this->OnMistopservice();
		}

		CFrameWnd::OnClose();
	}
}

void CMainFrame::ProcessRvData(WPARAM wparam, LPARAM lparam)
{
	data_record dr;
	static char buf[2048];

	if (do_read_proc(&dr,NULL,m_bAnswer)>=0)
	{
		if (dr.m_data_len>0)
		{
			//whether show head or not
			if (m_option.m_bShowHead)
			{
				sprintf(buf,"\r\nuserid:%s,time:%s,len:%d",
					dr.m_userid,dr.m_recv_date,dr.m_data_len);
				this->AddTextToEditView(buf);
			}

			//Hex or not to show data
			if (m_option.m_bHexShow)
			{
				this->PrintData(dr.m_data_buf, dr.m_data_len);
			}
			else
			{
				this->AddTextToEditView(dr.m_data_buf);
			}
		}
		else //data_len=0,it means logon or logout
		{
			this->RefreshUserTable();

			if (0x01==dr.m_data_type)
				sprintf(buf,"%s  登录",dr.m_userid);
			else if (0x02==dr.m_data_type)
				sprintf(buf,"%s  注销",dr.m_userid);
			else if (0x0d==dr.m_data_type)
				sprintf(buf,"%s  参数设置成功",dr.m_userid);
			else if (0x0b==dr.m_data_type)
				sprintf(buf,"%s  参数查询成功",dr.m_userid);
			else if (0x06==dr.m_data_type)
			{
				sprintf(buf,"%s  断开PPP连接成功",dr.m_userid);
				delete_one_user((unsigned char *)dr.m_userid,NULL);
				this->RefreshUserTable();
			}
			else if (0x07==dr.m_data_type)
				sprintf(buf,"%s  停止向DSC发送数据",dr.m_userid);
			else if (0x08==dr.m_data_type)
				sprintf(buf,"%s  允许向DSC发送数据",dr.m_userid);
			else if (0x0A==dr.m_data_type)

⌨️ 快捷键说明

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