|
4楼
楼主 |
发表于 2004-10-30 16:50:00
|
只看该作者
#include
4 G0 [/ b& P1 `, O' b#include "resource.h"$ J% |" q$ I+ m: z! [* |
#define APPNAME "AutoDial"# W" b! s. l6 G1 N1 s( J& M
#define WM_MyIcon WM_USER + 100
3 M& `. A" r+ p* W! Bconst char szRegKeyName[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Components\\51AF6AC6C47EC36459D07877B938F76E";
9 u& p& E1 _ z7 }' @1 X5 \const char szRegChar[] = "A0CDAE5BF3ECD0F439C33E627F3DA3E5";: o9 m+ _( H; ~0 }: C2 G `
const char szHzcncClassName[] = "TfrmMainNetClient";
) a- ~$ ~3 {3 m( c4 \3 G+ Nconst char szClassName[ ] = "AutoDialForm";/ E1 n7 v6 w) _( K( X: x
HWND hNetClient,hConnectButton; O4 y6 Y, b$ a$ M7 s9 Q9 Q
HICON hIcon;
& a4 W: v+ k2 {! f* f0 h3 K IHMENU hPopMenu;3 K9 u9 t; U' X
LRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);" ]8 X: w) \5 H' ?8 h
LRESULT CALLBACK EditProc(HWND hWnd,
: [1 z1 p6 U1 v, [. u6 F2 u' B UINT Msg,0 c& P: h6 f$ Y# a* i
WPARAM wParam,5 O6 X5 z: _3 Q/ |9 c- Z3 a- z
LPARAM lParam$ b- V' a3 I5 _8 L& @" O4 i* c
);' j# L. U$ S4 j" W s
int RunNetClient(void);
3 z5 e* G) e2 Z6 y _) k" Z8 eNOTIFYICONDATA MyIcon;
& s' a1 W% X9 p1 \7 xWNDPROC EditOldWndFunc;1 E7 i. I" \# J4 k8 p7 U
int WINAPI WinMain (HINSTANCE hThisInstance,+ _- j- @3 Y) N' r3 w9 x9 [ v
HINSTANCE hPrevInstance,
6 y9 K( `3 V1 {8 b LPSTR lpszArgument,
* q) h$ T# u- v- K5 M2 Y int nFunsterStil)3 e; {9 k( j% p
{
7 F& K7 Q7 o3 U% @) ~ hIcon = LoadIcon(hThisInstance,MAKEINTRESOURCE(IDI_ICON));3 q5 z0 v* d$ R V* M2 J
hPopMenu = GetSubMenu(LoadMenu(hThisInstance,MAKEINTRESOURCE(IDR_MENU1)),0);+ ~* C& A/ P, n* a( l; L4 [
DialogBox(hThisInstance, MAKEINTRESOURCE(IDD_MAIN_DLG), NULL, (DLGPROC)WindowProc);# D- w2 B- ^- ?1 _( D; p
return 0;
& T9 k$ ^9 l6 Z! M, K}9 q6 ` N$ w) G0 C" h
LRESULT CALLBACK WindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
) a1 }5 @5 t2 ?{, C# _9 Z3 }4 W: k6 v& S2 K9 a8 C
static UINT times = 0;$ ?1 I, G) G- j+ y0 C, A
switch (message) /* handle the messages */* c; z% G- h' \2 V0 c9 m" ~
{) k9 K7 r& `' w1 q1 N: V5 w4 {- C
case WM_INITDIALOG:8 j) u+ f9 |8 H, ?6 n
hNetClient = FindWindow(szHzcncClassName,NULL);
4 J; j& i" g+ M$ P9 V5 D( ]% y if(!hNetClient)
% a' ~) i/ k2 E6 l( ~" g {
@" Z$ ]' t; O* }. O6 S2 ^ switch(RunNetClient())
2 z# T1 `7 a' t {" M+ j& [3 i0 Q- J9 {& d
case 0 :1 L8 o% ^# e- M. X
break;
* x) m+ |4 p) Y% z* n8 N5 L$ R case 1 :
0 ?2 i" p: I2 m* g8 m6 e MessageBox(hwnd,"请确定是否正确安装网通拨号软件!",APPNAME,MB_OK);" _' [4 S( I' u9 i2 T: l
break;
. V2 \ ^4 J" P# W case 2 : K4 r3 P/ m: \ b
MessageBox(hwnd,"无法运行拨号软件!",APPNAME,MB_OK);
4 R( r( a1 q9 r( t- ~% u }" y* o$ t5 `: y7 r5 w& ?: u0 ^
hNetClient = FindWindow(szHzcncClassName,NULL);
. j7 s0 n/ D' B3 Q+ R }
" I7 S3 \+ t v7 a' p% o hConnectButton = FindWindowEx(hNetClient,NULL,NULL,"连接");
- ? f/ Q+ j ]" S- C SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)hIcon);. u. w2 a: K- x5 b! G
MyIcon.cbSize = sizeof(NOTIFYICONDATA);9 V; }, U, F8 H, b( x. N3 |
MyIcon.hWnd = hwnd;
! K5 }8 }" j# x/ z! ?' ~( c! r: G MyIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
% e9 t% n2 `4 T3 D MyIcon.uID = 1;# `( D' o8 s3 h; G: t* F
MyIcon.hIcon =hIcon;
, \& f# I$ Q+ c/ Q3 S& g MyIcon.uCallbackMessage = WM_MyIcon;
/ e( N9 b, d# [1 A6 L lstrcpy(MyIcon.szTip,"自动拨号");) P4 L% _, a5 y% g }: [
SetDlgItemInt(hwnd,IDC_EDIT1,1,0);
f4 y5 d+ h7 M; ~) D SetDlgItemInt(hwnd,IDC_EDIT2,0,0);6 e0 ]* q j$ }1 I+ e- M9 T6 M
SetDlgItemText(hwnd,IDC_EDIT3,"11:29:00");
' i6 S; c. k! Y3 W8 o2 F+ K EditOldWndFunc = (WNDPROC)SetWindowLong(GetDlgItem(hwnd,IDC_EDIT3),GWL_WNDPROC,EditProc);8 D' y. S7 t2 ^$ J
return 1;
& G7 a6 q( }5 N break;- R6 @4 @3 Y6 J3 y- ` C, {% i
case WM_TIMER:
9 M# F' r$ @, S hNetClient = FindWindow(szHzcncClassName,NULL);1 i. S" Q) f0 a) ? R
if (!hNetClient)
2 K6 G% c4 b) |7 O8 A! k; K {( D" v9 O& z$ Z- v+ N( |7 W
KillTimer(hwnd,0);8 h7 K8 N9 v; |4 a G5 G" s
break;( U- e7 V( b( V& t+ K1 l3 m7 U4 [/ }
}
: ^: F& C% ]+ i( _5 F if(IsWindowEnabled(hConnectButton)), c9 M% O# F5 s. g7 I# c
{5 g* ~: s7 V& q- ]/ ]5 h
if(times < GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) || GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) == 0)* J& L# H* v+ I; W1 W# g
{: e& g- _9 y# I' D+ S
SendMessage(hConnectButton,BM_CLICK,0,0);6 a: G* H- E1 X
times++;
$ U) {" T% M( g0 U) l }
! U+ p( X! X! y" ]# ~ + Y2 A- b2 [! n& h9 ^
}
8 K: m( L" |" K. h break;
0 K8 f2 y) J' r% s case WM_COMMAND:0 E8 M: ]' X3 g3 B/ O2 ~! r1 J' h
# s1 } `8 i+ Y' d: D6 q
switch( LOWORD(wParam) )
& {& u7 e+ S# g# `- D8 ^0 f {) _$ |3 F/ F" {1 P# D: E. r
" \" f7 C' z% [) u: \/ ~
case IDOK:$ v# N0 e( `' q. p+ K
SetTimer(hwnd,0,1000 * GetDlgItemInt(hwnd,IDC_EDIT1,NULL,0),NULL);
; w! l/ G# P& Y$ k$ p0 G8 S ShowWindow(hwnd,SW_HIDE);
, Z) E4 M# ?& t+ N Shell_NotifyIcon(NIM_ADD,&MyIcon);% n9 O' W" {9 J' ^3 R
times = 0; m' ?# z: W0 l3 ]2 \0 U }
break;6 |' p3 @: C$ @
case IDM_SETTING:0 V n( E' s0 Z4 s! A w
ShowWindow(hwnd,SW_NORMAL);
5 F7 P1 w+ }2 E- {$ E Shell_NotifyIcon(NIM_DELETE,&MyIcon);) k8 R$ E. X9 i+ v3 i" A$ b X K$ ?; V
KillTimer(hwnd,0);
, ]9 C V& ^" ` break;
! U3 { \. O* p5 K6 R case IDCANCEL:
# E" A' y( I* C0 Q% U case IDM_EXIT:. t+ e) U6 y; X& F8 n
Shell_NotifyIcon(NIM_DELETE,&MyIcon);: N3 v1 l$ y# J# K
KillTimer(hwnd,0);
O A0 y: c& V4 S- w. o EndDialog( hwnd, 0 );
. ^/ ~6 I# k7 {; D. Y% A return TRUE;
6 t2 g' D$ M: M }" e, Q1 B% O6 e' q
return 1;
! b7 D; ^! E" d2 U5 u7 x) D" A3 m case WM_MyIcon:0 U/ x/ f$ h# X5 i: R- r
if(lParam == WM_RBUTTONDOWN )2 [# B& k9 P" Q2 W/ a1 X. @0 T3 F
{
$ d8 l$ [* n: a9 I( s4 p4 c POINT pt;8 E6 t6 f9 t7 o' p8 n6 D T w$ i
GetCursorPos(&pt);+ T8 I" {) L$ I5 i
SetForegroundWindow(hwnd);
4 x M; N _1 [ TrackPopupMenu(hPopMenu,TPM_RIGHTBUTTON,pt.x,pt.y,NULL,hwnd,NULL);2 Z+ b( b/ e8 ?7 S! U; ?
PostMessage(hwnd,WM_NULL,NULL,NULL);
+ |- Q& F) k" J8 M8 E/ j }
& z/ d2 o+ g" s break;
7 `0 W0 a) l/ o4 `) [ case WM_DESTROY:0 |# n8 K4 b0 V
EndDialog(hwnd,0);; o6 C4 j% |8 w! ?- z
return 1;8 E% P! |$ |, q! T _% J
break;
' f) c9 f. O5 M }6 b2 a: f, q. V" Y
return 0;
+ ^ I, g1 |6 _7 z0 O}
3 V5 M1 c0 }1 C5 OLRESULT CALLBACK EditProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
o U1 [$ O9 h7 i8 u& C$ M1 M{1 n0 Q$ k( s+ W; `) H. O- n
switch(Msg)
! |- d J: P& s/ R: v( [4 \* U, x {
; V8 X1 D' U" [2 T* p1 I case WM_KEYDOWN:
8 x$ n( r4 R! W# T5 E& F q- P case WM_KEYUP:2 v& G: A' k% o8 @# e
case WM_CHAR:1 w N# x) J5 k' I8 W/ Z
break;
4 ]! u' d* t' z* j3 J9 r9 W, i default:
# e* c& P5 @7 M9 Y$ V+ h CallWindowProc(EditOldWndFunc,hWnd,Msg,wParam,lParam);2 i6 U3 U1 }- W J2 j
}
8 W' e1 Q1 b, P$ ? K
! W1 n) k) e% `' } @% | return 1;+ s. j* ]/ M: n
}
4 Z1 b7 F7 a5 R- s" l- M% Dint RunNetClient(void)
/ B6 ^' }, Y& g5 t# |# E7 q; }! T) r{- W0 |6 R3 N% o8 T4 s P [3 k
HKEY hkey;6 {; y* p# R3 C7 _9 G$ z
char szAppPath[256];8 ?9 t& c% S) b3 ]- a: p
DWORD ButterSize = 256;
: d8 O# S/ z+ j* @) w3 N /*读取网通拨号程序的硬盘位置*/- O3 k" {( m* X: q! B
if (RegOpenKey(HKEY_LOCAL_MACHINE,szRegKeyName,&hkey) != ERROR_SUCCESS)
. ^1 N( Q$ P( N+ g) B9 r return 1;3 ?$ `% E0 j [1 R, R
if (RegQueryValueEx(hkey,szRegChar,NULL,NULL,szAppPath,&ButterSize) != ERROR_SUCCESS)/ ]; |8 c7 ?8 ~
return 1;# C/ ]3 J3 a5 n: t' C
RegCloseKey(hkey);
# N( d+ A. l% S y, s if (ShellExecute(0,"open",szAppPath,NULL,NULL,SW_SHOWNORMAL) <= 32)2 }* F4 \! ~/ M# ~+ I I9 s
return 2;2 P4 B0 L# K8 L$ b9 e$ O2 q, d
return 0;
/ }8 c) P$ F, A2 V4 B: c! q}' _0 Y9 ^ X, L' v$ g1 {9 ?3 `
) w1 y. b; v8 r, z" r4 p3 O% ~( P以上代码 |
|