|
4楼
楼主 |
发表于 2004-10-30 16:50:00
|
只看该作者
#include 6 G: Z/ }. J: P2 M* s# Y% W
#include "resource.h"
$ q; J2 U( M- I* O+ Y: @4 ^" `#define APPNAME "AutoDial"# z# {& p) l7 b. u& Q- B, S7 H s
#define WM_MyIcon WM_USER + 100& W, u6 g# \" Y* Q# l- c. {* \
const char szRegKeyName[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Components\\51AF6AC6C47EC36459D07877B938F76E";
' l1 f: z3 M3 j X$ h8 W' O# Dconst char szRegChar[] = "A0CDAE5BF3ECD0F439C33E627F3DA3E5";
, Q3 `; Q' U" @ q- Lconst char szHzcncClassName[] = "TfrmMainNetClient";; f! c; [: T* p
const char szClassName[ ] = "AutoDialForm";) X1 k5 u8 j- l; a. T/ {
HWND hNetClient,hConnectButton;
6 N; |+ l7 o/ f$ r5 lHICON hIcon;8 d- |, k& l& K+ Y
HMENU hPopMenu;
6 |5 P+ ~( {4 s9 \' fLRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);
/ a/ Y; g6 y: g ^- z0 e1 o4 E. s6 ?LRESULT CALLBACK EditProc(HWND hWnd,
; y5 }+ }2 M4 k" x UINT Msg,( u4 K& y2 b: R' H$ }- d5 |
WPARAM wParam,
\ }0 a8 o. l8 C L LPARAM lParam7 i$ X6 i3 _. R: @: Y
);2 j7 G( o: k \2 [3 k& I
int RunNetClient(void);
5 i7 Y% s7 K% e7 y" iNOTIFYICONDATA MyIcon;
' u& H4 ^5 S7 v! L9 gWNDPROC EditOldWndFunc;7 S0 ]8 V+ W0 n& S0 [
int WINAPI WinMain (HINSTANCE hThisInstance,
, q* B% ^# I- X( U) O8 l/ ? HINSTANCE hPrevInstance,0 ~' u) s0 d0 H( m
LPSTR lpszArgument,& H! ?% \6 x, e
int nFunsterStil)
* J' h7 v9 [! [: v7 j{& Z3 \# D* O# _2 p8 F
hIcon = LoadIcon(hThisInstance,MAKEINTRESOURCE(IDI_ICON));3 e% Q: y& x M' ?- V2 m
hPopMenu = GetSubMenu(LoadMenu(hThisInstance,MAKEINTRESOURCE(IDR_MENU1)),0);
( |/ ~2 f2 r1 [$ L& O DialogBox(hThisInstance, MAKEINTRESOURCE(IDD_MAIN_DLG), NULL, (DLGPROC)WindowProc);$ n6 a+ g& _7 Z2 x* i# n
return 0;
z; Z& f) x6 t0 J}1 t! X& J. O( M; y ?
LRESULT CALLBACK WindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
! N2 g! b4 l% g& Q/ P{
6 r, X. i$ |& x; Q' K' c/ A0 e static UINT times = 0;2 T7 u* M. P7 c) c
switch (message) /* handle the messages */
" T& c) k! G2 T) P9 ^) N4 H {* H& `# W4 ]. o% r# k1 Y+ f' B
case WM_INITDIALOG:5 ]5 U% w' h' G( |6 g4 [& F
hNetClient = FindWindow(szHzcncClassName,NULL);1 v, E9 B6 S8 v1 d3 m
if(!hNetClient)
- V( E. ]) ?0 ]$ B: ?1 @( _: T {
8 i' m6 D4 o' P( ~ switch(RunNetClient())" K7 {7 F% S; O& a" [
{6 d+ B1 d* @" D
case 0 :( o+ E5 o y/ c
break;
0 J' y t8 M0 Y7 j: M1 _7 [% b- T case 1 :3 R8 v v1 ~# Y1 ~( H: W2 n, z
MessageBox(hwnd,"请确定是否正确安装网通拨号软件!",APPNAME,MB_OK);/ w4 }9 I# g0 q r
break;% }; ~' d5 w9 R, \( d: E6 \( y0 [. `
case 2 :
! i% K# G( \* `% [- g+ n# @ MessageBox(hwnd,"无法运行拨号软件!",APPNAME,MB_OK);
2 U' e3 I! p* n }& e+ [2 ?3 y! H, W% L
hNetClient = FindWindow(szHzcncClassName,NULL);
' b8 e$ Y- }7 l7 J) F }
" X. U9 U4 W( T6 ]1 ~9 P hConnectButton = FindWindowEx(hNetClient,NULL,NULL,"连接");
+ S1 z( q8 R; B% Q SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)hIcon);
0 {$ f$ ]/ q; q3 ?( k$ }1 B MyIcon.cbSize = sizeof(NOTIFYICONDATA);, ?* v: H/ ~! _1 ^
MyIcon.hWnd = hwnd;
3 ^3 U5 p7 a, p+ c/ N9 S MyIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;# C/ C# ^3 M; k* h
MyIcon.uID = 1;+ g) n# A2 [) g: x+ C, R7 w
MyIcon.hIcon =hIcon;
' S9 S9 Q3 {5 ?: k MyIcon.uCallbackMessage = WM_MyIcon;
( q& ]/ A' l& o0 L- O) o' F lstrcpy(MyIcon.szTip,"自动拨号");( Z# l5 w! L/ @ b
SetDlgItemInt(hwnd,IDC_EDIT1,1,0);
+ j" p7 M& ]4 a. g0 a SetDlgItemInt(hwnd,IDC_EDIT2,0,0);
. M; @2 H! g P6 I7 ?- Q) ]( @( h3 H SetDlgItemText(hwnd,IDC_EDIT3,"11:29:00");
. Z6 X; q6 [0 _, s5 v" [! k- ?, U$ E EditOldWndFunc = (WNDPROC)SetWindowLong(GetDlgItem(hwnd,IDC_EDIT3),GWL_WNDPROC,EditProc);# W0 J1 g1 k" |+ B/ _* A% e
return 1;
' B) o" t, [' J: _, }/ h; n. Z break;
5 e% P# L0 p1 }' q5 F7 Y+ ^ case WM_TIMER:
! R4 K) R" c4 W* L- y$ ? hNetClient = FindWindow(szHzcncClassName,NULL);+ S: u4 Q# G; n/ ]
if (!hNetClient)& O+ ~! x+ p g
{
3 f1 g7 X) `! J% _2 J/ X1 v7 A2 | KillTimer(hwnd,0);. c: z- e' }& \, Q" ^
break;' p2 c; p h h7 [1 j7 g
}5 D+ I+ Q, l; Q
if(IsWindowEnabled(hConnectButton))7 i- q* T! R* o" d$ S
{: Q( p( d* Q; n N
if(times < GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) || GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) == 0)
: O* ~! n/ X0 p1 p {8 s {
, ?' n9 k2 g5 I/ K% o SendMessage(hConnectButton,BM_CLICK,0,0);' @9 Y6 q) N a4 q i
times++;
4 `. G9 h9 ^2 i1 x! x7 b! _ }7 Q' l9 ~4 O/ a! L
# X# t7 v- G8 {: V. ?8 Z% y/ S# A
}. b7 l% a/ M) z% ~% o
break;% v- R2 q$ |7 i' U% m: k" o0 P
case WM_COMMAND:8 O" s4 d' w& l6 \# W8 N
2 `" e" l3 f7 B$ U switch( LOWORD(wParam) )( `) d3 U6 {1 y+ y8 \, f
{ h2 Q! T2 P# l" N1 o
! H# Y! T" U7 b/ } case IDOK:
7 K2 s- r3 i# X+ p SetTimer(hwnd,0,1000 * GetDlgItemInt(hwnd,IDC_EDIT1,NULL,0),NULL);, `- \. G$ H7 i+ l
ShowWindow(hwnd,SW_HIDE);2 t: w- R& @: V4 J% I% j
Shell_NotifyIcon(NIM_ADD,&MyIcon);) y. S1 E3 t" D: i# q5 ^
times = 0;, u1 }8 B- Y0 Z6 C0 `! ]
break;
5 g9 h* k" v8 K. d* U' B, T case IDM_SETTING:5 E# L6 t+ N3 y
ShowWindow(hwnd,SW_NORMAL);+ Y) E& J/ b' Z8 r
Shell_NotifyIcon(NIM_DELETE,&MyIcon);- F; u# K' f4 T/ ]! i$ T3 d
KillTimer(hwnd,0);
7 @1 J# b' i$ a/ K break;
B6 Z g- D# R1 w0 f& h! ] case IDCANCEL:' P! `& v, T7 d1 r5 d5 L% P
case IDM_EXIT:
4 W" ^7 z$ A( A4 P) ?1 r X Shell_NotifyIcon(NIM_DELETE,&MyIcon);- ~) Y& R# g, U2 ]" q
KillTimer(hwnd,0);
l6 }0 I. M& z EndDialog( hwnd, 0 );2 g" ?' m& |5 Y) ^( P# z) ~
return TRUE;
% P4 t) M* Y% _' d& J }9 @3 H) N- Z' {
return 1;
" e8 K: ~1 _! r3 \ case WM_MyIcon:7 P( b7 Y) U0 ]% I1 l
if(lParam == WM_RBUTTONDOWN )
1 {& V/ N' Q+ S( M& _& ?, O0 @1 t: G7 I- W {
( r$ h! h, z- l! J# e4 |8 L POINT pt;9 ]* y" L4 O+ x5 V
GetCursorPos(&pt);+ r9 J3 I- j/ V- E3 a
SetForegroundWindow(hwnd);
9 H' R& t0 W7 N& E! n0 T8 Y TrackPopupMenu(hPopMenu,TPM_RIGHTBUTTON,pt.x,pt.y,NULL,hwnd,NULL);
; k; n, f! n' D$ k' ^4 A. N PostMessage(hwnd,WM_NULL,NULL,NULL);
1 g. f, v8 v+ u1 W7 P ]. `$ f }
8 K' v3 R* J6 w, y break;
* T0 h9 U2 O# G& ]+ X7 _/ a" a# f case WM_DESTROY:
2 v9 n' Q* @# p EndDialog(hwnd,0);
. Z4 j! W" F# I( `: W; G return 1;
v" c9 W2 V( w+ f) P break;/ o4 p2 W4 V- p
}. S8 d+ o* p0 a0 R1 k6 q- T
return 0;/ P( m4 B3 b. R
}
: h. k' x- ~# t9 xLRESULT CALLBACK EditProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
5 ?- s: M( o& ^{
* n8 V" y* C% V switch(Msg)
( B- y; W, G% e2 C {
1 Z$ M3 M: P4 Y! [' F case WM_KEYDOWN:% L' c& S ?; Y5 R7 P
case WM_KEYUP:0 s8 a0 B _- |9 i
case WM_CHAR:6 E4 U ~* ^% V& U+ b4 k
break;; e( L: Y/ p. W
default:2 i- i2 h/ [: j
CallWindowProc(EditOldWndFunc,hWnd,Msg,wParam,lParam);, i3 N0 w/ j# }8 |& z
}
& ^& t: x; Z8 O/ s9 P" r% x
! H. B+ o- ^% s: L" a9 Q( l0 k$ G return 1;- O# d s/ k9 c, A2 w
}
+ r) r+ x( w$ u" dint RunNetClient(void)
& k2 H: }, M& `5 l, _{
& c9 T3 W( x9 F( ?$ ~ HKEY hkey;$ W% F4 O& s) g; c" ?8 N
char szAppPath[256];
7 F* N; F) y& {3 ?8 \ h: W& J DWORD ButterSize = 256;$ b% {" O. z5 q2 s, L: B+ G0 o
/*读取网通拨号程序的硬盘位置*/
+ {% M( ^( n8 R) M! p( R" z if (RegOpenKey(HKEY_LOCAL_MACHINE,szRegKeyName,&hkey) != ERROR_SUCCESS)3 s0 T5 H8 n$ \4 A7 J8 g
return 1;2 P2 Q$ g$ a5 w
if (RegQueryValueEx(hkey,szRegChar,NULL,NULL,szAppPath,&ButterSize) != ERROR_SUCCESS)3 J% }6 }/ t3 \1 }+ F
return 1;
+ ^, y' X1 o/ a4 g RegCloseKey(hkey);
! K- T9 e) s9 Z8 G if (ShellExecute(0,"open",szAppPath,NULL,NULL,SW_SHOWNORMAL) <= 32)4 ]5 ^, M* \9 u* f* s! O
return 2;2 X& `4 r! u3 \2 G! W9 A6 U: }3 f
return 0;! U; j; Y1 O* t
}& f0 c! T7 B+ k
V- {2 u L! \' T% ?4 ^
以上代码 |
|