📄 proxy.cpp
字号:
/******************************************************************************
Module: Proxy.cpp
Notices: Copyright (c) 2006 Lenus Margin
******************************************************************************/
#include "Proxy.h"
#include "SetCancelProxy.h"
#include "FindProxy.h"
NOTIFYICONDATA note;
HMENU hPopupMenu;
HINSTANCE g_hinstExe;
extern char *FXPIni;
extern char *NETTransport;
extern char *MYIEIni;
void CenterWindow(HWND hwnd)
{
RECT stRectDeskTop,stRectWin;
LONG Width,Height;
GetWindowRect(hwnd,&stRectWin);
GetWindowRect(GetDesktopWindow(),&stRectDeskTop);
Height = stRectWin.bottom - stRectWin.top;
Width = stRectWin.right - stRectWin.left;
MoveWindow(hwnd,(stRectDeskTop.right - Width)/2,(stRectDeskTop.bottom - Height)/2,Width,Height,FALSE);
}
///////////////////////////////////////////////////////////////////////////////
void DisplayMsg(HWND hwnd,char *msg)
{
HWND hHistory;
int lent;
if(msg){
hHistory = GetDlgItem(hwnd,IDC_HISTORY);
lent = GetWindowTextLength(hHistory);
SendMessage(hHistory,EM_SETSEL,lent,lent);
SendMessage(hHistory,EM_REPLACESEL,FALSE,(LPARAM)msg);
}
}
///////////////////////////////////////////////////////////////////////////////
BOOL Dlg_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) {
char *RestoreString="取消代理(&R)";
char *ExitString="退出程序(&E)";
chSETDLGICONS(hwnd, IDI_PROXY);
// Initialize the dialog box by disabling all the nonsetup controls.
CheckDlgButton(hwnd,IDC_IE,BST_CHECKED);
CheckDlgButton(hwnd,IDC_FLASH,BST_CHECKED);
CheckDlgButton(hwnd,IDC_CLOSECANCEL,BST_CHECKED);
// Initialize the edit control.
SetDlgItemText(hwnd, IDC_IP, "10.10.139.253:8080");
// Initialize the Dialog position
CenterWindow(hwnd);
// Initialize the ICON menu
hPopupMenu = CreatePopupMenu();
AppendMenu(hPopupMenu,MF_STRING,IDM_CANCEL,RestoreString);
AppendMenu(hPopupMenu,MF_STRING,IDM_EXIT,ExitString);
return(TRUE);
}
///////////////////////////////////////////////////////////////////////////////
void SET(HWND hwnd)
{
if(!CheckIP(hwnd)){
DisplayMsg(hwnd,"IP地址格式不正确");
return;
}
if(!UpdataProxyIP(hwnd))
if(IDCANCEL == MessageBox(
hwnd,
"IP地址没有成功更新,启用请点OK",
"注意!",
MB_OKCANCEL))
return;
if(SetProxy(hwnd))
DisplayMsg(hwnd,"已经设置代理IP\n");
else
DisplayMsg(hwnd,"设置失败\n");
}
void CANCEL(HWND hwnd)
{
if(CancelProxy(hwnd))
DisplayMsg(hwnd,"已经取消设置代理IP\n");
else
DisplayMsg(hwnd,"取消设置代理IP失败\n");
}
void FIND(HWND hwnd)
{
if(FindProxy(hwnd))
DisplayMsg(hwnd,"已经找到代理IP\n");
else
DisplayMsg(hwnd,"找不到代理IP\n");
}
void TEST(HWND hwnd)
{
int ret;
ret = TestIP(hwnd);
if( ret == -1)
DisplayMsg(hwnd,"此IP地址错误\n");
else if(ret == 0)
DisplayMsg(hwnd,"此代理已经时效,你可以搜索其他IP\n");
else if(ret == 1)
DisplayMsg(hwnd,"此代理有效,你可以继续使用\n");
}
void FXPPATH(HWND hwnd)
{
static char name[MAX_PATH];
strcpy(name,"FlashFxp.ini");
if(path(hwnd,name))
FXPIni = name;
}
void NETTRANSPATH(HWND hwnd)
{
static char name[MAX_PATH];
strcpy(name,"Admin' NetTransport.proxy");
if(path(hwnd,name))
NETTransport = name;
}
void MYIEPATH(HWND hwnd)
{
static char name[MAX_PATH];
strcpy(name,"config.ini");
if(path(hwnd,name))
MYIEIni = name;
}
void Dlg_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) {
switch (id) {
case IDC_SET:
// SET The Proxy IP and use it.
SET(hwnd);
break;
case IDC_CANCEL:
// Cancel the Proxy,but the IP do not change
CANCEL(hwnd);
break;
case IDC_TEST:
// Test the IP is value ?
TEST(hwnd);
break;
case IDC_FXPPATH:
// Set the path of FXP
FXPPATH(hwnd);
break;
case IDC_NETTRANSPATH:
// Set the path of FXP
NETTRANSPATH(hwnd);
break;
case IDC_MYIEPATH:
// Set the Path of MYIE
MYIEPATH(hwnd);
break;
}
if(hwndCtl == 0)
{
Shell_NotifyIcon(NIM_DELETE,¬e);
if(id == IDM_RESTORE)
{
ShowWindow(hwnd,SW_RESTORE);
}
else if(id == IDM_CANCEL)
{
ShowWindow(hwnd,SW_RESTORE);
CANCEL(hwnd);
}
else
DestroyWindow(hwnd);
}
}
///////////////////////////////////////////////////////////////////////////////
void Dlg_OnClose(HWND hwnd) {
if(IsDlgButtonChecked(hwnd,IDC_CLOSECANCEL))
CANCEL(hwnd);
DestroyMenu(hPopupMenu);
EndDialog(hwnd,NULL);
}
void Dlg_OnSize(HWND hwnd,UINT wP, int LlP, int HlP)
{
if(wP == SIZE_MINIMIZED)
{
note.cbSize = sizeof NOTIFYICONDATA;
note.hWnd = hwnd;
note.uID = IDI_ICON;
note.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
note.uCallbackMessage = WM_SHELLNOTIFY;
note.hIcon = LoadIcon(g_hinstExe,MAKEINTRESOURCE(IDI_PROXYTASK));
lstrcpy(note.szTip,"Proxy Prober");
ShowWindow(hwnd,SW_HIDE);
Shell_NotifyIcon(NIM_ADD,¬e);
}
}
///////////////////////////////////////////////////////////////////////////////
INT_PTR WINAPI Dlg_Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
POINT pt;
switch (uMsg) {
case WM_SHELLNOTIFY:
if(wParam == IDI_ICON){
if(lParam==WM_RBUTTONDOWN){
GetCursorPos(&pt);
SetForegroundWindow(hwnd);
TrackPopupMenu(hPopupMenu,TPM_RIGHTALIGN,pt.x,pt.y,NULL,hwnd,NULL);
PostMessage(hwnd,WM_NULL,0,0);
}
else if(lParam==WM_LBUTTONDBLCLK){
SendMessage(hwnd,WM_COMMAND,IDM_RESTORE,0);
}
}
break;
chHANDLE_DLGMSG(hwnd, WM_SIZE, Dlg_OnSize);
chHANDLE_DLGMSG(hwnd, WM_INITDIALOG, Dlg_OnInitDialog);
chHANDLE_DLGMSG(hwnd, WM_COMMAND, Dlg_OnCommand);
chHANDLE_DLGMSG(hwnd, WM_CLOSE, Dlg_OnClose);
}
return(FALSE);
}
///////////////////////////////////////////////////////////////////////////////
int WINAPI _tWinMain(HINSTANCE hinstExe, HINSTANCE, PTSTR pszCmdLine, int) {
g_hinstExe = hinstExe;
DialogBox(hinstExe, MAKEINTRESOURCE(IDD_PROXY), NULL, Dlg_Proc);
return(0);
}
//////////////////////////////// End of File //////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -