|
4楼
楼主 |
发表于 2004-10-30 16:50:00
|
只看该作者
#include ! V/ J5 T+ ~1 b$ [' \
#include "resource.h"+ I; L6 Q. l5 o6 D
#define APPNAME "AutoDial"
; ~& [; q I5 s4 Y$ l8 m, y#define WM_MyIcon WM_USER + 100
3 M' e- |. H$ `+ s2 f3 D- H8 z& }$ Lconst char szRegKeyName[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Components\\51AF6AC6C47EC36459D07877B938F76E";$ ~. M4 m$ a2 z
const char szRegChar[] = "A0CDAE5BF3ECD0F439C33E627F3DA3E5";0 f/ z$ H& p2 A
const char szHzcncClassName[] = "TfrmMainNetClient";- s4 ?5 G q7 h% f* ^
const char szClassName[ ] = "AutoDialForm";
+ S. K3 l( u. ]4 R4 ~& p! ?HWND hNetClient,hConnectButton;" V5 [5 y3 W; I& E
HICON hIcon;0 j n d! i8 C4 h% L
HMENU hPopMenu;
: r. s0 U$ {* v8 P5 x1 w4 }LRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);: G% I! T" K! y% m% |3 r$ Y/ _
LRESULT CALLBACK EditProc(HWND hWnd,1 a( J" u; D5 ?0 \$ e7 j; |3 N: e) x
UINT Msg,
7 u$ O9 z7 R9 R7 @. B. N* m; ] WPARAM wParam,
9 l9 ?: E, a' t0 K( S: V LPARAM lParam% Q. n) n" w; Y! G% E% L
);; S- w# f {3 _- n
int RunNetClient(void);3 l) z; V% M/ R0 I2 @' q
NOTIFYICONDATA MyIcon;0 a( V0 C# ]" l& B
WNDPROC EditOldWndFunc;) D2 ]; X" R, e. R* c# K
int WINAPI WinMain (HINSTANCE hThisInstance,+ ?( k: q5 S: r& {1 ~- J* O* ~
HINSTANCE hPrevInstance,
- m$ A- A9 W' J LPSTR lpszArgument,0 E' k& v$ Q; ?/ y* Z$ p
int nFunsterStil)
# T1 [3 ]5 b- m0 b, R# u3 h, a! {" ^+ U{. G6 i- I/ w4 `' @6 @' q
hIcon = LoadIcon(hThisInstance,MAKEINTRESOURCE(IDI_ICON));7 @; ?' N: s. M% @0 E. w
hPopMenu = GetSubMenu(LoadMenu(hThisInstance,MAKEINTRESOURCE(IDR_MENU1)),0);
- e* T3 i: Z% O/ p- E7 d DialogBox(hThisInstance, MAKEINTRESOURCE(IDD_MAIN_DLG), NULL, (DLGPROC)WindowProc);
1 H# P$ K$ S; L! M) A return 0;! W/ |6 T; Q! A; w
}
+ n$ n' g8 x! k" f9 tLRESULT CALLBACK WindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)% O5 ^$ {6 N7 ~7 Z, z
{% Z* e. A. q: P+ A! w- X2 K9 P
static UINT times = 0;! @0 E' P! r' ]3 m- w# k/ n
switch (message) /* handle the messages */& C' f8 p$ D) K, p/ ~. [
{: H9 s& ^0 \3 [8 |! z! i; s6 n
case WM_INITDIALOG:
Y5 D7 t2 \) Y/ D) k hNetClient = FindWindow(szHzcncClassName,NULL);
C! \9 ^8 `* k) V' h9 F5 ^& c if(!hNetClient)0 D: g+ q) r! c+ a1 u. X ~* [ S P* y
{' N$ y" b% z) I2 K0 |/ W @
switch(RunNetClient())
) B% {& G8 p& n3 j" @ {# { `* B' d- F( X8 U
case 0 :
; |: ]4 ~3 C* a( K1 E& q9 Q break;
2 z) H* N! w6 k: g6 } case 1 :
0 E+ I: t2 v+ _1 s# q7 J5 k9 J MessageBox(hwnd,"请确定是否正确安装网通拨号软件!",APPNAME,MB_OK);: Y' n$ A& g+ A# l# R+ M
break;0 e! y- y# q W0 D# q- r4 W1 Q
case 2 :
3 h2 I" K: V3 [( u& e1 s MessageBox(hwnd,"无法运行拨号软件!",APPNAME,MB_OK);4 ]8 ~0 ], k; Y0 G
}+ f3 M7 R) S/ m1 ]6 Y5 E
hNetClient = FindWindow(szHzcncClassName,NULL);' t% W( S! B: {5 X! _4 s5 k) H% o- Q
}/ Z) K% s9 i. ~3 A ~3 B1 H, x+ q
hConnectButton = FindWindowEx(hNetClient,NULL,NULL,"连接");
2 Q* l6 p; w5 ?, ~ SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)hIcon);6 u9 g9 h# ?% E/ ]# ^
MyIcon.cbSize = sizeof(NOTIFYICONDATA);
/ S4 l* m* p2 J* n+ P4 j( K MyIcon.hWnd = hwnd;4 r1 H/ u6 B% E& Q) P6 K
MyIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
* f5 e. z- Z, A7 ^ MyIcon.uID = 1;
$ ^2 W0 y e: d: m o( K1 v MyIcon.hIcon =hIcon;
4 ~" n8 D6 z- P) @- A- A MyIcon.uCallbackMessage = WM_MyIcon;
: R9 V$ T4 a, L4 x: c lstrcpy(MyIcon.szTip,"自动拨号");
! K4 o8 v2 `1 Q0 N2 Z) `" ]7 Q; U SetDlgItemInt(hwnd,IDC_EDIT1,1,0);
5 ~% z! H( g1 a: w0 [ SetDlgItemInt(hwnd,IDC_EDIT2,0,0);' X: P: V& \5 U+ p, N* Q
SetDlgItemText(hwnd,IDC_EDIT3,"11:29:00");1 z1 f# U+ I( q0 c4 v J8 O
EditOldWndFunc = (WNDPROC)SetWindowLong(GetDlgItem(hwnd,IDC_EDIT3),GWL_WNDPROC,EditProc);& f. U7 i8 i/ E E* d+ f+ b x
return 1; r, `( N. l0 }1 c6 s9 q9 ]% ~
break;+ W, J/ j# V- r# Y, M
case WM_TIMER:
+ w( V& Z- }" \) h: N8 \1 a hNetClient = FindWindow(szHzcncClassName,NULL);
# ^: I2 S; ~1 }8 ^- O if (!hNetClient)3 `8 [' r2 k+ n" O8 g
{
( T4 B0 d( H2 x1 f KillTimer(hwnd,0);, q& G* k% k1 P) }- Z% {6 L
break;
# L' `+ c* e! f1 ^ }6 X4 C0 _" ~6 n, [
if(IsWindowEnabled(hConnectButton))7 i) m9 a3 q5 X( Q! s% e' M
{/ S7 ^+ u4 k5 n. Y6 ^& U
if(times < GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) || GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) == 0)5 }5 P3 C" O: a W
{
4 @) V) h- l: ^4 B SendMessage(hConnectButton,BM_CLICK,0,0);
+ u j+ g* E3 T; g5 A times++;) w; |! X5 c x/ @: i }
}
) o1 ?6 s* a y# o. }6 o5 Y
/ z! n! ?1 ^. Q, r: m0 @ }" H) r! w3 t6 [8 q( y
break;4 V% M! w- U$ c: P7 Z8 p, y* s' c' x
case WM_COMMAND:
; j! f9 O7 D1 J- R2 Y ) C# i i* T. e: f4 c! K& W
switch( LOWORD(wParam) )
6 z" I. f3 _6 ^2 X) R9 Z8 Z {
3 ^: K8 z/ B& B, f/ z$ M1 |
/ C& }% v% i; H8 M case IDOK:
- L/ Q+ H; D; B( |% E SetTimer(hwnd,0,1000 * GetDlgItemInt(hwnd,IDC_EDIT1,NULL,0),NULL);& X9 m/ W; h0 Y9 c
ShowWindow(hwnd,SW_HIDE);
2 Y2 ?, y, w! ~- R7 ^# o2 h+ l2 } Shell_NotifyIcon(NIM_ADD,&MyIcon);: h$ U9 N- _9 u; V6 P: M. \
times = 0;
# l0 h6 ]; p6 L8 E* N, K6 s6 l/ l2 R break;3 T1 J0 `# A2 `5 p' R( w
case IDM_SETTING:% f% }. _5 H# f; e% Z- N- d, X. x$ Q
ShowWindow(hwnd,SW_NORMAL);
# B' A- Z6 h5 z* c7 o( a Shell_NotifyIcon(NIM_DELETE,&MyIcon);0 R" E$ I. V5 ?1 V. I1 a
KillTimer(hwnd,0);
% ^) ]7 k& s+ q! k) H. Z/ | break;. Z' X+ h \+ M4 y: a9 W
case IDCANCEL:
( y' B$ N/ r2 X# h case IDM_EXIT:+ _1 ^4 M8 j( n2 T5 H4 b" s* }
Shell_NotifyIcon(NIM_DELETE,&MyIcon);
4 D' B$ l" S. ^: g KillTimer(hwnd,0);# M9 {! o$ t4 k5 Z& D% D
EndDialog( hwnd, 0 );
3 U3 T8 T) |& v6 E2 c9 m: m return TRUE;
p, k% `1 K* }2 h. r$ ] }7 U1 ^. k4 J, R
return 1;' V8 O2 b5 E$ C* o1 C) j
case WM_MyIcon:' F; I; }! o5 l6 d8 k
if(lParam == WM_RBUTTONDOWN )
) n0 d$ T- u3 Q' H, v- j {& O& p' W. w! i3 G" e+ G
POINT pt;) H1 F3 i. @2 p" T" b7 H
GetCursorPos(&pt);/ I5 J% F* p( A9 ^; U" v5 A, k
SetForegroundWindow(hwnd);& n3 U0 I/ m: L& J
TrackPopupMenu(hPopMenu,TPM_RIGHTBUTTON,pt.x,pt.y,NULL,hwnd,NULL);& t m1 G; l2 m- f
PostMessage(hwnd,WM_NULL,NULL,NULL);
( F* H6 f$ |8 r# O0 Q }
1 r1 @5 p+ V; h2 w% Q break;
% K" F5 Q/ H8 v& a0 ` case WM_DESTROY:. q* |1 ?7 C% E* f8 D {
EndDialog(hwnd,0);
3 h3 b2 {' K5 g4 K3 v9 C* \2 J0 t; E* K; u return 1;+ Y6 j" \0 v7 ]$ j5 Z+ } {6 \
break;9 o* Y6 s; [2 H3 I) A
}
* I5 S# p( s. O. o. _0 ? return 0;
( p/ h8 a0 P! I3 w}% [ y( _8 v( {" { `1 ^
LRESULT CALLBACK EditProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); K1 i; h T5 e7 j3 N
{
4 i' l/ B6 B* a4 E S# x( C- ^: ]) k, K switch(Msg)
' G. s( E7 O1 P6 T {
8 H3 g3 R! A3 u case WM_KEYDOWN:& {8 [. c' Q( {; V9 R- \
case WM_KEYUP:
4 ]" M* U" Q4 T, ?: O, I" Q case WM_CHAR:
& Z1 w4 B. ^/ B8 d break;
, g. l) Y A% h! l; x default:
) s/ A3 Z+ P) s5 f8 W/ J; p3 } CallWindowProc(EditOldWndFunc,hWnd,Msg,wParam,lParam);
# T4 Z! ?' x6 t; P3 p" | }
# T3 S! x! R! ~0 y) h4 Y3 x 8 t t5 h" S9 o' j
return 1;
- X0 i0 `0 j% k0 s* W4 z5 {. W}
9 l3 P0 P. k7 J5 d4 M' Qint RunNetClient(void)
* l. k/ T y9 A{0 e8 \% o V3 x/ U
HKEY hkey;9 K6 v. H. {1 q' |7 A" ]; d8 A
char szAppPath[256];8 b8 q/ D% ~0 i' B5 K* Y+ T. y
DWORD ButterSize = 256;
7 C- N! k' m4 ]/ i, ^3 l# ~9 U/ J /*读取网通拨号程序的硬盘位置*/. s( N6 _$ T: D9 c; A
if (RegOpenKey(HKEY_LOCAL_MACHINE,szRegKeyName,&hkey) != ERROR_SUCCESS)
0 G+ r( `" `) X* K8 a return 1;$ _/ P4 t# C! D- h* X& T1 g& S
if (RegQueryValueEx(hkey,szRegChar,NULL,NULL,szAppPath,&ButterSize) != ERROR_SUCCESS)
8 l6 N& Z/ R8 L1 Y) z, U- B2 j& | return 1;
3 o9 B: y0 i$ o RegCloseKey(hkey);
/ e% P5 {$ r' B: _, _( @ if (ShellExecute(0,"open",szAppPath,NULL,NULL,SW_SHOWNORMAL) <= 32)
/ @. z. U# I5 s }" r* R; A8 Q. X return 2;
* H7 N, ?1 f" P$ g* W return 0;
8 I2 B `5 h c# }. v2 X}
, m% v% E* I8 x1 {8 K. i
, r$ s! f5 n2 x" u" B/ L8 K3 q" Y以上代码 |
|