📄 chenmiddlewaredlg.cpp
字号:
// ChenMiddlewareDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ChenMiddleware.h"
#include "ChenMiddlewareDlg.h"
#include "Get_CheckSum.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define WM_NOTIFYICON WM_USER+17
#define ID_TIMER 1 //时钟id
bool bThreadExitFlag=false; //socket线程退出标志
CStatic *g_Static_Tishi1;
CListCtrl *g_pListBox_Main;
CGetCheckSum g_CheckSum;
HANDLE g_hEventEnd;
int g_iCount=0;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChenMiddlewareDlg dialog
CChenMiddlewareDlg::CChenMiddlewareDlg(CWnd* pParent /*=NULL*/)
: CDialog(CChenMiddlewareDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CChenMiddlewareDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CChenMiddlewareDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChenMiddlewareDlg)
DDX_Control(pDX, IDC_LIST_MAIN, m_ListBox_Main);
DDX_Control(pDX, IDC_STATIC_TISHI1, m_Static_Tishi1);
DDX_Control(pDX, IDC_BUTTON_START, m_Butt_Start);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChenMiddlewareDlg, CDialog)
//{{AFX_MSG_MAP(CChenMiddlewareDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
ON_BN_CLICKED(IDC_BUTTON_HIDE, OnButtonHide)
ON_WM_CLOSE()
ON_MESSAGE(WM_NOTIFYICON, OnNotifyIcon)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChenMiddlewareDlg message handlers
BOOL CChenMiddlewareDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
// TODO: Add extra initialization here
g_hEventEnd=CreateEvent(NULL,FALSE,FALSE,NULL); //无信号
g_Static_Tishi1=&m_Static_Tishi1;
g_pListBox_Main=&m_ListBox_Main;
CRect rect;
m_ListBox_Main.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_ListBox_Main.SetBkColor(RGB(250,250,250));
m_ListBox_Main.SetTextColor(RGB(0,0,0));
m_ListBox_Main.SetTextBkColor(RGB(250,250,250));
m_ListBox_Main.InsertColumn(0,"序号");
m_ListBox_Main.InsertColumn(1,"进入时间");
m_ListBox_Main.InsertColumn(2,"客户IP");
m_ListBox_Main.InsertColumn(3,"备注");
m_ListBox_Main.GetClientRect(rect); //获得当前客户区信息
m_ListBox_Main.SetColumnWidth(0,rect.Width()/7);
m_ListBox_Main.SetColumnWidth(1,rect.Width()/3);
m_ListBox_Main.SetColumnWidth(2,rect.Width()/4);
m_ListBox_Main.SetColumnWidth(3,rect.Width()/6);
// 将图标放入系统托盘
NOTIFYICONDATA nd;
nd.cbSize = sizeof (NOTIFYICONDATA);
nd.hWnd = m_hWnd;
nd.uID = IDR_MAINFRAME;
nd.uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP;
nd.uCallbackMessage = WM_NOTIFYICON;
nd.hIcon = m_hIcon;
strcpy(nd.szTip, "通用应用服务器V1.0");
Shell_NotifyIcon(NIM_ADD, &nd);
return TRUE; // return TRUE unless you set the focus to a control
}
void CChenMiddlewareDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
// 屏蔽最大化(MFC Bug),将最小化重定向至隐藏窗口
if (nID == SC_MAXIMIZE)
return;
if (nID == SC_MINIMIZE)
ShowWindow(SW_HIDE);
else
CWnd::OnSysCommand(nID, lParam);
}
void CChenMiddlewareDlg::OnNotifyIcon(WPARAM wParam, LPARAM lParam)
{
// 响应在托盘图标上的右键双击
if ((wParam == IDR_MAINFRAME)&&(lParam == WM_LBUTTONDOWN))
ShowWindow(SW_SHOWNORMAL);
}
void CChenMiddlewareDlg::OnButtonHide()
{
// TODO: Add your control notification handler code here
OnSysCommand(SC_MINIMIZE, 0x0000);
return;
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CChenMiddlewareDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// 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
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CChenMiddlewareDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CChenMiddlewareDlg::OnButtonStart()
{
// TODO: Add your control notification handler code here
CString str;
GetDlgItemText(IDC_BUTTON_START,str);
if(str.Compare("停止服务")==0)
{
bThreadExitFlag=true;
StopService();
::KillTimer(this->m_hWnd,ID_TIMER); //关闭定时器
SetDlgItemText(IDC_BUTTON_START,"启动服务");
}
else
{
bThreadExitFlag=false;
if(StartService()==true)
{
SetDlgItemText(IDC_BUTTON_START,"停止服务");
SetDlgItemText(IDC_STATIC_TISHI1,"Runing 。。。。");
::SetTimer(this->m_hWnd,ID_TIMER,500,NULL); //启动定时器,10min
TRACE0("服务启动成功 ");
}
else
{
AfxMessageBox("启动服务失败! ");
}
}
}
bool CChenMiddlewareDlg::StartService()
{
m_NetWorkThread.CreateThread();
return true;
}
bool CChenMiddlewareDlg::StopService()
{
//1. 停止服务的过程
m_Butt_Start.EnableWindow(false);
WaitForSingleObject(g_hEventEnd,INFINITE);//此时,g_hEventEnd改变为无信号
SetDlgItemText(IDC_STATIC_TISHI1,"服务已经停止");
Sleep(1);
m_Butt_Start.EnableWindow(true);
TRACE0("服务已经停止 ");
return true;
}
void CChenMiddlewareDlg::OnOK()
{
CString str;
GetDlgItemText(IDC_BUTTON_START,str);
if(str.Compare("停止服务")==0)
{
AfxMessageBox("请先停止服务器! ");
return;
}
CDialog::OnOK();
}
void CChenMiddlewareDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
CString str;
GetDlgItemText(IDC_BUTTON_START,str);
if(str.Compare("停止服务")==0)
{
AfxMessageBox("请先停止服务器! ");
return;
}
CDialog::OnClose();
}
void CChenMiddlewareDlg::OnTimer(UINT nIDEvent)
{
g_iCount++;
switch (g_iCount)
{
case 1:
SetDlgItemText(IDC_STATIC_TISHI1,"Runing ");
break;
case 2:
SetDlgItemText(IDC_STATIC_TISHI1,"Runing 。 ");
break;
case 3:
SetDlgItemText(IDC_STATIC_TISHI1,"Runing 。。 ");
break;
case 4:
SetDlgItemText(IDC_STATIC_TISHI1,"Runing 。。。 ");
break;
case 5:
SetDlgItemText(IDC_STATIC_TISHI1,"Runing 。。。。");
g_iCount=0;
break;
}
CDialog::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -