|
4楼
楼主 |
发表于 2004-10-30 16:50:00
|
只看该作者
#include @' D. U- R; B8 ^1 b$ q
#include "resource.h"
0 f/ O8 K2 v, N% q5 D" t#define APPNAME "AutoDial"
& ^- s) p" N r& T# U$ r' [& d#define WM_MyIcon WM_USER + 100/ L+ ]0 E6 C; ^0 K0 Z, l6 d
const char szRegKeyName[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Components\\51AF6AC6C47EC36459D07877B938F76E";
1 S* o6 x% h7 _* _% Fconst char szRegChar[] = "A0CDAE5BF3ECD0F439C33E627F3DA3E5";6 o. j- s6 M Z
const char szHzcncClassName[] = "TfrmMainNetClient";
" x! k F4 L( N W% T5 T! M) S. L' Qconst char szClassName[ ] = "AutoDialForm";
5 K# m4 T& |2 U0 vHWND hNetClient,hConnectButton;
& u' Z6 M8 ]% Q, a* c* lHICON hIcon;% N/ R" O, \1 @
HMENU hPopMenu;
4 L" f: V( D c" ^LRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);
" q8 L& b" i- iLRESULT CALLBACK EditProc(HWND hWnd,' X) ]- T8 B) C& L
UINT Msg,
8 |$ a" k7 }1 h WPARAM wParam,8 T/ X, I5 ^7 l; d! A
LPARAM lParam8 {" {4 |: K) ^% R, D. P
);) [. ?1 m4 I6 k$ i% ?+ H
int RunNetClient(void);
7 k8 m9 V6 I w v% s1 s. pNOTIFYICONDATA MyIcon;3 N3 [" I; w2 C& Z5 P( h) b3 |1 H
WNDPROC EditOldWndFunc;3 r/ Y4 p9 p1 p" x8 y
int WINAPI WinMain (HINSTANCE hThisInstance,
+ {( U/ t5 F+ M: `, F+ F0 l9 r# w7 E HINSTANCE hPrevInstance,2 T. f- M; f+ ~, a7 t
LPSTR lpszArgument,
$ O, J" V2 P8 C# E int nFunsterStil)* R( R5 j9 l! B. s$ x
{4 o8 ]- U! U/ V" V8 d+ s
hIcon = LoadIcon(hThisInstance,MAKEINTRESOURCE(IDI_ICON));
7 _" x" N( W1 Q7 } hPopMenu = GetSubMenu(LoadMenu(hThisInstance,MAKEINTRESOURCE(IDR_MENU1)),0);# H2 Q3 |! t: C! e& b& t
DialogBox(hThisInstance, MAKEINTRESOURCE(IDD_MAIN_DLG), NULL, (DLGPROC)WindowProc);+ ~+ {* }- u; X5 ]0 X7 ?
return 0;
1 r# }8 X" i2 \8 _7 n& S/ U}
( N& r/ J' ~* H- H! {4 H7 ^2 `# _LRESULT CALLBACK WindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3 x4 E& H5 K9 l. C& L{) Z! Q6 e% y2 b
static UINT times = 0;
; w' a; J! w6 r/ } switch (message) /* handle the messages */
+ K S9 |9 {# c {
* M" d. Z1 F3 A* w# _ case WM_INITDIALOG:1 M- a5 Q6 A( H& i/ D E
hNetClient = FindWindow(szHzcncClassName,NULL);1 n0 _6 D7 } X9 w4 t8 m
if(!hNetClient)* H2 K S, ]1 a2 \9 o' z6 K: l
{9 _$ r& l- `. C& u0 Q
switch(RunNetClient())6 E8 y ]% y9 U
{
6 w1 V; ~2 q8 H case 0 :; I; B6 y5 F' ^5 d& P2 B
break;
7 t( t' K8 i# |, b7 ?/ T case 1 :
2 ]" m) {3 Q4 H MessageBox(hwnd,"请确定是否正确安装网通拨号软件!",APPNAME,MB_OK);3 @ j. \5 p; i: z7 h+ a
break;% \7 I6 |$ `* U/ P
case 2 :
4 O3 h, y s% }3 ^6 a* a9 s) w MessageBox(hwnd,"无法运行拨号软件!",APPNAME,MB_OK);
7 b3 r' u0 v- u1 O% Y9 F }- c9 `* D+ _% H8 T, o
hNetClient = FindWindow(szHzcncClassName,NULL);
. K1 b+ X3 G! R- o/ f }3 d& j& O$ E+ f7 q
hConnectButton = FindWindowEx(hNetClient,NULL,NULL,"连接");
( X; a. b! A; B6 B SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)hIcon); F) X0 X* O* m( @' Z1 F
MyIcon.cbSize = sizeof(NOTIFYICONDATA);
, M3 G( B$ E# K3 O MyIcon.hWnd = hwnd;
! c3 R# {$ O/ a* U* d+ o MyIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;' ^/ C; h& @ ~# n5 b b
MyIcon.uID = 1;- q, j( h7 L0 n W
MyIcon.hIcon =hIcon;
9 j( f T( A( h2 S. L% n MyIcon.uCallbackMessage = WM_MyIcon;% i2 A8 q& R& ^' e3 r* @1 E
lstrcpy(MyIcon.szTip,"自动拨号");" a. _9 O. A5 E' n( n
SetDlgItemInt(hwnd,IDC_EDIT1,1,0);
$ p `' _5 V! i SetDlgItemInt(hwnd,IDC_EDIT2,0,0);
, F7 C( Z* \1 ^; K8 B3 A# @. E SetDlgItemText(hwnd,IDC_EDIT3,"11:29:00");% r: i$ k. |- q9 A% r
EditOldWndFunc = (WNDPROC)SetWindowLong(GetDlgItem(hwnd,IDC_EDIT3),GWL_WNDPROC,EditProc);
( ^% E$ p" k( j# A, {1 L0 ` return 1;
2 m6 |9 Z0 Q/ Q4 R) c4 |/ W5 I9 A break;+ v7 ^- |# q m& r- }0 f
case WM_TIMER:
8 E D( z8 I* ~# e* i hNetClient = FindWindow(szHzcncClassName,NULL);
4 t: D+ {& R6 o if (!hNetClient)
`" c4 y" S# }5 T4 V0 [ {2 Y9 h$ K# I6 s) P/ t# H4 C' B. j
KillTimer(hwnd,0);
|( x4 |' y9 ^% Q. } break;5 T# ^: O) j/ J7 {
}
* o+ B1 g* F; [! y* ~ if(IsWindowEnabled(hConnectButton))2 v, V1 Z6 V9 \3 B( W# J
{. ^8 I. j9 C/ n' b
if(times < GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) || GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) == 0)
2 X* L+ P- ]" H; W# S1 c4 W# F {$ a6 j- M- u8 t; z- q
SendMessage(hConnectButton,BM_CLICK,0,0);
2 f$ Q! g7 ]3 M1 I( p1 B( t. Q times++;3 G- f& u+ E* r U1 R
}. O% O# e7 M# J1 h2 U9 R% L) z
7 r% q" i& F: G# ~; ?: |; J% [7 D& k }
0 K* w- H3 _1 a& p# B9 f+ N break;4 h2 j: @4 O0 ?! i$ I2 W
case WM_COMMAND:
c1 h* O8 u+ n) Y ( A7 z* R) S w
switch( LOWORD(wParam) )
f$ t' O! k0 W {- z, j4 H7 W8 t/ Q% Y1 ]! a
/ o0 N; w G/ J8 T
case IDOK:
2 F# v9 Z( j6 M+ A; t% `! n8 E G SetTimer(hwnd,0,1000 * GetDlgItemInt(hwnd,IDC_EDIT1,NULL,0),NULL);
0 M! a, A. ]; D" g/ U/ V ShowWindow(hwnd,SW_HIDE);
# V$ g1 a# W0 x6 a. J) b% y Shell_NotifyIcon(NIM_ADD,&MyIcon);
/ L" J5 Z& C/ t* N+ f2 ~( G( w3 ?' \ times = 0;. J' @! s/ W, T( k! C& I
break;0 W* E+ Y$ Y9 p$ F
case IDM_SETTING:+ M' ]; ?9 R5 t
ShowWindow(hwnd,SW_NORMAL);( S+ Q9 V* B/ L/ `. E, g
Shell_NotifyIcon(NIM_DELETE,&MyIcon);
; i* H+ H% f: R, {6 j KillTimer(hwnd,0);
3 x) L, m! ?/ j( y1 U0 ~, O/ R break;
/ }) b" S7 `. |. { case IDCANCEL:
g3 L* l; w! q% e; | G# N3 q case IDM_EXIT:8 E3 w7 m1 d* b* }) k( B7 j
Shell_NotifyIcon(NIM_DELETE,&MyIcon);. k$ x) J1 y; Q2 {( p
KillTimer(hwnd,0);
% o% h8 X) D, s' r EndDialog( hwnd, 0 );" f. ~/ x1 U5 i! U
return TRUE;
6 I; ~5 I. q& [( N }
C! ~ G3 j; x, b/ U& @& m2 Q$ S return 1;0 j2 d/ C8 \. k+ e q* j+ |/ I
case WM_MyIcon:
; t" a9 Z* r' O( T! t* Q+ r if(lParam == WM_RBUTTONDOWN )" O) t7 W A0 H) J- |
{/ y; U" j' S7 F. w# k/ L3 ?
POINT pt;
/ X$ R" A! {. B# z5 x& X. E+ ]+ J GetCursorPos(&pt);* h) l) Y8 w$ O% c9 s
SetForegroundWindow(hwnd);: v3 |4 f( |- v7 g7 S0 j
TrackPopupMenu(hPopMenu,TPM_RIGHTBUTTON,pt.x,pt.y,NULL,hwnd,NULL);2 [! i; j [! \) k0 q& I
PostMessage(hwnd,WM_NULL,NULL,NULL);5 f/ E1 [, v7 q
}
6 D" p* b# B( `* x9 K6 u break;
# [3 K# q' |, `0 b: n& f case WM_DESTROY:
. i6 N& p! Y# e9 d) Z; ` } EndDialog(hwnd,0);; @! e0 }1 X* O- h$ I
return 1;* B: L; ?: I# y6 R
break;
4 ]+ M" i: D0 Z' C" T/ W7 K }
" S, r2 h! q0 \2 r return 0;
# ]9 ]- x0 {2 A}
0 d9 W: u4 b1 s1 eLRESULT CALLBACK EditProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)* z4 ?/ t- q) h1 s
{
/ o: f4 c! b+ d, |* v m6 H switch(Msg)/ v6 {0 ]- q* r2 y
{. B( ^& B9 f0 `3 A2 `/ ]# E
case WM_KEYDOWN:6 ~3 o6 x- d7 |
case WM_KEYUP:. [! V5 M( K9 Y& w$ I5 f
case WM_CHAR:7 h8 k. ?* h- _9 u) k3 H
break;% F0 U6 z) A" ]4 u3 u
default:) j4 l: l- a+ T# A: B5 j
CallWindowProc(EditOldWndFunc,hWnd,Msg,wParam,lParam);
* Y* R) A+ O8 i G }
# D/ |7 y$ `# s
$ ]: V3 @, ?6 O7 j$ n- w return 1;. D/ q8 H7 ~( r) h* j! W
}! B# s) \5 e8 e# {
int RunNetClient(void)
0 j0 ?+ Q1 V& O) K+ z6 O$ M3 J{* K/ g8 {/ m5 g
HKEY hkey;
* @7 b7 m% ~3 g% r2 M& p" m char szAppPath[256];$ O, }- s! a$ X
DWORD ButterSize = 256;: s6 h( `8 @, S- @8 G# m
/*读取网通拨号程序的硬盘位置*/
" i/ Y ]# T9 Q if (RegOpenKey(HKEY_LOCAL_MACHINE,szRegKeyName,&hkey) != ERROR_SUCCESS)
K3 v$ B9 P2 ]. D return 1;
# O6 F1 d; Y0 h0 t1 T; H if (RegQueryValueEx(hkey,szRegChar,NULL,NULL,szAppPath,&ButterSize) != ERROR_SUCCESS)
, [: I# }% H/ W* ]/ F return 1;/ k" W6 Y/ G- z7 k
RegCloseKey(hkey);; s* l# X7 {. ^8 c
if (ShellExecute(0,"open",szAppPath,NULL,NULL,SW_SHOWNORMAL) <= 32)
9 F8 i- B% l) B3 S" t) _$ | return 2;
" ^8 a; Z3 V/ d. |) }* @5 ` return 0;3 K5 t! O0 V) X, o# j) n
}
. p/ h9 B3 Y& Q7 p! u1 I% V L) _
9 `' |" {" u" ]' ]! u+ B, P( _以上代码 |
|