首先謝謝您的幫助,想用VB腳本實作,再指定時間內檢測到滑鼠鍵盤無操作執行關機命令,并出現對話框提示10分鐘后關機,在出現對話框期間檢測到鍵盤滑鼠有操作,結束關機命令并重新檢測,謝謝,謝謝,謝謝,真心不想用軟體華而不實
uj5u.com熱心網友回復:
How To Create a Screen Saver in Visual Basic
Last reviewed: September 13, 1996
Article ID: Q146907
The information in this article applies to:
- Standard, Professional, and Enterprise Editions of Microsoft
Visual Basic, 16-bit, for Windows, version 4.0
SUMMARY
You can create a Windows screen saver with Visual Basic by following the guidelines listed below. However, please note that this article gives only a very rough outline of what you should do for a robust screen saver. These are general guidelines only.
MORE INFORMATION
Follow these guidelines when creating a Windows screen saver with Visual Basic:
In the File Make EXE File dialog, insert the string SCRNSAVE: (in upper case) at the beginning of the Application Title. For example:
SCRNSAVE:Flying Fish.
In the File Make EXE File dialog, specify the program file name extension as .SCR instead of .EXE.
Locate the .SCR program file in the \WINDOWS directory.
Give your form the following property settings so that it occupies the entire screen and does not have a title bar:
Caption = "" (no caption)
ControlBox = False
MaxButton = False
MinButton = False
WindowState = 2 (maximized)
Add code to all MouseMove, MouseDown, and KeyDown event handlers that exit the program. Because Visual Basic may invoke the MouseMove event when the form is first loaded, you must write code to ignore the first MouseMove event. The following MouseMove code avoids an artifact event that occurs when the application is first activated or when the application is running and another instance starts (causing loss of focus) and then quits (restoring focus):
Private Sub Form_MouseMove (Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Static count As Integer
If count > 2 Then
End
Else
count = count + 1
End If
End Sub
This gives you a bit of slack when it comes to artifact MouseMove
events. You will want to do something similar with the MouseDown and
KeyDown events.
Preventing Multiple Launches
Windows usually launches the screen saver program multiple times. To prevent more than one copy of your screen saver from running, add the following statements to the Form_Load event handler, or Sub Main if used:
Private Sub Form_Load ()
If App.PrevInstance Then
End
End If
End Sub
There is no reason to attempt to restore the previous instance of the screen saver as the active window because it will become the active window when the new instance ends. All you have to do is terminate when you see another instance running.
To prevent multiple instances of the application from running as well as to keep the application running, you should move the code from the Form_Load() to a Sub Main(). Then set the project's Startup Form Option to Sub Main(). Setting the project to begin processing at Sub Main is done on the Project tab which is part of Options... under Tools menu. For example:
Public Sub Main ()
If App.PrevInstance Then ' If already running, end the application.
End
Else
Form1.Show 1 ' Show the screen saver form.
End If
End Sub
Launching the Screen Saver
Windows takes care of launching the Screen Saver. It keeps track of system idle time and launches the screen saver program. You can use a timer control to periodically draw graphics on the form.
Screen savers are selected and configured from Windows Control Panel in the Desktop dialog. The screen saver section of this dialog has a button labeled Setup that invokes the screen saver program with the command line option /c. When your program is invoked with this option, you can display a configuration form to allow the user to select settings such as speed, number of objects, colors, and so on. Detect the /c command line parameter by checking the Command$ function. For example:
Private Sub Form_Load ()
If Command$ = "/c" Then
frmConfig.Show ' Display configuration form.
Unload Me ' Bypass regular form.
End If
End Sub
When Windows launches the screen saver, it usually specifies the command line option /s.
Possible Improvements
You may also want your program to appear on top of all other windows by making it a TOPMOST window.
For additional information, please see the following article(s) in the Microsoft Knowledge Base:
ARTICLE-ID: Q84251
TITLE : How to Create a Topmost or Floating Window in Visual Basic
Also, you can find two example programs and a complete explanation showing how to write your own screen savers in Visual Basic in the following book:
"Visual Basic Workshop 3.0" by John C. Craig, published by Microsoft
Press.
This article is a rough outline of what you should do for a robust screen saver. For example, you might want to have the startup be a Sub Main() in which you check for a previous instance and End if there is one. This would avoid the form load totally if there were already an instance running. It might also avoid the artifact MouseMove problem.
--------------------------------------------------------------------------------
Additional reference words: 4.00 vb4win vb416
KBCategory: kbprg kbcode
KBSubcategory: APrgOther
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
Last reviewed: September 13, 1996
? 1998 Microsoft Corporation. All rights reserved. Terms of Use.
uj5u.com熱心網友回復:
VBA腳本不太清楚,不過在VB6中可以使用鍵盤滑鼠HOOK,外加呼叫關機函式.鍵盤滑鼠HOOK代碼封裝:
http://www.m5home.com/bak_blog/article/245.html
關機函式封裝:
http://www.m5home.com/bbs/thread-391-1-1.html
思路為:
表單加一個定時器,周期設定為1秒,然后定時器事件里將一個全域變數A加1,這個A就是空閑時間了.
當這個時間大于某個設定的值,就可以呼叫關機了.
鍵盤滑鼠HOOK中每產生鍵盤或滑鼠事件,則就將A置0.
定時器內代碼類似這樣:
dim TimeLeft as long
private sub timer1_timer()
timeleft=timeleft+1
if timeleft>600 then '600秒就是10分鐘
timer1.enabled=false:doevents
call ShutDownPC(1) '呼叫關機
end if
end sub
然后滑鼠鍵盤事件中只需要timeleft=0就行了.
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/127642.html
標籤:VBA
上一篇:求助一個假如的用句
下一篇:windows關機死回圈腳本代碼
