|
4楼
楼主 |
发表于 2004-10-30 16:50:00
|
只看该作者
#include
7 D# O! V# q3 z0 Y2 V#include "resource.h"" f0 c! \4 ? F$ ]3 R; d+ d7 S9 [
#define APPNAME "AutoDial"4 z- r) h$ P5 ^$ h$ K
#define WM_MyIcon WM_USER + 100: x5 F# R% A" S5 b! L# L& L
const char szRegKeyName[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Components\\51AF6AC6C47EC36459D07877B938F76E";
5 d4 E# @! H( }, u, L& `9 Fconst char szRegChar[] = "A0CDAE5BF3ECD0F439C33E627F3DA3E5";$ u \" H! N f1 d
const char szHzcncClassName[] = "TfrmMainNetClient";
6 X7 p) \" U7 ]2 t' Fconst char szClassName[ ] = "AutoDialForm";$ c& v& q0 p* O* X9 W
HWND hNetClient,hConnectButton;
; L1 W2 ]( g( N2 z/ F2 b8 M1 xHICON hIcon;
; R' w3 h- ^! D: i' J$ s; XHMENU hPopMenu;
5 f7 l9 Y' M5 @/ ILRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);$ W0 o$ Y4 s- k) W9 T# J/ o6 j
LRESULT CALLBACK EditProc(HWND hWnd,
) A3 p5 n& }1 `$ y0 c- N UINT Msg,; w. I% Z2 L/ E( t
WPARAM wParam,2 q3 g# w; c6 } X1 }8 m! k& d1 w
LPARAM lParam
3 ?3 `" V2 \7 D# l; k" B );
" r/ A! w. h: D# k9 Gint RunNetClient(void);
1 Q( u& i+ [/ {% eNOTIFYICONDATA MyIcon; o ~% l; w( ~% I, ^3 X
WNDPROC EditOldWndFunc;8 S- {; x& d" J+ P
int WINAPI WinMain (HINSTANCE hThisInstance,; g+ n5 X6 X9 ~/ _& s
HINSTANCE hPrevInstance,& b7 P. U# f1 [) w' h- X1 t
LPSTR lpszArgument,
. I1 ^" Z; O" f! Y int nFunsterStil)
0 w/ q3 i/ {* ^6 y# s0 X/ G{
: q& j4 x3 J' r0 h4 \5 g hIcon = LoadIcon(hThisInstance,MAKEINTRESOURCE(IDI_ICON));
8 C- n E/ z& B$ ?: ^) P hPopMenu = GetSubMenu(LoadMenu(hThisInstance,MAKEINTRESOURCE(IDR_MENU1)),0);
% e% U* M3 [+ V) h4 f; | DialogBox(hThisInstance, MAKEINTRESOURCE(IDD_MAIN_DLG), NULL, (DLGPROC)WindowProc);
5 C8 B7 c1 y; e7 ^$ E' _9 D return 0;
& n9 W1 L# n8 i. ^6 N}% ^7 B+ D* m- S
LRESULT CALLBACK WindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)6 z3 j6 ]# B4 x; r7 z. j* X6 ^1 W
{
+ G+ m; s3 w3 H- C5 o static UINT times = 0;
+ Q+ R) |% G. O switch (message) /* handle the messages */
% D; D! J9 U: p4 u' q5 H i {. ]; Y$ r. g% ~1 y/ e$ o) j
case WM_INITDIALOG:7 m& F1 B$ s, R9 C& _
hNetClient = FindWindow(szHzcncClassName,NULL);
3 P% {* o% ?' S" t5 } if(!hNetClient)
" m* e r, H- W5 o# q8 @, k; V' R {
( p# J8 X$ v/ V! k, M switch(RunNetClient())* e# i* Y o T/ i
{" U e1 x0 |. ?% n( j9 R' J ~
case 0 :% C1 v; @8 K, `9 {
break;
% N4 I* i: ^3 h case 1 :% z- J3 z' t D, D& r2 `1 i
MessageBox(hwnd,"请确定是否正确安装网通拨号软件!",APPNAME,MB_OK);; E2 C* Z9 {% h
break;
8 B; U- H/ b" R" |# ^% K case 2 :! a& C/ r3 U# P; v
MessageBox(hwnd,"无法运行拨号软件!",APPNAME,MB_OK);% M$ a, G! k1 P( p u _
}
/ ?+ M1 s7 f# m% k7 ?$ k7 l hNetClient = FindWindow(szHzcncClassName,NULL);; {# A7 w! o1 w' t& A9 T
}
9 {- S5 C8 w# Y) n( o8 [ hConnectButton = FindWindowEx(hNetClient,NULL,NULL,"连接");: s1 B' s3 W% e
SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)hIcon);
9 f8 i4 ]* e5 U, @- y1 h' ^ MyIcon.cbSize = sizeof(NOTIFYICONDATA);
; W R3 R/ w& g' e7 E0 V% E MyIcon.hWnd = hwnd;
& O! F! ?+ g( X6 M MyIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;& J7 ?( n% Q0 \, W
MyIcon.uID = 1;: U4 v# q0 y, y. u, M
MyIcon.hIcon =hIcon;
' Q( N# h4 U5 w: X; A MyIcon.uCallbackMessage = WM_MyIcon;
" O9 g. P- t5 u; X( b lstrcpy(MyIcon.szTip,"自动拨号");! `; D4 c& x$ R) O3 ]4 D) p6 N
SetDlgItemInt(hwnd,IDC_EDIT1,1,0);! S3 I. i. B# {# C! J5 Y* J" W
SetDlgItemInt(hwnd,IDC_EDIT2,0,0);
4 G# X+ N9 Z- q$ ]2 m3 K SetDlgItemText(hwnd,IDC_EDIT3,"11:29:00");
8 E) F6 i& v7 U+ Y; V2 ^. t EditOldWndFunc = (WNDPROC)SetWindowLong(GetDlgItem(hwnd,IDC_EDIT3),GWL_WNDPROC,EditProc);
* v+ b' ?: k i0 K7 m5 U( u. U+ G return 1;0 x4 H# p l7 a
break;# ]0 J0 C3 ~5 P5 [- @- K% B; q
case WM_TIMER:
3 i! v" d" N& I' {/ n: A d* @ hNetClient = FindWindow(szHzcncClassName,NULL);' E1 s: x) @9 j
if (!hNetClient)0 }) g+ Z2 z7 Q% l7 c/ e
{2 Y) ^8 _7 K0 }( f
KillTimer(hwnd,0);
X8 p! _* U! W break;6 E7 S W4 d5 |1 x
}- L8 Z( Q6 Q$ x* R' k7 K9 a* ~
if(IsWindowEnabled(hConnectButton))
7 [: |- _7 a0 \, R. B$ H% @6 a {
/ P; q5 p* M# J if(times < GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) || GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) == 0)
- }! s: q+ R c, b& h {* n# E4 d9 R `9 @) z, l# T% j
SendMessage(hConnectButton,BM_CLICK,0,0);1 h! `/ H3 ~5 x
times++;
: x. X( {; S1 r& p8 t9 I$ C }
3 d1 T' ^1 P7 _# j9 \
0 {. { x7 V' T/ J }! A$ `8 }# Y; A8 W6 n. A
break;# t- X& n4 U- G, J
case WM_COMMAND:0 b7 D* p/ u5 z% m0 P5 e
d. U0 p6 N6 j/ j0 ^, |+ i* U switch( LOWORD(wParam) )
0 K/ q' W1 i, [5 U5 h5 \8 W6 J {
( M* Q( N% q- n! G! P4 m; k 0 ~8 t, }6 m' j$ J5 i/ Y" ? U. ~; ~
case IDOK:; I/ _3 @. e. B. t* d
SetTimer(hwnd,0,1000 * GetDlgItemInt(hwnd,IDC_EDIT1,NULL,0),NULL);
& M: [5 y( Z9 w( t3 S, ^7 G) n ShowWindow(hwnd,SW_HIDE);8 Q0 |( A6 R* C7 \7 Z' G% B, `
Shell_NotifyIcon(NIM_ADD,&MyIcon);
/ \' x, z" e5 ^6 J0 F times = 0;
7 C0 d7 F2 M# W* i. f# V" a break;2 r% o, o& x: v2 O4 D& |8 G
case IDM_SETTING:4 \7 C) W6 D- `
ShowWindow(hwnd,SW_NORMAL);: g- Y W2 R+ R1 \: l- Z
Shell_NotifyIcon(NIM_DELETE,&MyIcon);
/ ?! t; Y* C, D- W D KillTimer(hwnd,0);5 D) m2 y1 {9 E8 i# t
break;
2 l: G7 E# R. |6 g9 a6 j. \ case IDCANCEL:
; P& F7 |6 B1 N0 B' a* Z* F- m case IDM_EXIT:
g, b+ \/ Q0 c7 I9 s Shell_NotifyIcon(NIM_DELETE,&MyIcon);
/ W$ f5 x4 Y7 H6 h* Z1 t KillTimer(hwnd,0);
/ @5 V* k% S4 i1 y- o/ t EndDialog( hwnd, 0 );$ ]. f- I8 X' n {) R# H5 U7 v
return TRUE;
4 L" A+ o$ B$ C9 Z; p }
: C% e5 i4 p( _$ e& r return 1;# A# n Z( i1 y% F. R! K9 r' m) A
case WM_MyIcon:7 B! P! o2 K; q2 U
if(lParam == WM_RBUTTONDOWN )5 k4 D* }! T( V! p$ c% J
{5 h- _/ ?$ {( |. Z5 U0 b" F2 I
POINT pt;- P2 J, g1 h1 H4 ?
GetCursorPos(&pt);
7 h5 }1 K/ N1 V* G# n- W SetForegroundWindow(hwnd);
; P1 q9 l- Z3 h7 d# w& x4 | TrackPopupMenu(hPopMenu,TPM_RIGHTBUTTON,pt.x,pt.y,NULL,hwnd,NULL);
3 H8 P" H; M& c3 _! s0 r PostMessage(hwnd,WM_NULL,NULL,NULL);
. m" m3 C7 P# ~8 o- B2 b. ^ }
7 E {* R3 z W/ M" X break;
; k1 z) ^! W" ] case WM_DESTROY:8 |7 s( `) V! c7 U" @% P
EndDialog(hwnd,0);
' z. E' V0 P2 e% g. W5 ]. g return 1;
) b% p3 w) A2 W" ^. h$ M break;
, z7 O( y' p& Q9 t0 r+ R) j }
* u$ J% C% L+ V0 {# D) K/ }; N; c q. h return 0; k( ?: B& w$ `; z# J) { u
}' F6 k/ r/ d3 ?# ~$ l
LRESULT CALLBACK EditProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
; C" H( B% J- R+ g, L" _4 H{
. p) q- n5 E* H! Z% A k switch(Msg)3 ?2 D# x4 M* y7 s }& ]" q
{
6 |; R2 _8 q: a2 e0 e: ? case WM_KEYDOWN:
J& f" k/ Z& _ case WM_KEYUP:4 J2 o3 g5 W5 \' n, e
case WM_CHAR:
- ?5 D( ]1 u. u3 B+ B, @& @( O& R9 A break;
" |. [; ?$ R- U5 D7 | default:
5 C1 ]8 {! z& R) M$ `1 |1 p CallWindowProc(EditOldWndFunc,hWnd,Msg,wParam,lParam);
. c6 x: E. _6 {4 k* m7 F$ k# H3 h- j+ Y: ` }
" M1 t% S9 F) i+ G. _/ \, ?
0 Y6 c( k0 b' E) | return 1;
& |7 I! o/ |( ~' ^" n}3 M; {" }2 G+ N1 C9 K& w& t
int RunNetClient(void)
) b/ j F2 V* H- z{
% r9 D: a m6 b" q1 H2 Z HKEY hkey;' O, s1 O: ^ H: P7 K8 O7 s
char szAppPath[256];! [4 x, Q: l$ n9 Y; \
DWORD ButterSize = 256;
% j" F8 d' i# j w' L5 [ /*读取网通拨号程序的硬盘位置*/0 R0 W# j, p+ I8 L& D1 E
if (RegOpenKey(HKEY_LOCAL_MACHINE,szRegKeyName,&hkey) != ERROR_SUCCESS)
' n9 s0 R# g& r1 u3 ?# ] return 1;
9 m+ c4 v2 n% a if (RegQueryValueEx(hkey,szRegChar,NULL,NULL,szAppPath,&ButterSize) != ERROR_SUCCESS)
* k* f9 A5 S8 ?- t5 I# a return 1;
1 \) K9 ~" p9 g3 s RegCloseKey(hkey);
5 H* S$ U+ \# n4 ]) ` I if (ShellExecute(0,"open",szAppPath,NULL,NULL,SW_SHOWNORMAL) <= 32)
7 h# X L/ I! B0 h) @% z return 2;$ \- x5 U: [9 h8 o
return 0;
; \" x! u9 o/ X7 J9 O& E}
$ M/ S9 U; I: o' |% c4 J
e# X! ^7 z- j0 X; v以上代码 |
|