acl/app/jaws/JawsCtrl/JawsCtrlDlg.cpp

366 lines
8.4 KiB
C++
Raw Normal View History

// JawsCtrlDlg.cpp : ʵ<><CAB5><EFBFBD>ļ<EFBFBD>
2014-11-19 00:25:21 +08:00
//
#include "stdafx.h"
#include "lib_acl.h"
#include "JawsCtrl.h"
#include "JawsCtrlDlg.h"
#include ".\jawsctrldlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// <20><><EFBFBD><EFBFBD>Ӧ<EFBFBD>ó<EFBFBD><C3B3>򡰹<EFBFBD><F2A1B0B9>ڡ<EFBFBD><DAA1>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD> CAboutDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
2014-11-19 00:25:21 +08:00
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// <20>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV ֧<><D6A7>
2014-11-19 00:25:21 +08:00
// ʵ<><CAB5>
2014-11-19 00:25:21 +08:00
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CJawsCtrlDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
2014-11-19 00:25:21 +08:00
CJawsCtrlDlg::CJawsCtrlDlg(CWnd* pParent /*=NULL*/)
: CDialog(CJawsCtrlDlg::IDD, pParent)
, m_trayIcon(IDR_MENU_ICON)
, m_bShutdown(FALSE)
, m_sJawsName(_T(""))
, m_sJawsCtrlName(_T(""))
, m_listenPort(8080)
, m_listenIp(_T("127.0.0.1"))
, m_httpVhostPath(_T(""))
, m_httpVhostDefault(_T(""))
, m_httpTmplPath(_T(""))
, m_httpFilter(_T("HTTP_FILTER_HTTPD"))
, m_nHttpFilter(IDC_RADIO_HTTPD)
, m_pService(NULL)
, m_regRun(_T("JawsCtrl"))
{
char buf[MAX_PATH];
acl_proctl_daemon_path(buf, sizeof(buf));
m_sJawsName.Format("%s\\Jaws.exe", buf);
m_sJawsCtrlName.Format("%s\\JawsCtrl.exe", buf);
//m_sJawsName.Format("C:\\\"Program Files\"\\\"Acl Project\"\\Jaws\\Jaws.exe");
m_httpVhostPath.Format("%s\\conf\\www\\vhost", buf);
m_httpVhostDefault.Format("%s\\conf\\www\\defaults.cf", buf);
m_httpTmplPath.Format("%s\\conf\\www\\tmpl", buf);
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_procCtrl.RunThread();
}
void CJawsCtrlDlg::DoDataExchange(CDataExchange* pDX)
{
BYTE field1, field2, field3, field4;
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_IPADDRESS_LISTEN, m_listenIpCtrl);
if (pDX->m_bSaveAndValidate) {
m_listenIpCtrl.GetAddress(field1, field2, field3, field4);
m_listenIp.Format("%d.%d.%d.%d", field1, field2, field3, field4);
}
DDX_Text(pDX, IDC_EDIT_PORT, m_listenPort);
DDV_MinMaxLong(pDX, m_listenPort, 0, 65535);
}
BEGIN_MESSAGE_MAP(CJawsCtrlDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_WM_CREATE()
ON_COMMAND(ID_OPEN_MAIN, OnOpenMain)
ON_COMMAND(ID_QUIT, OnQuit)
ON_MESSAGE(WM_MY_TRAY_NOTIFICATION, OnTrayNotification)
ON_WM_NCPAINT()
ON_WM_CLOSE()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON_START, OnBnClickedButtonStart)
ON_BN_CLICKED(IDC_BUTTON_STOP, OnBnClickedButtonStop)
ON_BN_CLICKED(IDC_BUTTON_QUIT, OnBnClickedButtonQuit)
ON_BN_CLICKED(IDC_MORE, OnBnClickedMore)
ON_BN_CLICKED(IDC_AUTO_RUN, OnBnClickedAutoRun)
END_MESSAGE_MAP()
// CJawsCtrlDlg <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
BOOL CJawsCtrlDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// <20><>\<5C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...\<5C><><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ϵͳ<CFB5>˵<EFBFBD><CBB5>С<EFBFBD>
2014-11-19 00:25:21 +08:00
// IDM_ABOUTBOX <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD>Χ<EEB7B6>ڡ<EFBFBD>
2014-11-19 00:25:21 +08:00
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);
}
}
// <20><><EFBFBD>ô˶Ի<CBB6><D4BB><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD><EAA1A3>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>ǶԻ<C7B6><D4BB><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ܽ<EFBFBD><DCBD>Զ<EFBFBD>
// ִ<>д˲<D0B4><CBB2><EFBFBD>
SetIcon(m_hIcon, TRUE); // <20><><EFBFBD>ô<EFBFBD>ͼ<EFBFBD><CDBC>
SetIcon(m_hIcon, FALSE); // <20><><EFBFBD><EFBFBD>Сͼ<D0A1><CDBC>
2014-11-19 00:25:21 +08:00
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
m_dVerticalExpand.Init(this, IDC_DIVIDER, TRUE);
ExpandDialog(FALSE);
theApp.m_singleCtrl.Register();
m_listenIpCtrl.SetAddress(127, 0, 0, 1);
CheckRadioButton(IDC_RADIO_HTTPD, IDC_RADIO_HTTP_PROXY, IDC_RADIO_HTTP_PROXY);
GetDlgItem(IDC_BUTTON_STOP)->EnableWindow(FALSE);
// <20><><EFBFBD><EFBFBD> Jaws.exe
2014-11-19 00:25:21 +08:00
if (m_regRun.IfAutoRun()) {
OnBnClickedButtonStart();
CheckDlgButton(IDC_AUTO_RUN, 1);
} else
CheckDlgButton(IDC_AUTO_RUN, 0);
return TRUE; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿ؼ<CBBF><D8BC>Ľ<EFBFBD><C4BD><EFBFBD><E3A3AC><EFBFBD>򷵻<EFBFBD> TRUE
2014-11-19 00:25:21 +08:00
}
void CJawsCtrlDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƹ<EFBFBD>ͼ<EFBFBD><EFBFBD><EAA1A3><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD>ĵ<EFBFBD>/<2F><>ͼģ<CDBC>͵<EFBFBD> MFC Ӧ<>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>
// <20><EFBFBD>ɿ<EFBFBD><C9BF><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>ɡ<EFBFBD>
2014-11-19 00:25:21 +08:00
void CJawsCtrlDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // <20><><EFBFBD>ڻ<EFBFBD><DABB>Ƶ<EFBFBD><C6B5><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// ʹͼ<CAB9><CDBC><EFBFBD>ڹ<EFBFBD><DAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD>
2014-11-19 00:25:21 +08:00
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;
// <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
2014-11-19 00:25:21 +08:00
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
//<2F><><EFBFBD>û<EFBFBD><C3BB>϶<EFBFBD><CFB6><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱϵͳ<CFB5><CDB3><EFBFBD>ô˺<C3B4><CBBA><EFBFBD>ȡ<EFBFBD>ù<EFBFBD><C3B9><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>
2014-11-19 00:25:21 +08:00
HCURSOR CJawsCtrlDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
int CJawsCtrlDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ר<EFBFBD>õĴ<C3B5><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
m_trayIcon.SetNotificationWnd(this, WM_MY_TRAY_NOTIFICATION);
m_trayIcon.SetIcon(IDI_MIN_ICON);
return 0;
}
void CJawsCtrlDlg::OnOpenMain()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEB4A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
ShowWindow(SW_NORMAL);
}
void CJawsCtrlDlg::OnQuit()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEB4A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
m_bShutdown = TRUE; // really exit
SendMessage(WM_CLOSE);
}
afx_msg LRESULT CJawsCtrlDlg::OnTrayNotification(WPARAM uID, LPARAM lEvent)
{
// let tray icon do default stuff
return m_trayIcon.OnTrayNotification(uID, lEvent);
}
void CJawsCtrlDlg::OnNcPaint()
{
// TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><>Ϊ<EFBFBD><CEAA>ͼ<EFBFBD><CDBC>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD> CDialog::OnNcPaint()
2014-11-19 00:25:21 +08:00
static int i = 2;
if(i > 0)
{
i --;
ShowWindow(SW_HIDE);
} else
{
CDialog::OnNcPaint();
}
}
void CJawsCtrlDlg::OnClose()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
2014-11-19 00:25:21 +08:00
if (m_bShutdown) {
if (m_pService) {
m_procCtrl.StopOne(*m_pService);
delete m_pService;
m_pService = NULL;
}
CDialog::OnClose();
} else {
ShowWindow(SW_HIDE);
}
}
void CJawsCtrlDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
theApp.m_singleCtrl.Remove();
}
void CJawsCtrlDlg::OnBnClickedButtonStart()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
CString addr;
addr.Format("%s:%d", m_listenIp, m_listenPort);
m_nHttpFilter = GetCheckedRadioButton(IDC_RADIO_HTTPD, IDC_RADIO_HTTP_PROXY);
switch (m_nHttpFilter) {
case IDC_RADIO_HTTPD:
m_httpFilter.Format("HTTP_FILTER_HTTPD");
break;
case IDC_RADIO_HTTP_PROXY:
m_httpFilter.Format("HTTP_FILTER_PROXY");
break;
default:
m_httpFilter.Format("HTTP_FILTER_HTTPD");
break;
}
ASSERT(m_pService == NULL);
m_pService = new CHttpService(
m_sJawsName.GetString(),
addr.GetString(),
m_httpVhostPath.GetString(),
m_httpVhostDefault.GetString(),
m_httpTmplPath.GetString(),
m_httpFilter.GetString());
m_pService->DebugArgv();
m_procCtrl.StartOne(*m_pService);
GetDlgItem(IDC_BUTTON_START)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_STOP)->EnableWindow(TRUE);
GetDlgItem(IDC_RADIO_HTTPD)->EnableWindow(FALSE);
GetDlgItem(IDC_RADIO_HTTP_PROXY)->EnableWindow(FALSE);
}
void CJawsCtrlDlg::OnBnClickedButtonStop()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
ASSERT(m_pService != NULL);
GetDlgItem(IDC_BUTTON_START)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON_STOP)->EnableWindow(FALSE);
m_procCtrl.StopOne(*m_pService);
GetDlgItem(IDC_RADIO_HTTPD)->EnableWindow(TRUE);
GetDlgItem(IDC_RADIO_HTTP_PROXY)->EnableWindow(TRUE);
delete m_pService;
m_pService = NULL;
}
void CJawsCtrlDlg::OnBnClickedButtonQuit()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
m_bShutdown = TRUE; // really exit
SendMessage(WM_CLOSE);
}
void CJawsCtrlDlg::OnBnClickedMore()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
static BOOL bExpand = TRUE;
ExpandDialog(bExpand);
bExpand = !bExpand;
}
void CJawsCtrlDlg::ExpandDialog(BOOL bExpand)
{
CString sExpand;
m_dVerticalExpand.Expand(bExpand);
if (bExpand) {
sExpand = "<<(&L)<29><><EFBFBD><EFBFBD>";
2014-11-19 00:25:21 +08:00
} else {
sExpand = "(&M)<29><><EFBFBD><EFBFBD>>>";
2014-11-19 00:25:21 +08:00
}
SetDlgItemText(IDC_MORE, sExpand);
}
void CJawsCtrlDlg::OnBnClickedAutoRun()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
if (IsDlgButtonChecked(IDC_AUTO_RUN))
m_regRun.AutoRun(TRUE, m_sJawsCtrlName.GetString());
else
m_regRun.AutoRun(FALSE, m_sJawsCtrlName.GetString());
}