|
4楼
楼主 |
发表于 2004-10-30 16:50:00
|
只看该作者
#include
( ? W. v9 {1 n; T#include "resource.h"
[2 Y+ y8 ~8 G4 p1 p#define APPNAME "AutoDial"% s: c# p% u, J/ S( D/ d
#define WM_MyIcon WM_USER + 1009 G* a+ K5 U, P$ H% ~; r
const char szRegKeyName[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Components\\51AF6AC6C47EC36459D07877B938F76E";1 d3 O2 @+ p' z; N
const char szRegChar[] = "A0CDAE5BF3ECD0F439C33E627F3DA3E5";
# i1 ~6 K) |2 r* e, @ fconst char szHzcncClassName[] = "TfrmMainNetClient";
$ [) Y2 s: n) E8 ]const char szClassName[ ] = "AutoDialForm";6 \% {7 g1 R( m4 E% U0 \; W' P) e
HWND hNetClient,hConnectButton;, i( E# R# v+ f M4 C
HICON hIcon;
! T: a) R: _: B2 r- kHMENU hPopMenu;
3 R T' J: s- vLRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);
' K, I/ d u2 U2 D/ r' kLRESULT CALLBACK EditProc(HWND hWnd,0 o j; R6 g) m- j, L, F1 K2 C
UINT Msg,
, S* y/ _! G! F1 v! N) C WPARAM wParam,
* P$ B) E p& C7 |* I, u( B9 M LPARAM lParam
+ Q% K6 T& ?( z9 i );
7 k5 B% L0 W1 n6 R5 T9 Pint RunNetClient(void);
" `8 }1 T* V- D* b+ w2 U0 ? l5 DNOTIFYICONDATA MyIcon;5 _, @3 v d* o$ l1 k
WNDPROC EditOldWndFunc;
% b, d0 `4 _6 l" l* }int WINAPI WinMain (HINSTANCE hThisInstance,
1 N; |: X8 S. @9 N- k( S0 X# ` HINSTANCE hPrevInstance,! U. W7 i4 ?0 ~. J4 \& ~ M
LPSTR lpszArgument," A( q1 M( r P$ J; F7 j& y& q
int nFunsterStil)
( {; @/ ~& ?$ E3 B# n$ a' w% O{( P3 ]* d. t0 a3 T& n& b6 U
hIcon = LoadIcon(hThisInstance,MAKEINTRESOURCE(IDI_ICON));
/ y- _" U9 f3 x4 W/ \/ i% _ hPopMenu = GetSubMenu(LoadMenu(hThisInstance,MAKEINTRESOURCE(IDR_MENU1)),0);
9 |; H. U. |' M( W0 D7 Y4 Q& \! e DialogBox(hThisInstance, MAKEINTRESOURCE(IDD_MAIN_DLG), NULL, (DLGPROC)WindowProc);
% L" P; P% \3 ]) H, k return 0;
% I; N: {1 W$ x9 r; P}
/ B' H, g* H; e% |8 RLRESULT CALLBACK WindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam): S' k6 G" d5 `& v$ W
{( _3 ~1 i6 ]5 I6 m4 F" @
static UINT times = 0;
3 I2 Z# P4 u6 w- H; n9 H8 Q switch (message) /* handle the messages */
6 Y4 ?' O" T( Y0 J- | {
8 m3 Q# K2 a- d9 G) J/ Y/ Z& m1 c case WM_INITDIALOG:
* y3 {4 t/ C% W0 ?: t% Q hNetClient = FindWindow(szHzcncClassName,NULL);5 Q. c0 o- `! j6 z$ D% T
if(!hNetClient)3 N0 B+ X3 m/ X2 N7 W/ `: z. r
{
2 P7 |+ U& l( z1 y0 r switch(RunNetClient()); o' l! w# g0 Y0 g8 e
{
1 F1 _0 U. c- V# b- f7 p! O case 0 :
+ s1 o4 ^8 ?1 |& v* Q break;
% S# E0 A7 T6 G% V) C6 n( u2 X% ~ case 1 :
4 {* v1 t+ {( n7 z! S$ v MessageBox(hwnd,"请确定是否正确安装网通拨号软件!",APPNAME,MB_OK);
* U6 c: I: o s2 l; I7 [0 i break;) ?+ @& U$ N. s: G' R
case 2 :
9 }% `9 d( Y0 ?7 n( r MessageBox(hwnd,"无法运行拨号软件!",APPNAME,MB_OK);. d9 Q. _2 Z! u2 z& ~
}
" K' Z# r" ^- m% a/ B: }1 G& m hNetClient = FindWindow(szHzcncClassName,NULL);% a. b' g2 N/ T0 B
}
( v) F0 T/ N1 W, y, P hConnectButton = FindWindowEx(hNetClient,NULL,NULL,"连接");
8 t# F" }$ i- ?, P4 p. Z }# A& G SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)hIcon);
+ e2 c4 z) @* x6 A' E+ c MyIcon.cbSize = sizeof(NOTIFYICONDATA);2 b* e- o/ @1 Q
MyIcon.hWnd = hwnd;
; H. a' d$ ^5 I0 ]' \. @4 n MyIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;5 k4 I# Z( `2 `
MyIcon.uID = 1;
8 b! h- o& V% n! _, j% n1 o; f MyIcon.hIcon =hIcon;4 k4 z& b" [, c! L, ?! D/ X
MyIcon.uCallbackMessage = WM_MyIcon;( T$ c- Z+ Z) M5 [/ f) K
lstrcpy(MyIcon.szTip,"自动拨号");0 m- d% x( }2 c6 J
SetDlgItemInt(hwnd,IDC_EDIT1,1,0);
- ]0 t: `; t, ?4 G SetDlgItemInt(hwnd,IDC_EDIT2,0,0);& K% ?4 p) k' ?: g J& U& w f' `
SetDlgItemText(hwnd,IDC_EDIT3,"11:29:00");
7 E. K- X' _! N9 a2 h2 ~ EditOldWndFunc = (WNDPROC)SetWindowLong(GetDlgItem(hwnd,IDC_EDIT3),GWL_WNDPROC,EditProc);
/ A! J* T3 G: y* \4 U7 n return 1;
: }/ S( i4 W2 ]5 k, x6 g break;0 X( U; e4 Z+ g& [
case WM_TIMER:" K. D% G; F2 ~% `9 e8 J
hNetClient = FindWindow(szHzcncClassName,NULL); O) h9 c+ \6 o( T( o1 v
if (!hNetClient)
* Z' h H/ i% n( G6 Y {
( Q. j0 P$ Q. \; f$ a KillTimer(hwnd,0);
8 C7 m* T+ X1 Q% Y1 Q6 p break;
$ s& \1 {5 M! r6 s% O }3 N4 Z ?5 f$ y; \9 ~/ t
if(IsWindowEnabled(hConnectButton))" W+ b7 t4 M2 h( p; W# s
{
; D0 f) t! B9 m5 d if(times < GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) || GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) == 0)
" h% D5 R; {4 J1 R {, Z D6 M! k( W4 p2 k* ]7 _* z1 Q
SendMessage(hConnectButton,BM_CLICK,0,0);
! a& }+ `/ `& `. S6 } times++;
( c1 F- d) C' [: A, Z }
7 R; R3 `! i }. P! Y ; R! P+ Q) B, R& l. h! Z# F
} }* U" }& S" Y' |: B6 |! x# ~! A& |
break;9 V" g% {: v8 ^+ n
case WM_COMMAND:* \) C1 P# t# a, C+ l$ d
7 U" g7 O! ^8 g& y4 ?; w& |
switch( LOWORD(wParam) )
* A, P8 s2 u2 H$ M+ w0 Z8 N4 _2 K {
+ i$ r# d. b; ?: h6 o; a7 v
/ G! E+ s9 c/ \% S5 y4 _) n case IDOK:
) B8 G' t- X; x2 n9 M X: C SetTimer(hwnd,0,1000 * GetDlgItemInt(hwnd,IDC_EDIT1,NULL,0),NULL);: \# K R- G% E- F
ShowWindow(hwnd,SW_HIDE);
# C% Z% M+ Z, L2 x, J3 l Shell_NotifyIcon(NIM_ADD,&MyIcon); ]$ l% z* l, e3 A2 y
times = 0;
# W/ l0 u. B# t# X7 X% U6 C break;
: D4 `4 e1 ?7 F; a) D- Q$ z$ P$ G' M case IDM_SETTING:
0 R/ ^- S, Z& X ShowWindow(hwnd,SW_NORMAL);
6 D0 h6 m- F" N6 @4 U: P9 @) R; \. t Shell_NotifyIcon(NIM_DELETE,&MyIcon);! `5 ]4 C- }$ y+ v$ _$ ^
KillTimer(hwnd,0);
8 y+ H- Q) o9 z break;$ P1 }2 q- e' _" _- _) w; ]1 C$ E7 Q
case IDCANCEL:
( t9 ?* R+ ]9 S, d0 u7 @# R case IDM_EXIT:! n* n# A# t7 Y5 Q, L0 U! Q: v) G& t
Shell_NotifyIcon(NIM_DELETE,&MyIcon);
5 [/ L1 Y3 @3 ~6 x( @ KillTimer(hwnd,0);
9 x" R# r+ ~8 |/ p5 `* ]0 Z& p EndDialog( hwnd, 0 );
! s0 p" z; p4 |7 N2 d1 N, y return TRUE;) i2 u. r7 k/ }
}/ }0 h' ? n$ N1 ?" d5 o3 c
return 1;
9 `1 S. @$ J5 q+ R: ^+ J" P2 e3 G case WM_MyIcon:
# e6 ?! h, e5 \8 ?+ L6 ~ if(lParam == WM_RBUTTONDOWN )
3 Q" P( w1 y$ j- b9 M. u6 } {( H, N W1 W( F; T" }# u# w- E
POINT pt;: F8 u! \8 w+ G6 N
GetCursorPos(&pt);& E: a4 e$ `( J8 X
SetForegroundWindow(hwnd);6 i; N Z" m7 Q4 F5 i' z4 n$ ?2 j
TrackPopupMenu(hPopMenu,TPM_RIGHTBUTTON,pt.x,pt.y,NULL,hwnd,NULL);
; j. w }5 g% K PostMessage(hwnd,WM_NULL,NULL,NULL);7 o1 ^- ~% J; S8 c# m4 G0 E
}
6 A# _1 B9 q% y break;
9 E6 d6 Q4 w& x2 g0 A- Q6 {2 I case WM_DESTROY:
, r8 ?9 Z8 O7 e; E5 t EndDialog(hwnd,0);
+ U, k5 S t3 f0 N8 N: Y3 v return 1;
6 O- _% b" J5 r) y5 i1 y* _ break;
% y' c) ?3 F: ~- y$ B }, G: G |# w9 `! u% `1 T5 f; R
return 0;) Y2 _' {0 d [% g+ N: H6 F" A
}
h* `: D5 p- gLRESULT CALLBACK EditProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
3 d- J2 ^$ l) {% B{ }5 N/ ]( c9 X. v( F+ y! \
switch(Msg)
9 A+ B! Z" b3 x, Y {
" t3 W2 o0 E1 B6 l3 R0 c; ^4 \ case WM_KEYDOWN:0 |" n" g* ~8 P/ ]) Y- t( c; r- n
case WM_KEYUP:
" N" k) ]. b+ M* S, l. v. z case WM_CHAR:
. h3 Z+ P' C6 T( V ^ break;, S; n" Z6 Q9 m* H) S
default:
; F4 Y$ x% H% z* P CallWindowProc(EditOldWndFunc,hWnd,Msg,wParam,lParam);# z @: u% V/ |! \& m
}2 U' r- ^) D9 Y i
5 |5 [- I- ^* G) [% k return 1;' A; r. Q- V, e$ n7 c' ^% ~3 y6 i
}/ }& u/ ~& W0 v& z! ]
int RunNetClient(void)% T, A2 W ^7 v0 |9 X. I7 B- W5 ^
{& _ l9 }3 d- @2 g6 Z$ l2 t. u
HKEY hkey;. D5 N7 ^, B1 K4 S6 P2 p# l) S
char szAppPath[256];3 M4 X+ C6 r0 Y% V
DWORD ButterSize = 256;8 c+ @7 I" C' t/ A2 @
/*读取网通拨号程序的硬盘位置*/7 n& k) V( {$ X2 |/ h( d# o
if (RegOpenKey(HKEY_LOCAL_MACHINE,szRegKeyName,&hkey) != ERROR_SUCCESS), ~( [( Q) u5 ?# ^* m/ y" W
return 1;
: L- Y- [7 T8 t; N" E if (RegQueryValueEx(hkey,szRegChar,NULL,NULL,szAppPath,&ButterSize) != ERROR_SUCCESS)' ^" |7 P$ |0 U& [/ b- f2 d
return 1;
" B/ {3 \; k4 H3 S) R2 A RegCloseKey(hkey);3 d5 P/ C d: Y& \, X: Y9 g
if (ShellExecute(0,"open",szAppPath,NULL,NULL,SW_SHOWNORMAL) <= 32)5 }2 ^$ N2 D" w' s
return 2;8 N4 B2 F# M& t0 s& Z( Y
return 0;0 ]! U# D6 v; d9 D( O
}& a9 p! w2 P$ k3 ^% f% a) L
7 ~( K* k$ t! x0 y1 ]3 {2 w以上代码 |
|