|
4楼
楼主 |
发表于 2004-10-30 16:50:00
|
只看该作者
#include
2 _* b! l" }4 o& U#include "resource.h"
; i. ]8 U" l ?. d$ t#define APPNAME "AutoDial"
1 M1 c8 T$ @8 g. @+ k2 {% \#define WM_MyIcon WM_USER + 100
, Z# q# v k. y/ y/ g: `$ t" D, Xconst char szRegKeyName[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Components\\51AF6AC6C47EC36459D07877B938F76E";" }4 G9 V7 f! {% t% o( t" u
const char szRegChar[] = "A0CDAE5BF3ECD0F439C33E627F3DA3E5";; G; k+ S0 M9 w
const char szHzcncClassName[] = "TfrmMainNetClient";
4 c( y$ N; ~; dconst char szClassName[ ] = "AutoDialForm";' ^$ C# K6 X' `3 q, A
HWND hNetClient,hConnectButton;
' l6 \/ R1 |) f$ n! V; ^4 g7 IHICON hIcon;3 B. r) g- ?1 r
HMENU hPopMenu;# B B' i+ G% ?4 Z
LRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);; r8 i3 S5 b6 s' z
LRESULT CALLBACK EditProc(HWND hWnd,: j& u* o, o3 D$ v8 u1 w& u- X+ \+ E
UINT Msg,- }. w3 }3 L6 S0 s* l
WPARAM wParam,
: H/ H7 S3 w2 R+ r7 G LPARAM lParam
: l8 r: u9 Q8 ~; Q& |3 Z, R );
/ ^7 Y7 U) \: l+ J: Q( |& ^* Uint RunNetClient(void);
& r3 L* \0 C( a+ t! a0 i+ \8 @NOTIFYICONDATA MyIcon;% j0 V0 ^' F( _# N/ d3 b
WNDPROC EditOldWndFunc;3 ^- A. D0 Y( v# y) C/ l
int WINAPI WinMain (HINSTANCE hThisInstance,
+ E9 g# W, g c, t6 O: g7 Q$ m HINSTANCE hPrevInstance,
6 M' n( ^8 ]2 |: X2 v LPSTR lpszArgument,
/ Z' J; H. S+ o8 j$ K int nFunsterStil)
( k- v5 f+ k: p{3 e4 p0 x! g# x! E% S) y4 I
hIcon = LoadIcon(hThisInstance,MAKEINTRESOURCE(IDI_ICON));& s+ s2 o$ S/ @5 S$ {
hPopMenu = GetSubMenu(LoadMenu(hThisInstance,MAKEINTRESOURCE(IDR_MENU1)),0);1 L9 N; i+ z, u+ O
DialogBox(hThisInstance, MAKEINTRESOURCE(IDD_MAIN_DLG), NULL, (DLGPROC)WindowProc);$ f# D# A, |+ w* b
return 0;
7 G8 J4 t' T5 V0 ^4 `( X}, n6 T: Z: F0 ^& \7 E
LRESULT CALLBACK WindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)& ]; _- r) C. Y( a. q7 w- A
{; K( W8 c2 P: _7 A( \
static UINT times = 0;' ^. N T' a& P- P e8 u8 e
switch (message) /* handle the messages */
) p5 [ H' ], s1 m% y. q) r {# z2 S+ m4 n4 G8 K
case WM_INITDIALOG:
; ]2 a- a q) Q6 U ?$ X hNetClient = FindWindow(szHzcncClassName,NULL);
. |7 S& ], g) Y7 K n if(!hNetClient)
/ X( F3 N) a6 M- }( Z( v) H( t {
* }/ ~4 s6 y& |* p) k. V" Y switch(RunNetClient())( A5 L* S& Q3 ]6 P
{
6 X, x7 S2 s1 s4 M% U8 _: x case 0 :+ {3 K+ b3 k# {" P# I, g' H: q
break;" s/ S' G% N" w3 {3 M
case 1 :
4 y+ x: N# ^4 D/ ^$ |6 W6 y+ ` MessageBox(hwnd,"请确定是否正确安装网通拨号软件!",APPNAME,MB_OK);5 Z, |* H j4 g8 {
break;' F) x. u3 ^3 Z# e9 u! `
case 2 :+ E' D! @0 j: ]8 f; @
MessageBox(hwnd,"无法运行拨号软件!",APPNAME,MB_OK);) G2 G7 Q' M7 u" r$ _6 F: _
}' ~# C, ] P3 n0 b
hNetClient = FindWindow(szHzcncClassName,NULL);- w9 p+ t5 ~3 ~4 J& P
}
' c% O, o9 D* H- c% m6 ?2 \ hConnectButton = FindWindowEx(hNetClient,NULL,NULL,"连接");
0 X# ^4 S% F* P" P5 L: P+ n5 B7 E SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)hIcon);# x; E, S G: [; l4 o; G. G, x" r
MyIcon.cbSize = sizeof(NOTIFYICONDATA);8 B3 F: O8 ], H- J
MyIcon.hWnd = hwnd;
7 r3 c( c3 Z# M, Q; N! v MyIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
5 q P7 W, l7 P Z. V1 x+ G" ^7 k5 s MyIcon.uID = 1;8 o( e, N8 n Z1 I& G0 R# b
MyIcon.hIcon =hIcon; x+ ~. {! z* o; J3 P
MyIcon.uCallbackMessage = WM_MyIcon;
; z5 C7 A% I3 f+ L& c6 z lstrcpy(MyIcon.szTip,"自动拨号");$ @& u4 h. X% q" @5 P2 x1 V, C
SetDlgItemInt(hwnd,IDC_EDIT1,1,0);. Z* s7 H+ r7 p8 C4 \$ C; t
SetDlgItemInt(hwnd,IDC_EDIT2,0,0);: I _( f6 k$ G7 z8 z( ^
SetDlgItemText(hwnd,IDC_EDIT3,"11:29:00");; {4 H0 @: K& b/ C
EditOldWndFunc = (WNDPROC)SetWindowLong(GetDlgItem(hwnd,IDC_EDIT3),GWL_WNDPROC,EditProc);
q3 k* B+ L9 U6 i. ^ return 1;
/ o$ p8 q" C0 L4 u8 o A" q break;
5 y4 l4 z9 Q6 z0 c6 g case WM_TIMER:/ V! o; ?* @2 Z/ E0 S4 }2 y
hNetClient = FindWindow(szHzcncClassName,NULL);% v0 Z' j' j4 `# Y5 o
if (!hNetClient)
Y' A% F \: } {
$ c1 x9 b! w8 {7 T9 s KillTimer(hwnd,0);
$ M3 i) ?1 q9 ^: Q" D$ Z break;+ J' z4 P, X* B3 G+ _/ M! m, }0 i
}6 w2 e9 o# r9 p: F7 J- V; K
if(IsWindowEnabled(hConnectButton)): ~3 b, ?2 u v- \6 D0 z& Z Q$ r
{
8 L8 C* t- |5 m- C8 m7 t if(times < GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) || GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) == 0)
0 o( F- L- f" x3 e6 L {
8 c+ M+ V1 k& g: A; i SendMessage(hConnectButton,BM_CLICK,0,0);6 w% J* m0 K( s" ]( ?
times++;" i- @; S2 Q6 {
}
# E5 `" j2 W7 D
6 H% p v( Q2 l) | }* w: d V3 ?6 A& K
break;
6 s: W7 V( \$ w case WM_COMMAND:( G' S e& k& R1 t" u. W: {
6 |4 o+ c: }6 _5 ~: C
switch( LOWORD(wParam) )8 e& r& f0 w% a" _# a& z
{
- Z5 q) H, W H. u - K8 G, V8 v$ Y/ R& k
case IDOK:
9 A j Q/ @ ]9 E- k SetTimer(hwnd,0,1000 * GetDlgItemInt(hwnd,IDC_EDIT1,NULL,0),NULL);5 l0 ]1 c/ [. H/ c- s
ShowWindow(hwnd,SW_HIDE);+ K6 e, a! S! L; o; A! K; O9 u& h
Shell_NotifyIcon(NIM_ADD,&MyIcon);7 b. s/ S; Z/ T' s i
times = 0;
6 ~6 p( x8 P7 E break;# j8 @7 ~ `1 V( u6 f5 R% m
case IDM_SETTING:3 l9 i) _3 J$ ~7 y6 \! E4 g* p6 l
ShowWindow(hwnd,SW_NORMAL);8 ^) w3 d' Q" L, {5 W
Shell_NotifyIcon(NIM_DELETE,&MyIcon);9 h* j- S7 W0 {- b7 {; E
KillTimer(hwnd,0);! f) F/ o f# ^' c1 U/ E* E0 w
break;
! M C3 |0 F) ^6 _0 q case IDCANCEL:' n) D$ {5 t! i0 T: i
case IDM_EXIT: u7 i; l# R# a
Shell_NotifyIcon(NIM_DELETE,&MyIcon);- \: f* ^- Q- q4 U% p3 u+ Z
KillTimer(hwnd,0);7 F8 p3 Q. k% f7 Z! [$ W$ `
EndDialog( hwnd, 0 );% p! [% X1 R+ ]- l1 j# m
return TRUE;
# D% S, Z/ |; V; P" N }
/ G6 }" D+ Z0 p9 }1 _8 T5 W return 1;; j2 P8 X$ l4 z; ^# A5 Q; {
case WM_MyIcon:. T6 R( l4 ?( c; {
if(lParam == WM_RBUTTONDOWN )0 J% a3 ^' H1 g* r a/ a
{* I; W% u4 u7 w% K) G5 E
POINT pt;; ]) P9 _: {1 P* t$ M2 ^
GetCursorPos(&pt);- \ W3 h3 |7 H: n# ~ O
SetForegroundWindow(hwnd);. u9 Y3 i- M( ^3 x4 `# G
TrackPopupMenu(hPopMenu,TPM_RIGHTBUTTON,pt.x,pt.y,NULL,hwnd,NULL);
, C2 s$ L" Y' ]9 r+ t% x PostMessage(hwnd,WM_NULL,NULL,NULL);
% I9 R6 S3 U+ d% A4 N' K% Q* X. \ }
! |2 \3 p; O6 _+ ?) l9 H* Q break;- A6 u9 @8 T) M/ w3 R* ~, n
case WM_DESTROY:
# K2 n) r0 c8 u EndDialog(hwnd,0);
7 I( F/ |' f8 _5 S return 1;/ t) \0 H' y" ]- G" K2 e/ S! A4 d
break;
1 m: S0 p/ D. J& l0 t v" V4 Z# { }
* m0 b. g% O3 H& q) n" Z3 b return 0;
: ~: a6 b N1 ~* X8 k; A7 W}
( I0 w# Q; Y& I* S: O+ a' u$ PLRESULT CALLBACK EditProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
8 D' n2 e& H: ]# `& {: i% r{& N; \) A! U% X9 L
switch(Msg)" E( J( [8 d; r1 Y
{ m: s8 ]! h2 _: U; z
case WM_KEYDOWN:
6 @; D7 B/ ~: a case WM_KEYUP:# E6 x8 Q E X/ L9 s2 v" J
case WM_CHAR:: b5 n: `" @/ k/ B" K! ]& d" m
break;3 [/ L; |6 A k! V% ?# N- ?
default:
9 r- R# q/ Z* K% y% h, H! @& _ CallWindowProc(EditOldWndFunc,hWnd,Msg,wParam,lParam);+ i) q6 ~0 L3 ^$ [9 v6 e2 }
}" U( O& O" B. s' c, b
+ i# u V, Y5 l# } return 1;
4 f" B# m' @0 c+ `+ x9 j" x, ?; J}
' ~, Y% T3 k0 r: [9 Jint RunNetClient(void). E/ Z0 y$ {0 h$ J) s/ w+ p: I
{, J" J1 R, N" l5 X% A5 @; M
HKEY hkey;
; K5 G* G& r2 o$ M* q/ Y) s char szAppPath[256];$ D* ~7 d# _8 E2 V6 H
DWORD ButterSize = 256;# h8 L4 b+ A( v, l* i" o
/*读取网通拨号程序的硬盘位置*/
9 x E3 a5 G" t if (RegOpenKey(HKEY_LOCAL_MACHINE,szRegKeyName,&hkey) != ERROR_SUCCESS)
2 ]6 c$ J- p) d3 O: U. F return 1;2 R/ k9 q* [& r5 u: S. F" x8 R7 w
if (RegQueryValueEx(hkey,szRegChar,NULL,NULL,szAppPath,&ButterSize) != ERROR_SUCCESS)
0 {/ s0 k" B7 z- P return 1;+ {- j4 G$ P5 G, t p
RegCloseKey(hkey);0 }9 z" O, J8 k& X' a: P+ G
if (ShellExecute(0,"open",szAppPath,NULL,NULL,SW_SHOWNORMAL) <= 32)
|2 S" ]# H0 }9 `+ D& r) |; b- _8 q return 2;1 U- M$ {3 d5 \+ X$ L& K L
return 0;; D" Q$ ~; g0 }& ?0 o1 _- _
}- C/ [7 z. x; @8 b2 o
7 g* ]8 K6 S8 f7 D9 l' W* q4 i" m) ]
以上代码 |
|