|
4楼
楼主 |
发表于 2004-10-30 16:50:00
|
只看该作者
#include
a% ^9 W: _. L, `# E1 `2 {#include "resource.h"6 v9 A( _0 r; n* Z2 \3 Q3 A
#define APPNAME "AutoDial"
8 `: s* L& D) S$ z#define WM_MyIcon WM_USER + 100# p/ |0 A/ X4 G4 e
const char szRegKeyName[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Components\\51AF6AC6C47EC36459D07877B938F76E";2 u8 y' s* N3 v( k6 j3 _
const char szRegChar[] = "A0CDAE5BF3ECD0F439C33E627F3DA3E5";
" [$ l. `; [8 y3 x- cconst char szHzcncClassName[] = "TfrmMainNetClient";5 v. T4 ?6 {8 V# L
const char szClassName[ ] = "AutoDialForm";
& G7 |$ {6 f( `# n% z6 r. K3 ?HWND hNetClient,hConnectButton;
, r/ s: G6 o( r8 v& rHICON hIcon;; [* e% x, f' i
HMENU hPopMenu;
* f' n- A9 f0 t4 V U8 ULRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);+ \2 ?- B) w* D W
LRESULT CALLBACK EditProc(HWND hWnd,9 t3 Z# t3 y( M9 R
UINT Msg,
) n9 G5 T2 Y8 t' m; _$ G7 \, ?" E WPARAM wParam,/ U8 D9 m9 E# _/ t( H
LPARAM lParam7 L5 C- h2 ^9 `/ }% c# k
);6 I7 Y) }! r3 q& A* R& ]
int RunNetClient(void);
7 V$ v0 L$ `! `- TNOTIFYICONDATA MyIcon;
; H* ?6 M' @6 u. i4 v& ], s. w, cWNDPROC EditOldWndFunc;$ m& v# \ h1 y* D) {: d
int WINAPI WinMain (HINSTANCE hThisInstance,
$ Y: B+ m; P$ R# W. m. V; ~ HINSTANCE hPrevInstance,
5 R! ^( e$ p" ]6 `3 m LPSTR lpszArgument,
: K) a7 W& m8 Q0 P! W int nFunsterStil)
# Z+ l1 Q2 x* {1 K* c) _{
' [2 Z" I; R" `1 D; D hIcon = LoadIcon(hThisInstance,MAKEINTRESOURCE(IDI_ICON));* y* ]- R! A+ z4 l/ j
hPopMenu = GetSubMenu(LoadMenu(hThisInstance,MAKEINTRESOURCE(IDR_MENU1)),0);2 {4 X/ m1 w4 W: l7 P
DialogBox(hThisInstance, MAKEINTRESOURCE(IDD_MAIN_DLG), NULL, (DLGPROC)WindowProc);4 M. N3 I6 v Q
return 0;3 T% ^6 i% D- l" M8 ?, h
}' `% U- j2 m) d) k7 A. o4 P
LRESULT CALLBACK WindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7 v$ S9 Z8 k. I{4 }* N" _2 o7 i% @. @
static UINT times = 0;& s# V {* x3 K3 Q: {2 t l
switch (message) /* handle the messages */
) }9 S9 w% |6 `! s {
- s9 j2 {7 Y8 u case WM_INITDIALOG:' L. A% L; d; y, |
hNetClient = FindWindow(szHzcncClassName,NULL);
/ D5 P0 T% K3 S) U0 s+ t if(!hNetClient)4 @( b. X7 T* M6 K _
{: m |! Y- e9 q/ I- }
switch(RunNetClient())* ]0 D5 X" b0 y; h F+ p9 Q# Q5 B
{; l [# _4 ]6 k' l% M4 x+ B
case 0 :6 @ \" B% ]6 Y5 X$ H2 X
break;8 Y* \0 `7 m: o7 t' Z
case 1 :
7 s$ Q% E& o: J7 t& i7 Q MessageBox(hwnd,"请确定是否正确安装网通拨号软件!",APPNAME,MB_OK);# ?. g" ? [) D6 z
break;
8 {. O6 ?* C; X( t/ v. [" k case 2 :
$ K& q) u& P1 a3 X9 D' I MessageBox(hwnd,"无法运行拨号软件!",APPNAME,MB_OK);
+ o& u5 R% A/ H' h+ ] }
6 |, Z9 T* J% y1 G hNetClient = FindWindow(szHzcncClassName,NULL);" W" c& d, c' _: p/ K
}& X m1 N. R! D& h0 o
hConnectButton = FindWindowEx(hNetClient,NULL,NULL,"连接");
' B# V. X8 K O4 Z W/ p SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)hIcon);; W; M ]) Y" w& }4 r- [ Q0 F
MyIcon.cbSize = sizeof(NOTIFYICONDATA);7 A- C; l3 R5 `, z& n
MyIcon.hWnd = hwnd;$ F4 w* T+ G( H o
MyIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
% u2 g) P6 f! K' _! |+ h* D4 u E MyIcon.uID = 1;! ]1 ]6 g0 C- N$ G; R2 [
MyIcon.hIcon =hIcon;
8 @* k- {) d/ i' [ MyIcon.uCallbackMessage = WM_MyIcon;0 L* F4 q& f4 \1 u6 o' z( h
lstrcpy(MyIcon.szTip,"自动拨号");& t/ x6 X/ A4 r$ p1 d; D
SetDlgItemInt(hwnd,IDC_EDIT1,1,0);9 V2 k4 v ~' R+ z4 r: U) Q3 v
SetDlgItemInt(hwnd,IDC_EDIT2,0,0);
; s6 J2 {$ X5 m# A SetDlgItemText(hwnd,IDC_EDIT3,"11:29:00");2 E4 c! J: D8 E ^0 T4 Z
EditOldWndFunc = (WNDPROC)SetWindowLong(GetDlgItem(hwnd,IDC_EDIT3),GWL_WNDPROC,EditProc);
& |( t0 a8 G' i R return 1;
$ l, C: ^- u G B+ V break;
# x- a1 j7 t L+ T/ b case WM_TIMER:
( m h& i' v: [" `5 W; C hNetClient = FindWindow(szHzcncClassName,NULL);
9 n: u' f5 i2 {& B' v if (!hNetClient)
$ }% r* Z+ ]! F W7 f0 O {
# ^4 T+ j) _2 z2 V( j" S KillTimer(hwnd,0);
0 a1 @" W; L( ?/ p- D; g break;
8 m8 A/ c: ?/ D/ C }
( [% i6 ]! x5 |9 I6 v5 o9 b if(IsWindowEnabled(hConnectButton))
; n1 F* B& {) S$ ?& f Y {. N" _% p9 I8 _$ J r
if(times < GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) || GetDlgItemInt(hwnd,IDC_EDIT2,NULL,0) == 0)7 j' ?* i$ F5 y3 t# `4 X3 J
{
: E7 w; A& d o1 W, g SendMessage(hConnectButton,BM_CLICK,0,0);
# e Y8 B: j0 ~0 I+ Z times++;0 M! f' Q# q5 W @/ Y
}% c0 B' O6 r4 g* ]# f
- v! {3 ^9 x; l! f2 i }
- O' [1 s& k8 a break;
" n1 c5 O" K. T1 O, o& p/ i case WM_COMMAND:
' a0 h" p9 ]$ Y2 D6 P
2 I: b% W- k' W) ] G( }; @. M switch( LOWORD(wParam) )
/ `* G0 R# K U8 I& a, S {* O# J; e5 I3 G$ W9 Q
1 o1 u& k; _& m+ O7 Q$ S, `; i6 t
case IDOK:/ F, n+ y8 m% H
SetTimer(hwnd,0,1000 * GetDlgItemInt(hwnd,IDC_EDIT1,NULL,0),NULL);
5 u0 D/ v! L8 s# k- i5 ] ShowWindow(hwnd,SW_HIDE);
+ J' G% b+ M$ y! L, { Shell_NotifyIcon(NIM_ADD,&MyIcon);0 q4 P& G) y) y& p
times = 0; u7 c3 ^& ?$ H8 }* t. b
break;) y9 B) I. _" p& F# B4 S, x! `0 O5 p P
case IDM_SETTING:
* p% `' [& T+ X* ]3 D ShowWindow(hwnd,SW_NORMAL);
* ~: o! h1 U5 y2 t: d Shell_NotifyIcon(NIM_DELETE,&MyIcon);6 t7 x* w0 `) Z/ `( b7 q, y
KillTimer(hwnd,0);
y5 ]" ~ w; m4 G- N break;
9 b6 e* @6 i; u* |) t case IDCANCEL:
$ D/ t" V( Y- J% M9 |& ]5 M9 A# q case IDM_EXIT:3 U. w/ `% }! K0 h
Shell_NotifyIcon(NIM_DELETE,&MyIcon);
" ~' y* \. k6 @; S1 j5 v KillTimer(hwnd,0);4 W" _6 c6 ]' I9 ]4 c
EndDialog( hwnd, 0 );
' y$ w/ E- c% }/ q. M+ a return TRUE;0 R8 G) C1 j- ^ d
}
6 h; ]/ B% _! {5 W3 f- Q return 1;+ _6 r, d. A# Q' I# i+ r C
case WM_MyIcon:+ I M& m# Y/ c) z! ^9 C
if(lParam == WM_RBUTTONDOWN )0 k$ C* I& s) w6 E
{$ A6 a5 v# C% d
POINT pt;
4 N5 K# Y Q+ S* I8 g0 k GetCursorPos(&pt);6 f. @% a) w; k `. b
SetForegroundWindow(hwnd);1 r% W4 F/ N% s2 B) [& U
TrackPopupMenu(hPopMenu,TPM_RIGHTBUTTON,pt.x,pt.y,NULL,hwnd,NULL);
# T9 q5 Y u0 x# w' | PostMessage(hwnd,WM_NULL,NULL,NULL);# p8 G' t" k5 v& G) D' B
}
& V- n, d9 q4 ^) i3 E0 [ break;
+ h8 l6 X; {/ t4 Z" s case WM_DESTROY:
( q* r6 S, ]; B5 I8 H EndDialog(hwnd,0);
* i; m6 {+ F; S return 1;; `2 V+ E8 K4 ]5 D) {
break;: a7 g3 H4 J0 t) _9 }
}
4 |. v1 } T5 L$ `4 b* C return 0;
4 D2 l" ]: _& A0 y}
& E+ \) Q% d/ m+ XLRESULT CALLBACK EditProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)2 f( W, H& f* M$ b: J
{; N$ S5 S; l/ t5 g' V2 S, B- A) Y
switch(Msg)2 v: H- m/ R6 \/ [
{
, H3 y: V. ?3 v/ g P1 k case WM_KEYDOWN:
9 |; E% Q* ^' E case WM_KEYUP:4 a: {0 l. F0 F
case WM_CHAR:
' o( a; J& a0 \, M- L" @ break;. o0 Y$ v6 u R1 g; ^' B
default:6 T1 N G, K7 \+ {6 C$ b
CallWindowProc(EditOldWndFunc,hWnd,Msg,wParam,lParam);
4 t! o1 `1 Q* C: G }) j# i4 F8 f9 j' ?# J7 S
: q/ z& C" d# F7 `7 S) _
return 1;# S2 o. w+ z p
}' v# g" ?6 U+ X {' A: q! i
int RunNetClient(void)/ |% O; ]8 [+ [
{
7 z1 P# h6 S( J HKEY hkey;+ l5 r# W* m, _2 A1 v
char szAppPath[256];9 h! d+ r2 c8 R7 N
DWORD ButterSize = 256;: }6 M: R# i2 t+ P7 P
/*读取网通拨号程序的硬盘位置*/
4 i! s3 f, ]* @4 y! d* m1 i) c$ K if (RegOpenKey(HKEY_LOCAL_MACHINE,szRegKeyName,&hkey) != ERROR_SUCCESS)
2 A8 P8 Z7 n2 _' S# h& s return 1;
9 q+ m# ] k+ i+ o- m, X3 ~' N5 E f+ c if (RegQueryValueEx(hkey,szRegChar,NULL,NULL,szAppPath,&ButterSize) != ERROR_SUCCESS)1 z+ _3 w8 H8 J( l0 F4 x1 A. F
return 1;
5 J9 v" k1 L5 [) f) m8 \' k6 E RegCloseKey(hkey);( |9 `% _; N6 U, L. s0 p
if (ShellExecute(0,"open",szAppPath,NULL,NULL,SW_SHOWNORMAL) <= 32)9 _5 U0 c1 f. K/ A( B: w# B- F
return 2;, c; {# \ n+ }. y8 W
return 0;
^( t2 `" {- Z# I}
2 Y/ v) E1 e0 n8 t! @: z; [; X5 [0 i/ ]
以上代码 |
|