不用TIME控件如何实现TIME功能!(100分)

  • 主题发起人 主题发起人 lovenuo
  • 开始时间 开始时间
L

lovenuo

Unregistered / Unconfirmed
GUEST, unregistred user!
因为没有窗休的程序不能用TIME控件,怎么能实现TIME功能!<br>我要加在钩子里!程序运行10分钟后自动提示信息!<br>请给出代码!谢谢!
 
请给出代码!
 
就用api 啦,啦队createTimer,悄看看帮助就知道啦
 
帮助里没有找到,请你给出代码好不!
 
看看这个吧,人家写的一个自动定时的小程序,很精典的<br>program AutoShutDown;<br><br>uses<br> &nbsp;Windows,<br> &nbsp;ShellAPI,<br> &nbsp;Sysutils,<br> &nbsp;Messages;<br><br>{$R *.RES}<br>var<br> &nbsp;WinClass:TWndClassA;<br> &nbsp;Handle:hwnd;<br> &nbsp;Inst,Button1, Label1, Edit1: Integer;<br> &nbsp;Msg: TMsg;<br> &nbsp;tid: TNotifyIconDataA;<br> &nbsp;sdt:tdatetime;<br> &nbsp;timerid:integer;<br> &nbsp;hFont: Integer;<br>const<br> &nbsp;AppName='AutoShutDown';<br> &nbsp;st='定时关机';<br> &nbsp;About=st+' 1.0, Keyes.chen@263.net, Keyes 1999.10.23';<br> &nbsp;gjs='设定关机时间';<br>procedure SetShutdownTime;<br>var<br> &nbsp;Textlength: Integer;<br> &nbsp;Text: PChar;i:tdatetime;<br>begin<br> &nbsp;TextLength := GetWindowTextLength(Edit1);<br> &nbsp; &nbsp;GetMem(Text, TextLength + 1);<br> &nbsp; &nbsp;GetWindowText(Edit1, Text, TextLength + 1);<br> &nbsp; &nbsp;try<br> &nbsp; &nbsp; i:=Strtodatetime(Text);<br> &nbsp; &nbsp; if i&lt;=now then<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; MessageBox(handle,'不对吧!太早了.','错误',mb_ok or MB_ICONERROR);<br> &nbsp; &nbsp; exit;<br> &nbsp; &nbsp; end;<br> &nbsp; &nbsp; sdt:=i;<br> &nbsp; &nbsp; timerid:=Settimer(handle,1000,1000,nil);<br> &nbsp; &nbsp; Showwindow(handle,sw_hide);<br> &nbsp; &nbsp; lstrcpy (tid.szTip,pchar(st+' &nbsp;关机时间:'+Datetimetostr(sdt)));<br> &nbsp; &nbsp; Shell_NotifyIcon (nim_modify, @tid);<br> &nbsp; &nbsp;except<br> &nbsp; &nbsp; Killtimer(handle,timerid);<br> &nbsp; &nbsp; Messagebox(handle,pchar('关机时间设定错误'#13#10#13#10+'格式因该是:'+Datetimetostr(now)),AppName,Mb_ok or MB_ICONINFORMATION);<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;FreeMem(Text, TextLength + 1);<br>end;<br>function WindowProc(hWnd, uMsg, wParam, lParam: Integer): Integer; stdcall;<br>var pt:tpoint;pm:Hmenu;<br>begin<br> &nbsp;result:=0;<br> &nbsp;Case uMsg of<br> &nbsp;wm_timer:<br> &nbsp;begin<br> &nbsp; &nbsp;if now&gt;=sdt then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp;Killtimer(handle,timerid);<br> &nbsp; &nbsp;ExitWindowsEx(EWX_SHUTDOWN or EWX_Force, 0);<br>// &nbsp; &nbsp;PostMessage(handle,wm_Destroy,0,0);<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br> &nbsp;wm_User:<br> &nbsp;begin<br> &nbsp; &nbsp;Case lparam of<br> &nbsp; &nbsp;WM_LBUTTONDBLCLK:<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp;showwindow(handle,sw_restore);<br> &nbsp; &nbsp;setforegroundwindow(handle);<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;wm_LButtonDown,wm_RButtonDown:<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp;GetCursorPos (pt);<br> &nbsp; &nbsp;pm := CreatePopupMenu;<br> &nbsp; &nbsp;AppendMenu (pm,0,Ord ('S'),gjs);<br> &nbsp; &nbsp;AppendMenu (pm, 0, Ord ('A'), '关于...');<br> &nbsp; &nbsp;AppendMenu (pm, mf_Separator, 0, Nil);<br> &nbsp; &nbsp;AppendMenu (pm, 0, Ord ('E'), '退出');<br> &nbsp; &nbsp;SetForegroundWindow (handle);<br> &nbsp; &nbsp;if TrackPopupMenu (pm, tpm_BottomAlign or tpm_RightAlign, pt.x,{GetDeviceCaps(dc,Vertres)}pt.y, 0, handle, Nil) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetForegroundWindow (handle);<br> &nbsp; &nbsp;DestroyMenu (pm)<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br> &nbsp;end;<br> &nbsp;wm_Destroy:<br> &nbsp;begin<br> &nbsp; &nbsp; Shell_NotifyIcon (nim_Delete, @tid);<br> &nbsp; &nbsp; Killtimer(handle,timerid);<br> &nbsp; &nbsp; halt;<br> &nbsp;end;<br> &nbsp;wm_Command:<br> &nbsp;begin<br> &nbsp; &nbsp; if (lParam = Button1) then begin SetshutdownTime;exit end;<br> &nbsp; &nbsp; Case Loword(wParam) of<br> &nbsp; &nbsp; &nbsp; &nbsp; Ord ('A'): MessageBox (0, About, AppName, mb_ok or MB_ICONINFORMATION);<br> &nbsp; &nbsp; &nbsp; &nbsp; Ord ('E'): PostMessage (handle, wm_Close, 0, 0);<br> &nbsp; &nbsp; &nbsp; &nbsp; Ord ('S'):<br> &nbsp; &nbsp; &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp; Showwindow(handle,sw_restore);<br> &nbsp; &nbsp; &nbsp; &nbsp; end;<br> &nbsp; &nbsp; end;<br> &nbsp;end;<br> &nbsp;end;<br> &nbsp;Result := DefWindowProc(hWnd, uMsg, wParam, lParam);<br>end;<br><br>begin<br> &nbsp;{ ** Register Custom WndClass ** }<br> &nbsp;if FindWindow (AppName, Nil) &lt;&gt; 0 then begin<br> &nbsp;Messagebox(handle,'已经有一个AutoShutDown运行了',AppName,mb_ok or MB_ICONWARNING);<br> &nbsp;halt(0);<br> &nbsp;end;<br> &nbsp;Inst := hInstance;<br> &nbsp;with WinClass do<br> &nbsp;begin<br> &nbsp; &nbsp;style &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= CS_CLASSDC or CS_PARENTDC;<br> &nbsp; &nbsp;lpfnWndProc &nbsp; &nbsp; &nbsp; &nbsp;:= @WindowProc;<br> &nbsp; &nbsp;hInstance &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= Inst;<br> &nbsp; &nbsp;hbrBackground &nbsp; &nbsp; &nbsp;:= color_btnface + 1;<br> &nbsp; &nbsp;lpszClassname &nbsp; &nbsp; &nbsp;:= AppName;<br> &nbsp; &nbsp;hCursor &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= LoadCursor(0, IDC_ARROW);<br> &nbsp;end;<br> &nbsp;RegisterClass(WinClass);<br> &nbsp;Handle := CreateWindowEx(WS_EX_WINDOWEDGE, AppName, 'AutoShutDown 1.00',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WS_VISIBLE {or WS_SIZEBOX} or WS_CAPTION or WS_SYSMENU,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 283, 238, 325, 65, 0, 0, Inst, nil);<br> &nbsp;Button1 := CreateWindow('Button', 'OK', WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 236, 8, 75, 20, handle, 0, Inst, nil);<br> &nbsp;Label1 := Createwindow('Static', '', WS_VISIBLE or WS_CHILD or SS_LEFT,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 8, 12, 80, 13, Handle, 0, Inst, nil);<br> &nbsp;Edit1 := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', Pchar(Datetimetostr(now)), WS_CHILD or WS_VISIBLE or<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WS_BORDER {or ES_PASSWORD}, 88, 8, 141, 21, Handle, 0, Inst, nil);<br> &nbsp;hFont := CreateFont(-12, 0, 0, 0, 500, 0, 0, 0, GB2312_CHARSET,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DEFAULT_PITCH or FF_DONTCARE, '宋体');<br> &nbsp;if hFont &lt;&gt; 0 then<br> &nbsp;begin<br> &nbsp; &nbsp;SendMessage(Button1, WM_SETFONT, hFont, 0);<br> &nbsp; &nbsp;SendMessage(Label1, WM_SETFONT, hFont, 0);<br> &nbsp; &nbsp;SendMessage(Edit1, WM_SETFONT, hFont, 0);<br> &nbsp;end;<br> &nbsp;SetWindowText(Label1, pchar(gjs+':'));<br> &nbsp;SetFocus(Edit1);<br> &nbsp;UpdateWindow(Handle);<br> &nbsp; &nbsp; tid.cbSize &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := sizeof (tid);<br> &nbsp; &nbsp; tid.Wnd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= handle;<br> &nbsp; &nbsp; tid.uID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= 1;<br> &nbsp; &nbsp; tid.uFlags &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := nif_Message or nif_Icon or nif_Tip;<br> &nbsp; &nbsp; tid.uCallBackMessage := wm_User;<br> &nbsp; &nbsp; tid.hIcon &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= LoadIcon (hInstance, 'MAINICON');<br> &nbsp; &nbsp; lstrcpy (tid.szTip,st);<br> &nbsp; &nbsp; Shell_NotifyIcon (nim_Add, @tid);<br> &nbsp;while(GetMessage(Msg, Handle, 0, 0)) do<br> &nbsp;begin<br> &nbsp; &nbsp;TranslateMessage(msg);<br> &nbsp; &nbsp;DispatchMessage(msg);<br> &nbsp;end;<br>end.
 
老哥,能不能给个短点的代码,实现功能10分钟后提示&quot;10分钟到了!&quot;[:(!]关键是我现在看不太明白你的代码,我水平太错!
 
这个的确是最短的了,你拷下来运行一下,自己学学吧,水平差不是错,不肯学就是错了
 
收到,结帐,学习!
 
后退
顶部