acl/lib_acl_cpp/samples/gui_rpc/gui_rpcDlg.cpp

382 lines
8.8 KiB
C++
Raw Normal View History

// gui_rpcDlg.cpp : ʵ<><CAB5><EFBFBD>ļ<EFBFBD>
//
#include "stdafx.h"
#include "gui_rpc.h"
#include "rpc/rpc_manager.h"
#include "rpc/http_download.h"
#include "gui_rpcDlg.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>
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// <20>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV ֧<><D6A7>
// ʵ<><CAB5>
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()
// Cgui_rpcDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
Cgui_rpcDlg::Cgui_rpcDlg(CWnd* pParent /*=NULL*/)
: CDialog(Cgui_rpcDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
Cgui_rpcDlg::~Cgui_rpcDlg()
{
}
void Cgui_rpcDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_REQ, m_reqCtlEdit);
DDX_Control(pDX, IDC_RES, m_resCtlEdit);
DDX_Text(pDX, IDC_IP, m_serverIp);
DDX_Text(pDX, IDC_PORT, m_serverPort);
}
BEGIN_MESSAGE_MAP(Cgui_rpcDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON_RUN, OnBnClickedButtonRun)
ON_BN_CLICKED(IDC_CLEAR, OnBnClickedClear)
ON_WM_SIZE()
ON_EN_CHANGE(IDC_URL, OnEnChangeUrl)
END_MESSAGE_MAP()
// Cgui_rpcDlg <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BOOL Cgui_rpcDlg::OnInitDialog()
{
CDialog::OnInitDialog();
BOOL bOk = m_resizer.Hook(this);
ASSERT(bOk == TRUE);
// <20><>\<5C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...\<5C><><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ϵͳ<CFB5>˵<EFBFBD><CBB5>С<EFBFBD>
// IDM_ABOUTBOX <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD>Χ<EEB7B6>ڡ<EFBFBD>
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);
}
}
bOk = m_resizer.SetAnchor(IDC_URL, ANCHOR_HORIZONTALLY);
ASSERT( bOk);
bOk = m_resizer.CreateSplitContainer(_T("MySplitter"), IDC_STATIC_REQ, IDC_STATIC_RES);
ASSERT( bOk );
//bOk = m_resizer.SetAnchor(IDC_STATIC_REQ, ANCHOR_ALL | ANCHOR_PRIORITY_RIGHT);
//ASSERT( bOk );
//bOk = m_resizer.SetAnchor(IDC_STATIC_RES, ANCHOR_ALL | ANCHOR_PRIORITY_BOTTOM);
//ASSERT( bOk );
//bOk = m_resizer.SetMinimumSize(IDC_STATIC_REQ, CSize(150, 100));
//ASSERT( bOk );
//bOk = m_resizer.SetMinimumSize(IDC_STATIC_RES, CSize(150, 100));
//ASSERT( bOk );
bOk = m_resizer.SetAnchor(_T("MySplitter"), ANCHOR_ALL);
ASSERT( bOk );
bOk = m_resizer.SetShowSplitterGrip(_T("MySplitter"), TRUE);
ASSERT( bOk);
bOk = m_resizer.SetParent(IDC_REQ, IDC_STATIC_REQ);
ASSERT( bOk);
bOk = m_resizer.SetParent(IDC_RES, IDC_STATIC_RES);
ASSERT( bOk);
bOk = m_resizer.SetAnchor(IDC_REQ, ANCHOR_LEFT | ANCHOR_ALL );
ASSERT( bOk);
bOk = m_resizer.SetAnchor(IDC_RES, ANCHOR_RIGHT | ANCHOR_ALL);
ASSERT( bOk);
bOk = m_resizer.SetAnchor(IDOK, ANCHOR_RIGHT | ANCHOR_BOTTOM);
ASSERT(bOk == TRUE);
bOk = m_resizer.SetAnchor(IDC_BUTTON_RUN, ANCHOR_RIGHT | ANCHOR_BOTTOM);
ASSERT(bOk == TRUE);
bOk = m_resizer.SetAnchor(IDC_CLEAR, ANCHOR_RIGHT | ANCHOR_BOTTOM);
ASSERT(bOk == TRUE);
//GetClientRect(&m_rect);
// <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>
GetDlgItem(IDC_PORT)->SetWindowText("80");
// <20><><EFBFBD><EFBFBD>״̬<D7B4><CCAC>
int aWidths[3] = {50, 300, -1};
m_wndMeterBar.SetParts(3, aWidths);
m_wndMeterBar.Create(WS_CHILD | WS_VISIBLE | WS_BORDER
| CCS_BOTTOM | SBARS_SIZEGRIP,
CRect(0,0,0,0), this, 0);
m_wndMeterBar.SetText("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 0, 0);
m_wndMeterBar.SetText("", 1, 0);
m_wndMeterBar.SetText("", 2, 0);
//ShowWindow(SW_MINIMIZE);
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_resizer.SetShowResizeGrip(TRUE);
bOk = m_resizer.InvokeOnResized();
ASSERT( bOk);
return TRUE; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿ؼ<CBBF><D8BC>Ľ<EFBFBD><C4BD><EFBFBD><E3A3AC><EFBFBD>򷵻<EFBFBD> TRUE
}
void Cgui_rpcDlg::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>
void Cgui_rpcDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // <20><><EFBFBD>ڻ<EFBFBD><DABB>Ƶ<EFBFBD><C6B5><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// ʹͼ<CAB9><CDBC><EFBFBD>ڹ<EFBFBD><DAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD>
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>
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
// <20><><EFBFBD><EFBFBD> URL <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GetDlgItem(IDC_URL)->SetFocus();
}
//<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>
HCURSOR Cgui_rpcDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void Cgui_rpcDlg::OnBnClickedButtonRun()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CString url;
GetDlgItem(IDC_URL)->GetWindowText(url);
if (url.GetLength() == 0)
{
MessageBox("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD> URL!");
return;
}
const char* ptr = url.GetString();
if (strncasecmp(ptr, "http://", sizeof("http://") - 1) != 0)
url = "http://" + url;
CString addr;
GetDlgItem(IDC_IP)->GetWindowText(addr);
if (addr.GetLength() == 0)
{
MessageBox("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD>ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ!");
return;
}
CString port;
GetDlgItem(IDC_PORT)->GetWindowText(port);
addr.AppendFormat(":%s", port.GetString());
// <20><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><DFB3>д<EFBFBD><D0B4><EFBFBD>һ<EFBFBD><D2BB> HTTP <20><><EFBFBD>ع<EFBFBD><D8B9><EFBFBD>
http_download* down = new http_download(addr.GetString(),
url.GetString(), this);
// ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD>߳̿<DFB3>ʼһ<CABC><D2BB> HTTP <20><><EFBFBD>ع<EFBFBD><D8B9><EFBFBD>
rpc_manager::get_instance().fork(down);
// <20><>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD>ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP <20><><EFBFBD>ع<EFBFBD><D8B9>̣<EFBFBD><CCA3><EFBFBD><EFBFBD>˴<EFBFBD>Ϊ<EFBFBD>˼򵥣<CBBC><F2B5A5A3>Ƚ<EFBFBD>ֹ<EFBFBD><D6B9>һ<EFBFBD><D2BB>
// HTTP <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GetDlgItem(IDC_BUTTON_RUN)->EnableWindow(false);
}
void Cgui_rpcDlg::OnBnClickedClear()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_reqCtlEdit.SetSel(0, m_reqCtlEdit.GetWindowTextLength());
m_reqCtlEdit.ReplaceSel("");
m_resCtlEdit.SetSel(0, m_resCtlEdit.GetWindowTextLength());
m_resCtlEdit.ReplaceSel("");
m_wndMeterBar.GetProgressCtrl().SetPos(0);
}
void Cgui_rpcDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ի<EFBFBD><D4BB><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD>û<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˲<EFBFBD><CBB2>ܸı<DCB8><C4B1><EFBFBD><EFBFBD><EFBFBD>С(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>)
if(!IsWindowVisible())
return;
// TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (m_wndMeterBar.GetSafeHwnd())
{
int aWidths[3] = {cx / 3, cx / 3, -1};
m_wndMeterBar.SetParts(3, aWidths);
m_wndMeterBar.SetText("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 0, 0);
m_wndMeterBar.SetText("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>2", 1, 0); //SBT_NOBORDERS);
m_wndMeterBar.SetText("", 2, SBT_NOBORDERS);
m_wndMeterBar.SendMessage(WM_SIZE, nType, MAKELONG(cy, cx));
}
}
void Cgui_rpcDlg::OnEnChangeUrl()
{
// TODO: <20><><EFBFBD><EFBFBD><EFBFBD>ÿؼ<C3BF><D8BC><EFBFBD> RICHEDIT <20>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD>͸<EFBFBD>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д CDialog::OnInitDialog()
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CRichEditCtrl().SetEventMask()<29><>
// ͬʱ<CDAC><CAB1> ENM_CHANGE <20><>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3B5BD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CString url;
GetDlgItem(IDC_URL)->GetWindowText(url);
if (url.GetLength() == 0)
return;
url.MakeLower();
char* ptr = url.GetBuffer();
#define SKIP_SP(x) do { if (*(x) == ' ' || *(x) == '\t') (x)++; } while(0)
SKIP_SP(ptr);
if (*ptr == 0 || strlen(ptr) <= sizeof("http://") - 1)
return;
if (strncmp(ptr, "http://", sizeof("http://") - 1) == 0)
ptr += sizeof("http://") - 1;
if (*ptr == 0)
{
GetDlgItem(IDC_IP)->SetWindowText("");
return;
}
CString addr = ptr;
int pos = addr.Find('/');
if (pos >= 0)
addr.Truncate(pos);
CString port = "80";
pos = addr.Find(':');
if (pos >= 0)
{
port = addr.Mid(pos + 1);
addr.Truncate(pos);
}
GetDlgItem(IDC_IP)->SetWindowText(addr.GetString());
if (port.GetLength() > 0)
GetDlgItem(IDC_PORT)->SetWindowText(port.GetString());
}
//////////////////////////////////////////////////////////////////////////
void Cgui_rpcDlg::OnDownloading(long long int content_length,
long long int total_read)
{
if (content_length > 0)
{
int nStept;
nStept = (int) ((total_read * 100) / (content_length));
m_wndMeterBar.GetProgressCtrl().SetPos(nStept);
}
CString msg;
msg.Format("<EFBFBD><EFBFBD> %I64d <20>ֽ<EFBFBD>", total_read);
m_wndMeterBar.SetText(msg, 1, 0);
}
void Cgui_rpcDlg::OnDownloadOver(long long int total_read, double spent)
{
CString msg;
msg.Format("<EFBFBD><EFBFBD> %I64d <20>ֽڣ<D6BD><DAA3><EFBFBD>ʱ %.3f <20><><EFBFBD><EFBFBD>", total_read, spent);
m_wndMeterBar.SetText(msg, 1, 0);
GetDlgItem(IDC_BUTTON_RUN)->EnableWindow(true);
}
void Cgui_rpcDlg::SetRequestHdr(const char* hdr)
{
if (hdr == NULL || *hdr == 0)
return;
m_reqCtlEdit.SetSel(0, m_reqCtlEdit.GetWindowTextLength());
m_reqCtlEdit.ReplaceSel(hdr);
}
void Cgui_rpcDlg::SetResponseHdr(const char* hdr)
{
if (hdr == NULL || *hdr == 0)
return;
m_resCtlEdit.SetSel(0, m_resCtlEdit.GetWindowTextLength());
m_resCtlEdit.ReplaceSel(hdr);
}