|
4楼
楼主 |
发表于 2004-10-30 16:50:00
|
只看该作者
#include
; v4 m$ u2 g" d" h# B% {( T#include "resource.h"
0 k! L0 k4 ]: {7 N3 T1 `#define APPNAME "AutoDial"( B" R9 ^# h! `! T7 r5 S
#define WM_MyIcon WM_USER + 1006 z g& V" @) h1 c, L% x- d! c) a
const char szRegKeyName[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Components\\51AF6AC6C47EC36459D07877B938F76E";# K2 M# l7 Y6 `1 ]/ \
const char szRegChar[] = "A0CDAE5BF3ECD0F439C33E627F3DA3E5"; a: }( B2 a' o4 I. M- J$ u
const char szHzcncClassName[] = "TfrmMainNetClient";
( a s w' W" |" |const char szClassName[ ] = "AutoDialForm";& u( l! y. J+ Z R9 q6 P
HWND hNetClient,hConnectButton;4 \/ k1 Q. ^! a, L- J5 h+ Z% f
HICON hIcon;8 Q; B8 J Q/ h, m+ g) H
HMENU hPopMenu;# ]1 L7 U6 Y; s) _9 j
LRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);
% Y1 Z' E7 p! O+ L5 C, XLRESULT CALLBACK EditProc(HWND hWnd,
% m0 P" Z# {, B2 [ UINT Msg,# P: R3 ~5 ^3 I) @8 N5 p6 j5 k
WPARAM wParam,
3 }5 x% k! Z# p( e! e LPARAM lParam% u" G; G1 D. G3 k! t
);
/ u4 Y6 G M% x1 P8 [5 kint RunNetClient(void);
3 p( _1 r; H5 @" o+ sNOTIFYICONDATA MyIcon;
% n2 `! q1 s+ ^5 UWNDPROC EditOldWndFunc;
+ a2 | D3 I7 L6 ^' i- Uint WINAPI WinMain (HINSTANCE hThisInstance,
: O1 o( ?2 h, j; u. P HINSTANCE hPrevInstance,
/ {5 U' x' x( c$ K LPSTR lpszArgument,
6 {. |$ n* q& w: Z int nFunsterStil)+ j. j; [8 q1 R/ c
{
' `* f. i% v0 @, d hIcon = LoadIcon(hThisInstance,MAKEINTRESOURCE(IDI_ICON));6 z4 h0 [8 \- a u4 Y' M3 M y
hPopMenu = GetSubMenu(LoadMenu(hThisInstance,MAKEINTRESOURCE(IDR_MENU1)),0);
2 C) P. _" c- Y DialogBox(hThisInstance, MAKEINTRESOURCE(IDD_MAIN_DLG), NULL, (DLGPROC)WindowProc);
7 `- V% W" l7 r& P2 Q return 0;5 S" ]+ s, A* |0 p& E7 N1 O
}
9 a7 F* Q# S6 I" ^5 S, t jLRESULT CALLBACK WindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5 C1 \+ E/ @7 s# [% ~8 p% ?& W{% ^7 R4 E5 a$ V2 O! b
static UINT times = 0;) N4 h8 p2 n. p! a
switch (message) /* handle the messages */
4 s. d' ?9 z, }) b& q6 M9 ]3 b7 n3 c3 }8 ` {
" U( ?; W: Y* x: h. M3 G case WM_INITDIALOG:2 q. Y8 v& d o: j4 G/ q( j2 l- ~
hNetClient = FindWindow(szHzcncClassName,NULL);! ?1 `3 A5 K7 g
if(!hNetClient)
* C* d5 ]7 m6 h y# R {. ]; M7 r F( q& ^& b3 C' z6 O @
switch(RunNetClient())
4 F4 n" d: h3 d" u. P6 ? {' ?+ n0 W+ _! A& _
case 0 :
8 j% o" U8 Y& V& ^$ G2 N- ? F break;
1 E% e; N4 }' A case 1 :- L0 t. Y4 C4 H9 p0 M+ M" m+ y
MessageBox(hwnd,"请确定是否正确安装网通拨号软件!",APPNAME,MB_OK);
& R5 e3 ]1 l+ ]- ], l; E7 l$ E break;3 ~: O- r4 g0 ~, H+ J3 v0 a. |& {% g
case 2 :
7 N2 Q' u9 Z3 G' m MessageBox(hwnd,"无法运行拨号软件!",APPNAME,MB_OK);, o7 V- | ?6 w3 e. Q1 H+ Y' S
}
& c7 n$ _& D/ S hNetClient = FindWindow(szHzcncClassName,NULL);7 t, |5 t2 P( t3 d8 @! t
}
, {4 S8 h, `) ]( D hConnectButton = FindWindowEx(hNetClient,NULL,NULL,"连接");6 G( V; Q$ G9 Y" @, G+ `( p
SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)hIcon);) W. a4 A$ D; D
MyIcon.cbSize = sizeof(NOTIFYICONDATA);
& G# n+ t" ?5 y2 G MyIcon.hWnd = hwnd;
) W0 Z* N4 }- G: s5 Z E MyIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
; X7 H8 z3 f" G" E4 C. e MyIcon.uID = 1;
( E0 I4 Z2 |- X6 i7 N" {# K7 W+ S MyIcon.hIcon =hIcon;
# Z4 Q' P3 ~9 Q0 Z MyIcon.uCallbackMessage = WM_MyIcon;6 X1 B9 C1 X6 [- x/ \# B
lstrcpy(MyIcon.szTip,"自动拨号");! c$ V/ W0 Y) z# m7 _/ Z; L$ ]0 {
SetDlgItemInt(hwnd,IDC_EDIT1,1,0);1 e# h' l1 C* C8 j! q" m% E
SetDlgItemInt(hwnd,IDC_EDIT2,0,0);
* a- W8 k" S7 r. j SetDlgItemText(hwnd,IDC_EDIT3,"11:29:00");, \0 @- K- h2 d# ^1 S. I4 n- }
EditOldWndFunc = (WNDPROC)SetWindowLong(GetDlgItem(hwnd,IDC_EDIT3),GWL_WNDPROC,EditProc);( Z. H5 a. [+ _5 E. @& B% h8 Z( R
return 1;* }6 M/ m! ~# F
break;
7 }- M0 R9 L5 L case WM_TIMER:- M8 ~( Z5 x; e
hNetClient = FindWindow(szHzcncClassName,NULL);9 \' m5 T2 a" Q, R' `, b0 x- Q, s
if (!hNetClient)
: y/ l/ O9 \6 ^" P' ?& ` {: J# }/ x& A" n% T" g
KillTimer(hwnd,0);# d) e% J' x/ A" g9 D
break;
3 W& Z3 ^, X5 E2 v( K0 v }
2 A% [: c$ ], C if(IsWindowEnabled(hConnectButton))
5 u) L3 l! X( A. }% j {; J# _* {+ `# [' G; Z
if(times < GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) || GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) == 0)5 h0 v, j2 d4 n6 E" f! B/ m
{/ c" a. Z/ j1 Z& z' ]8 _" U* ?5 z
SendMessage(hConnectButton,BM_CLICK,0,0);3 h! H; E# z/ q9 X, E# ?
times++;' y% d" u- C+ \7 V* ^* @! A
}0 M W( m$ N0 s8 z
; I, X, }* i! e. q+ P# B6 ~( R
}1 }- N& G3 d: j% ^$ ]2 A
break;
A8 p' i4 Z2 d6 M- ~: M case WM_COMMAND:
8 o5 N' L1 w9 J7 c2 Z1 ?* I / o# L2 X1 x2 z1 [
switch( LOWORD(wParam) ), l: T+ ]# b: A- N
{) E% P3 i% k/ P- g* f$ Z
0 R3 v, L2 o8 ?: c0 D case IDOK:8 R: p6 I5 \& U2 k4 F; D9 j
SetTimer(hwnd,0,1000 * GetDlgItemInt(hwnd,IDC_EDIT1,NULL,0),NULL);
! i( b* N0 x# v6 |& [1 C9 E ShowWindow(hwnd,SW_HIDE);$ ~* X: j6 _* ]% z; D
Shell_NotifyIcon(NIM_ADD,&MyIcon);
( U% |" Y' D w times = 0;
/ t) `1 Q) \7 i/ x break;
! ^; W+ p7 i7 j8 f& t- ]6 L7 ]: e case IDM_SETTING:
- q; d) t% `3 l9 k# b$ B2 f' n0 y ShowWindow(hwnd,SW_NORMAL);
O9 ]3 h7 r3 t; W& N0 }: U Shell_NotifyIcon(NIM_DELETE,&MyIcon);
9 K5 J- f1 [* k( i! i$ x7 g7 q6 n& S. I KillTimer(hwnd,0);
" ~! u1 [; F. u break;
& X+ g6 C: B8 W* O case IDCANCEL:9 g$ T& P9 {4 {- V3 n3 b: X
case IDM_EXIT:
+ Q' ^$ h4 p! l( X3 m: | Shell_NotifyIcon(NIM_DELETE,&MyIcon);
& q K+ K6 a1 e5 L KillTimer(hwnd,0);3 E; X8 M B" o6 Y m
EndDialog( hwnd, 0 );
9 U5 `, t) c9 B1 }0 G; k& Y9 u return TRUE;( M8 L; D) C8 F, K# U& f U, S
}" O7 R; D+ j, J4 |, O
return 1;( d2 p5 S: i1 t+ g% q( V
case WM_MyIcon:' W* n+ d: Y9 W$ Z, h& A+ X
if(lParam == WM_RBUTTONDOWN )/ H+ g2 Y. Z8 T8 B. i4 w! A- H
{9 ?! T8 V& `4 K& L3 T1 H9 e
POINT pt;
8 ~' h+ o7 Y6 } GetCursorPos(&pt);
; o* ^ E' h/ D SetForegroundWindow(hwnd);
& |4 u8 J6 n A TrackPopupMenu(hPopMenu,TPM_RIGHTBUTTON,pt.x,pt.y,NULL,hwnd,NULL);
7 m% o* H- h! U/ F; G* n) m PostMessage(hwnd,WM_NULL,NULL,NULL);; L0 z/ E# z' W( ^+ {
}6 b; {6 y# v: _( u
break;
9 O& a8 K3 T, L, P% h- B( y! V case WM_DESTROY:
D7 o- i5 w+ a. W. g8 n6 I1 N EndDialog(hwnd,0);
; K9 m' A( I: s8 b' e/ e. h return 1;9 C1 a7 f# q! L- D- ~8 ~0 L Z2 `
break;
! C! m/ s7 R$ x6 L6 K3 O4 K }2 q' _& ?0 R' n' x# j7 D% h' u
return 0;5 D. e0 F' j$ i5 g- E6 R
}# ^1 L2 T+ O3 r$ i" q6 Y0 k, Z
LRESULT CALLBACK EditProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)# ?4 z- @! {9 X; t1 W; |! t
{
- X# W- O, d7 o& M3 D4 g" o switch(Msg)' M1 ^' F& ] S4 Y" V/ Y9 b* N) m
{
% F7 b Z" E- w. R* V, ^: d case WM_KEYDOWN:
( H% F* K* Y/ g case WM_KEYUP:
4 K' F! Q% c: W case WM_CHAR:
% @ Q( ]9 a! { break;0 u1 ~, m( ?$ ~
default:
4 q+ H' N. {" P( S( M2 }( U CallWindowProc(EditOldWndFunc,hWnd,Msg,wParam,lParam);
1 X9 ~) L, ~0 P+ O/ R }0 O: O w) H' u E" \
& y" @6 O! ^3 J, Y return 1;
: e# L. W5 O$ s8 q$ _3 v) @, }+ d}
+ ]6 H* t+ t3 `1 Pint RunNetClient(void)+ V: ]1 U& p6 K M1 ]
{
5 V. g+ J: x2 R% Z$ N6 i, R r6 d HKEY hkey;3 r! a' {& e7 P! C1 D
char szAppPath[256];
, {4 }7 j+ q* M, k DWORD ButterSize = 256;' r8 S8 U! O7 t; z: R( [) a
/*读取网通拨号程序的硬盘位置*/' e; K3 K, e* L& p% H
if (RegOpenKey(HKEY_LOCAL_MACHINE,szRegKeyName,&hkey) != ERROR_SUCCESS)- z( t7 b3 j" G1 b. L# l
return 1;
- R6 D6 g8 y1 V if (RegQueryValueEx(hkey,szRegChar,NULL,NULL,szAppPath,&ButterSize) != ERROR_SUCCESS)
% f* X+ v% f0 Y3 s3 D1 V' x return 1;- ]- @! i7 ~! B x. F8 s
RegCloseKey(hkey);& ~7 g. G9 W5 ~0 y( O7 E
if (ShellExecute(0,"open",szAppPath,NULL,NULL,SW_SHOWNORMAL) <= 32)* S, A8 p8 d w/ v0 \
return 2;
' Y( ?, l! Z1 P2 |9 y5 M return 0;
& A& W, ]" \3 f2 r& z}( p. X/ Z$ q8 o+ O
+ U. I2 p! S' G, @& u& k% `: k
以上代码 |
|