|
4楼
楼主 |
发表于 2004-10-30 16:50:00
|
只看该作者
#include . b1 P7 i: I0 l$ ?' E ~5 m
#include "resource.h"% B' q/ H* H; H- T- ~$ k+ I
#define APPNAME "AutoDial"
7 k: d5 c/ D3 g) }9 H8 C#define WM_MyIcon WM_USER + 100
/ \% Y8 t) s1 g7 dconst char szRegKeyName[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Components\\51AF6AC6C47EC36459D07877B938F76E";) x, D# G# L( k0 V& ?$ j4 i+ @* _
const char szRegChar[] = "A0CDAE5BF3ECD0F439C33E627F3DA3E5";+ E( o; ]0 r. w$ _
const char szHzcncClassName[] = "TfrmMainNetClient";
: q+ l3 J7 I/ m* s/ | E. iconst char szClassName[ ] = "AutoDialForm";) C. h$ R% h0 E8 p7 K9 k7 _* b" z+ o( _
HWND hNetClient,hConnectButton;' x* M) N3 c8 Z8 G* l/ @% ?
HICON hIcon;/ j$ N0 l1 M2 X' T" W {
HMENU hPopMenu;% B( X4 b$ ?- s
LRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);& A) ^" Z" Y: X9 n( i
LRESULT CALLBACK EditProc(HWND hWnd,
6 }$ U6 ?! n, z" U- L UINT Msg,
% E( ~1 k- [. K WPARAM wParam,
' t; j4 \& U( [7 H' q8 u$ e! q9 n LPARAM lParam# C% [4 o3 ^8 N& a: {3 l
);( @" ?) t. R! M1 [$ @
int RunNetClient(void);
1 }7 h8 w- F4 A: TNOTIFYICONDATA MyIcon;, \7 @; `2 P6 \7 `" z( r$ \5 v. V
WNDPROC EditOldWndFunc;+ A! y9 ?. W& p$ t/ B& N$ c
int WINAPI WinMain (HINSTANCE hThisInstance,% q( |, F* t! O6 d
HINSTANCE hPrevInstance,
% _8 \& o6 G. J. ~6 i! s6 i# h* j LPSTR lpszArgument,# r: H" D( V! t2 w J
int nFunsterStil)# \1 C7 l8 ^* o i( r
{: n5 F8 K) |* p& t
hIcon = LoadIcon(hThisInstance,MAKEINTRESOURCE(IDI_ICON));) e9 ]4 s R6 g
hPopMenu = GetSubMenu(LoadMenu(hThisInstance,MAKEINTRESOURCE(IDR_MENU1)),0);5 q3 v. l- L$ h" J4 \) {9 b$ b
DialogBox(hThisInstance, MAKEINTRESOURCE(IDD_MAIN_DLG), NULL, (DLGPROC)WindowProc);4 x$ _- ~1 k2 U& L I
return 0; w1 u9 }, u* m" q
}/ x/ i% D6 Z3 M' b2 g
LRESULT CALLBACK WindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)" z* z; T7 ^6 _: Z& T
{! p/ S, A+ u- w8 t: o# N7 L1 d' V
static UINT times = 0;& R Q0 U; E9 O% m
switch (message) /* handle the messages */+ t! G0 |* ]/ E! j6 ~8 _. L4 {2 y
{
$ K' R6 I7 N1 c0 G. a case WM_INITDIALOG:
7 `+ m6 a4 G$ E: h8 F hNetClient = FindWindow(szHzcncClassName,NULL);( @* a: l1 I- @
if(!hNetClient)
8 _' J( u9 D" V: k {
, [7 T6 D. b0 V3 X' H switch(RunNetClient())7 l$ e5 Y7 _, V; a1 L" ]; q9 ?
{8 N J2 q4 j! X0 `. @: V) h7 D
case 0 :
% X* V9 M5 t$ q+ u# ` break;4 Q- P: u) j; V$ ^ N
case 1 :* u8 W8 `/ `+ _9 c. [; `% l
MessageBox(hwnd,"请确定是否正确安装网通拨号软件!",APPNAME,MB_OK);' E: d! J2 P2 u, L5 a' B. l: W
break;
/ H7 o# D! q1 x/ e: l( k case 2 :4 R7 J9 M; d# J6 O) j
MessageBox(hwnd,"无法运行拨号软件!",APPNAME,MB_OK);
& j, L4 r3 \! q) D" N! T4 M }
7 b' M& d0 q+ W) x `1 U! Z$ b+ `& J hNetClient = FindWindow(szHzcncClassName,NULL);
1 U) g6 N# O1 A }
0 D. ^. i/ m: _& B8 U$ B" @. D1 F hConnectButton = FindWindowEx(hNetClient,NULL,NULL,"连接");
& s( S- L" @1 Y% m SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)hIcon);
; L4 L, w, v! }3 E MyIcon.cbSize = sizeof(NOTIFYICONDATA);% S! v# R e! [# l% u
MyIcon.hWnd = hwnd;* ]* x3 _7 [( \+ K1 W' [
MyIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;% R" A3 I- e( G1 d* j- N
MyIcon.uID = 1;
. |# B# O x& y/ \* N9 k) Y9 h3 j MyIcon.hIcon =hIcon;7 e& U+ Z& F. h5 o
MyIcon.uCallbackMessage = WM_MyIcon;
- {' u# G' t0 l/ H8 I& G3 d lstrcpy(MyIcon.szTip,"自动拨号");& i6 u- X; G2 @0 ]/ ]2 Q* H% H& L7 E
SetDlgItemInt(hwnd,IDC_EDIT1,1,0);2 p& n& g8 M1 k4 |& K; U
SetDlgItemInt(hwnd,IDC_EDIT2,0,0);
2 j1 _( F9 t. m9 s$ P$ C4 U5 b u& l SetDlgItemText(hwnd,IDC_EDIT3,"11:29:00");, g/ i2 J0 B1 T+ h5 h$ F% {
EditOldWndFunc = (WNDPROC)SetWindowLong(GetDlgItem(hwnd,IDC_EDIT3),GWL_WNDPROC,EditProc);0 i" T% @5 j$ T5 Z) y3 G: @( T
return 1;
, n: V) x" i' s3 H break;
/ s$ y; Q7 h3 Q3 u Y& ^& o e case WM_TIMER:
. P- J6 {- j: w2 L8 W2 ?# I; P5 }2 b hNetClient = FindWindow(szHzcncClassName,NULL);2 j& V( z% v5 [8 L) ~9 E5 X2 C
if (!hNetClient)7 B; C* ?% j$ I2 @3 Y! Y0 g
{: m8 ]9 i9 k t- q: p2 |
KillTimer(hwnd,0);( x& k/ M/ M! z! b
break;+ A4 F; Y3 d/ R
}
7 O( y2 q0 g( p" s! J8 S- T3 a if(IsWindowEnabled(hConnectButton))" z4 Q* u& Y4 m. P) ^% i
{
* X# h z- |) I6 }* h if(times < GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) || GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) == 0)% j; C5 S* r. _+ k7 y
{
& I- c" b k6 k( J SendMessage(hConnectButton,BM_CLICK,0,0);) E6 ^) R4 g* M$ r, V
times++;
" n- c5 g5 S+ l# U/ K }
3 ~- M) f; E( r6 I 1 W. [5 [& W& k) U2 u2 Q
}2 H; Z, T7 P$ x) ]: |1 d
break;
4 [/ v0 p: R+ S8 k/ D0 A" t) F2 ? case WM_COMMAND:
$ C3 }3 ^. N0 ~
C0 V$ a: d& v& ~9 w! P switch( LOWORD(wParam) )( o6 B0 W& {; ], {0 b
{
( R" G0 e5 {; B; y3 B
# M( ~+ j: D. O" C7 y case IDOK:
' N* {8 b$ ^6 m* h SetTimer(hwnd,0,1000 * GetDlgItemInt(hwnd,IDC_EDIT1,NULL,0),NULL);
[& ]5 b }3 c2 W& c! R4 \" e- Z6 b ShowWindow(hwnd,SW_HIDE);1 I; Q4 X0 a" }" u! M- d1 {
Shell_NotifyIcon(NIM_ADD,&MyIcon);
+ E& Y: U; i1 H: T2 E8 Z3 O times = 0;6 g7 @) _3 b; |9 ?, K
break;
9 p3 c1 d/ ~* f& ~ case IDM_SETTING:
# p1 M2 I3 H- U7 V d ShowWindow(hwnd,SW_NORMAL);0 M I7 H. H) j' z, c( T1 E w
Shell_NotifyIcon(NIM_DELETE,&MyIcon);+ Z5 ?. c1 M3 O2 G9 D8 a# v1 F0 Y
KillTimer(hwnd,0);6 ]* |9 h" i8 ~8 c
break;: I7 F/ N/ L. L2 a* P1 c" o
case IDCANCEL:- {: A* D5 h% \
case IDM_EXIT:/ c9 S2 o4 q, {2 _. ?6 \
Shell_NotifyIcon(NIM_DELETE,&MyIcon);
5 Y, B/ B% w! W" D* t9 u KillTimer(hwnd,0);# A7 b% F# k8 w
EndDialog( hwnd, 0 );1 L: x% y0 S8 @
return TRUE;
9 [' `# d; ~# r& @& \( ~* V }
. q: q5 h5 b% g2 L) C' o! u( q return 1;
! A* w7 U7 N& B1 l case WM_MyIcon:
- q n7 [2 \9 n, Y if(lParam == WM_RBUTTONDOWN )7 U% O+ @3 x6 s8 y; c! j
{2 @5 X3 H c: U" P; v+ S" D/ o! y
POINT pt;8 q S+ @! G! x" m3 i
GetCursorPos(&pt);
" U! H+ @* m) r8 m6 B' f, J SetForegroundWindow(hwnd);
4 S& V& @8 b; T4 _0 Y- V TrackPopupMenu(hPopMenu,TPM_RIGHTBUTTON,pt.x,pt.y,NULL,hwnd,NULL);, O) a" D5 u& V
PostMessage(hwnd,WM_NULL,NULL,NULL);
4 L& k7 R. i6 n5 j. I: f$ K }! @, h) |. N7 {$ j/ A8 Z! I i
break;8 F; f1 e8 k5 F; c
case WM_DESTROY:( _1 M2 r z6 f/ z" U0 q
EndDialog(hwnd,0);
0 g% G" n* [9 U# F4 P4 z* A/ } return 1;6 ]* b( R8 o. w
break;
! a, X W1 X. a$ U }
& T6 P5 [7 H, ?* x5 V% o& k return 0;: {& Z) a2 }2 i6 q; { j
}% ?' @" K$ e# w# W! H- k$ E, s- Z* F0 ~
LRESULT CALLBACK EditProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam): \: b0 `- _* }: z6 {) K
{
, o7 u2 t0 R9 t; p switch(Msg)) h# G/ n5 P6 f1 [( F0 J7 N
{+ L" y9 ^' W- h
case WM_KEYDOWN:' S/ K l& z* `0 |, J' a8 n
case WM_KEYUP:
% G( c# W3 M8 r: O- w case WM_CHAR:9 J8 D$ i7 {) C% Y% D$ a
break;9 t( G6 p% P3 Y2 m8 j
default:% `5 t' P4 K: s8 I* ~4 z
CallWindowProc(EditOldWndFunc,hWnd,Msg,wParam,lParam);# w5 S8 i' f- Z# t0 k/ [
}
3 `$ H i- m E) J& _& C/ Y
7 j; B( J% i6 V return 1;9 h7 E: v0 \" ?* j& O1 R
}2 B) N0 Q5 ^& D( c9 ^' o; C
int RunNetClient(void)
5 k+ m4 g0 D/ E# R{
% P' o0 u( }9 T HKEY hkey;
) V' I/ Y) p; b/ t; I. W6 U; o char szAppPath[256];% n; I( k b% F7 T) p* t4 n3 c3 T7 ~
DWORD ButterSize = 256;6 s k E7 T& L% a2 |7 e c" s
/*读取网通拨号程序的硬盘位置*/
/ x" L0 Y0 a$ [% u; i# w& i- ^ if (RegOpenKey(HKEY_LOCAL_MACHINE,szRegKeyName,&hkey) != ERROR_SUCCESS)
: L' A) w( C, O: U% G) O1 C, l2 B return 1;1 c h& s& ]* n9 [( Z
if (RegQueryValueEx(hkey,szRegChar,NULL,NULL,szAppPath,&ButterSize) != ERROR_SUCCESS)
4 |$ b- z5 Q+ W0 w2 j# P return 1;5 R7 u8 g' z7 r) _
RegCloseKey(hkey);
) p; v q3 p; [5 t if (ShellExecute(0,"open",szAppPath,NULL,NULL,SW_SHOWNORMAL) <= 32)) o. s; P, Q$ ^
return 2;
6 @3 }# `5 h+ f& U7 C9 f& }9 d$ ? return 0; n& R* w; e$ K) F/ {
}& W: E- C L$ ^% d8 Z- ~2 A" Q& i
" z. T8 M. B/ K: v3 ?! q7 a
以上代码 |
|