如果是关机: Public Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As LongParameters uFlags [in] Specifies the type of shutdown. This parameter must include one of the following values. Value Meaning EWX_LOGOFF Shuts down all processes running in the security context of the process that called the ExitWindowsEx function. Then it logs the user off. EWX_POWEROFF Shuts down the system and turns off the power. The system must support the power-off feature. Windows NT/2000: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Res section.
EWX_REBOOT Shuts down the system and then restarts the system. Windows NT/2000: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Res section.
EWX_SHUTDOWN Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped. Windows NT/2000: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Res section.
This parameter can optionally include the following values. Value Meaning EWX_FORCE Forces processes to terminate. When this flag is set, the system does not send the WM_QUERYENDSESSION and WM_ENDSESSION messages. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency. EWX_FORCEIFHUNG Windows 2000: Forces processes to terminate if they do not respond to the WM_QUERYENDSESSION or WM_ENDSESSION message. This flag is ignored if EWX_FORCE is used.
to csdncb(csdncai),Arcan(Arcan) 请说的详细点好吗?
ExitWindowsEx Function Declare Function ExitWindowsEx Lib "user32.dll" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long Platforms: Win 95/98, Win NT ExitWindowsEx shuts down or reboots the user's computer. Of course, since the shutdown/reboot process will begin once the function is called, there won't normally be much left for your program to do. The function returns 0 if an error occured, or 1 if successful. uFlags One or more of the following flags specifying how to shut down or reboot the computer: EWX_FORCE = 4 Force any applications to quit instead of prompting the user to close them. EWX_LOGOFF = 0 Log off the network. EWX_POWEROFF = 8 Shut down the system and, if possible, turn the computer off. EWX_REBOOT = 2 Perform a full reboot of the system. EWX_SHUTDOWN = 1 Shut down the system. dwReserved Reserved for future versions of Windows. Always set to 0. Example: ' Reboot the computer, forcing any open programs to close Dim retval As Long ' return valueretval = ExitWindowsEx(EWX_REBOOT Or EWX_FORCE, 0) If retval = 0 Then Debug.Print "Reboot attempt failed."
我寫過這樣一個小程序,附下(節選,自已看吧) Option Explicit' 宣告最上層顯示sub Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, Y, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Const HWND_TOPMOST = -1 Private Const HWND_NOTOPMOST = -2 Private Const HWND_TOP = 0 Private Const HWND_BOTTOM = 1 Private Const SWP_NOMOVE = &H2 Private Const SWP_NOSIZE = &H1Enum HowExitConst EWX_FORCE = 4 ' 強制關機 EWX_LOGOFF = 0 ' 登出 EWX_REBOOT = 2 ' 重開機 EWX_SHUTDOWN = 1 ' 關機 End EnumConst TOKEN_ADJUST_PRIVILEGES = &H20 Const TOKEN_QUERY = &H8 Const SE_PRIVILEGE_ENABLED = &H2 Const ANYSIZE_ARRAY = 1 Private Type LUID lowpart As Long highpart As Long End TypePrivate Type LUID_AND_ATTRIBUTES pLuid As LUID Attributes As Long End TypePrivate Type TOKEN_PRIVILEGES PrivilegeCount As Long Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES End TypePrivate Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, _ ByVal dwReserved As Long) As Long Private Declare Function GetCurrentProcess Lib "kernel32" () As Long Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias _ "LookupPrivilegeValueA" (ByVal lpSystemName As String, _ ByVal lpName As String, lpLuid As LUID) As Long Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" _ (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, _ NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, _ PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long Private Declare Function OpenProcessToken Lib "advapi32.dll" _ (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, _ TokenHandle As Long) As LongPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, lParam As Any) As Long' 設置按鈕樣式消息 ( C++ 樣式按鈕,無獲得焦點時那討厭的黑圈 ) ' 設置按鈕樣式消息 Private Const BM_SETSTYLE = &HF4 '& ' 有效的按鈕按下時的樣式 Private Const BS_DEFPUSHBUTTON = &H1& '標準樣式 Private Const BS_PUSHBUTTON = &H0& 'API 樣式'2. AdjustToken 副程式:Private Sub AdjustToken() Dim hdlProcessHandle As Long Dim hdlTokenHandle As Long Dim tmpLuid As LUID Dim tkp As TOKEN_PRIVILEGES Dim tkpNewButIgnored As TOKEN_PRIVILEGES Dim lBufferNeeded As Long
hdlProcessHandle = GetCurrentProcess() OpenProcessToken hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), _ hdlTokenHandle 'Get the LUID for shutdown privilege. LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid tkp.PrivilegeCount = 1 ' One privilege to set tkp.Privileges(0).pLuid = tmpLuid tkp.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED 'Enable the shutdown privilege in the access token of this process. AdjustTokenPrivileges hdlTokenHandle, False, tkp, Len(tkpNewButIgnored), _ tkpNewButIgnored, lBufferNeededEnd SubPrivate Sub Command1_Click() If (Option1.Item(0).Value) Or (Option1.Item(3).Value) Then Else
If Not Folder_Exist("c:\boot\tw\") Then MakeDirs "C:\Boot\Tw\" End If
If Not Folder_Exist("c:\boot\cn\") Then MakeDirs "C:\Boot\Cn\" End If
If Not File_Exist("c:\boot\tw\msdos.sys") Then MsgBox "Refer to Ver MSDOS.SYS TW_Windows not exist ", , App.ProductName Exit Sub End If
If Not File_Exist("c:\boot\cn\msdos.sys") Then MsgBox "Refer to Ver MSDOS.SYS CN_Windows not exist", , App.ProductName Exit Sub End If End If
If Option1.Item(0).Value Then AdjustToken Call ExitWindowsEx(EWX_LOGOFF, 0) 'how 等於 EWX_LOGOFF 、 EWX_REBOOT 、 EWX_SHUTDOWN、 或EWX_FORCE End If
If Option1.Item(1).Value Then
If Option2.Item(0).Value Then Copy_File "C:\boot\tw\msdos.sys", "C:\" End If If Option2.Item(1).Value Then Copy_File "C:\boot\CN\msdos.sys", "C:\" End If
AdjustToken Call ExitWindowsEx(EWX_REBOOT, 0) End If
If Option1.Item(2).Value Then If Option2.Item(0).Value Then Copy_File "C:\boot\tw\msdos.sys", "C:\" End If If Option2.Item(1).Value Then Copy_File "C:\boot\CN\msdos.sys", "C:\" End If AdjustToken Call ExitWindowsEx(EWX_SHUTDOWN, 0) End If
If Option1.Item(3).Value Then AdjustToken Call ExitWindowsEx(EWX_FORCE, 0) End If
Unload MeEnd SubPrivate Sub Command2_Click() Unload MeEnd Sub' 呼叫的範例:' AdjustToken ' Call ExitWindowsEx(how, 0) 'how 等於 EWX_LOGOFF 、 EWX_REBOOT 、 EWX_SHUTDOWN、 或EWX_FORCE'在 Windows 95 底下呼叫了 AdjustToken 也沒關係,因為 Windows 95 並不會理會安全性的設定。'************************************************************************************* ' OnTop() ' 目 的: 設置窗口為最頂層窗口 ' 輸 入: 窗口名 ' 返 回 值: 無 '************************************************************************************* Public Sub OnTop(ByVal lngValue As Long) SetWindowPos lngValue, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZEEnd Sub'************************************************************************************* ' 目 的: 將指定按鈕變為 C++ 按鈕樣式 但怎作怎不象 ' 輸 入: 引用的按鈕 ' 返 回 值: 無 (改變其外觀) '************************************************************************************* Public Sub ButtonStyle(TheButton As CommandButton) Dim hCmd As Long
Option2.Item(0).Value = True ' Option2.Item(1).Value = TrueEnd SubPrivate Sub Option1_Click(Index As Integer) If (Index = 0) Or (Index = 3) Then Option2.Item(0).Enabled = False Option2.Item(1).Enabled = False Else Option2.Item(0).Enabled = True Option2.Item(1).Enabled = True End IfEnd Sub
谢谢,可我要的是WIN2K的休眠啊。
300分我要了 :)Public oldProcAddress As Long Public Enum enPowerBroadcastType PBT_APMQUERYSUSPEND = &H0 PBT_APMQUERYSTANDBY = &H1 PBT_APMQUERYSUSPENDFAILED = &H2 PBT_APMQUERYSTANDBYFAILED = &H3 PBT_APMSUSPEND = &H4 PBT_APMSTANDBY = &H5 PBT_APMRESUMECRITICAL = &H6 PBT_APMRESUMESUSPEND = &H7 PBT_APMRESUMESTANDBY = &H8 End Enum Public Const BROADCAST_QUERY_DENY = &H424D5144 Public Const WM_POWER = &H48 Public Const WM_POWERBROADCAST = &H218 Public Const PWR_SUSPENDREQUEST = 1 Public Const GWL_WNDPROC = (-4) Public Const PWR_FAIL = (-1) Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public Function VB_WindowProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long On Local Error Resume Next Dim lRet As Long If wMsg = WM_POWER And wParam = PWR_SUSPENDREQUEST Then VB_WindowProc = PWR_FAIL ElseIf wMsg = WM_POWERBROADCAST And wParam = PBT_APMQUERYSUSPEND Then VB_WindowProc = BROADCAST_QUERY_DENY Else VB_WindowProc = CallWindowProc(oldProcAddress, hWnd, wMsg, wParam, lParam) End If End Function Private Sub Form_Load() oldProcAddress = SetWindowLong(Me.hWnd, GWL_WNDPROC, AddressOf VB_WindowProc) End Sub Private Sub Form_Unload(Cancel As Integer) Call SetWindowLong(Me.hWnd, GWL_WNDPROC, oldProcAddress) End Sub
to mamaye(mamaye) 执行休眠的函数如何调用啊,能说一下吗?是VB_WindowProc吗,参数怎么添??
Public Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As LongParameters
uFlags
[in] Specifies the type of shutdown. This parameter must include one of the following values. Value Meaning EWX_LOGOFF Shuts down all processes running in the security context of the process that called the ExitWindowsEx function. Then it logs the user off. EWX_POWEROFF Shuts down the system and turns off the power. The system must support the power-off feature. Windows NT/2000: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Res section.
EWX_REBOOT Shuts down the system and then restarts the system.
Windows NT/2000: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Res section.
EWX_SHUTDOWN Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped.
Windows NT/2000: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Res section.
This parameter can optionally include the following values. Value Meaning
EWX_FORCE Forces processes to terminate. When this flag is set, the system does not send the WM_QUERYENDSESSION and WM_ENDSESSION messages. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency.
EWX_FORCEIFHUNG Windows 2000: Forces processes to terminate if they do not respond to the WM_QUERYENDSESSION or WM_ENDSESSION message. This flag is ignored if EWX_FORCE is used.
请说的详细点好吗?
Declare Function ExitWindowsEx Lib "user32.dll" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long Platforms: Win 95/98, Win NT ExitWindowsEx shuts down or reboots the user's computer. Of course, since the shutdown/reboot process will begin once the function is called, there won't normally be much left for your program to do. The function returns 0 if an error occured, or 1 if successful. uFlags
One or more of the following flags specifying how to shut down or reboot the computer:
EWX_FORCE = 4
Force any applications to quit instead of prompting the user to close them.
EWX_LOGOFF = 0
Log off the network.
EWX_POWEROFF = 8
Shut down the system and, if possible, turn the computer off.
EWX_REBOOT = 2
Perform a full reboot of the system.
EWX_SHUTDOWN = 1
Shut down the system.
dwReserved
Reserved for future versions of Windows. Always set to 0.
Example: ' Reboot the computer, forcing any open programs to close
Dim retval As Long ' return valueretval = ExitWindowsEx(EWX_REBOOT Or EWX_FORCE, 0)
If retval = 0 Then Debug.Print "Reboot attempt failed."
Option Explicit' 宣告最上層顯示sub
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, Y, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const HWND_TOP = 0
Private Const HWND_BOTTOM = 1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1Enum HowExitConst
EWX_FORCE = 4 ' 強制關機
EWX_LOGOFF = 0 ' 登出
EWX_REBOOT = 2 ' 重開機
EWX_SHUTDOWN = 1 ' 關機
End EnumConst TOKEN_ADJUST_PRIVILEGES = &H20
Const TOKEN_QUERY = &H8
Const SE_PRIVILEGE_ENABLED = &H2
Const ANYSIZE_ARRAY = 1
Private Type LUID
lowpart As Long
highpart As Long
End TypePrivate Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End TypePrivate Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End TypePrivate Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, _
ByVal dwReserved As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias _
"LookupPrivilegeValueA" (ByVal lpSystemName As String, _
ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" _
(ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, _
NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, _
PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" _
(ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, _
TokenHandle As Long) As LongPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long' 設置按鈕樣式消息 ( C++ 樣式按鈕,無獲得焦點時那討厭的黑圈 )
' 設置按鈕樣式消息
Private Const BM_SETSTYLE = &HF4 '&
' 有效的按鈕按下時的樣式
Private Const BS_DEFPUSHBUTTON = &H1& '標準樣式
Private Const BS_PUSHBUTTON = &H0& 'API 樣式'2. AdjustToken 副程式:Private Sub AdjustToken() Dim hdlProcessHandle As Long
Dim hdlTokenHandle As Long
Dim tmpLuid As LUID
Dim tkp As TOKEN_PRIVILEGES
Dim tkpNewButIgnored As TOKEN_PRIVILEGES
Dim lBufferNeeded As Long
hdlProcessHandle = GetCurrentProcess()
OpenProcessToken hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), _
hdlTokenHandle 'Get the LUID for shutdown privilege.
LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
tkp.PrivilegeCount = 1 ' One privilege to set
tkp.Privileges(0).pLuid = tmpLuid
tkp.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED 'Enable the shutdown privilege in the access token of this process.
AdjustTokenPrivileges hdlTokenHandle, False, tkp, Len(tkpNewButIgnored), _
tkpNewButIgnored, lBufferNeededEnd SubPrivate Sub Command1_Click() If (Option1.Item(0).Value) Or (Option1.Item(3).Value) Then Else
If Not Folder_Exist("c:\boot\tw\") Then MakeDirs "C:\Boot\Tw\" End If
If Not Folder_Exist("c:\boot\cn\") Then MakeDirs "C:\Boot\Cn\" End If
If Not File_Exist("c:\boot\tw\msdos.sys") Then MsgBox "Refer to Ver MSDOS.SYS TW_Windows not exist ", , App.ProductName
Exit Sub End If
If Not File_Exist("c:\boot\cn\msdos.sys") Then MsgBox "Refer to Ver MSDOS.SYS CN_Windows not exist", , App.ProductName
Exit Sub End If End If
If Option1.Item(0).Value Then AdjustToken
Call ExitWindowsEx(EWX_LOGOFF, 0)
'how 等於 EWX_LOGOFF 、 EWX_REBOOT 、 EWX_SHUTDOWN、 或EWX_FORCE End If
If Option1.Item(1).Value Then
If Option2.Item(0).Value Then Copy_File "C:\boot\tw\msdos.sys", "C:\" End If If Option2.Item(1).Value Then Copy_File "C:\boot\CN\msdos.sys", "C:\" End If
AdjustToken
Call ExitWindowsEx(EWX_REBOOT, 0) End If
If Option1.Item(2).Value Then If Option2.Item(0).Value Then Copy_File "C:\boot\tw\msdos.sys", "C:\" End If If Option2.Item(1).Value Then Copy_File "C:\boot\CN\msdos.sys", "C:\" End If AdjustToken
Call ExitWindowsEx(EWX_SHUTDOWN, 0) End If
If Option1.Item(3).Value Then AdjustToken
Call ExitWindowsEx(EWX_FORCE, 0) End If
Unload MeEnd SubPrivate Sub Command2_Click() Unload MeEnd Sub' 呼叫的範例:' AdjustToken
' Call ExitWindowsEx(how, 0)
'how 等於 EWX_LOGOFF 、 EWX_REBOOT 、 EWX_SHUTDOWN、 或EWX_FORCE'在 Windows 95 底下呼叫了 AdjustToken 也沒關係,因為 Windows 95 並不會理會安全性的設定。'*************************************************************************************
' OnTop()
' 目 的: 設置窗口為最頂層窗口
' 輸 入: 窗口名
' 返 回 值: 無
'*************************************************************************************
Public Sub OnTop(ByVal lngValue As Long) SetWindowPos lngValue, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZEEnd Sub'*************************************************************************************
' 目 的: 將指定按鈕變為 C++ 按鈕樣式 但怎作怎不象
' 輸 入: 引用的按鈕
' 返 回 值: 無 (改變其外觀)
'*************************************************************************************
Public Sub ButtonStyle(TheButton As CommandButton) Dim hCmd As Long
'hCmd = FindWindow("Button", TheButton.Caption)
'SendMessage hCmd, BM_SETSTYLE, BS_PUSHBUTTON, 0&
'SendMessage TheButton.hWnd, BM_SETSTYLE, BS_DEFPUSHBUTTON, 0&
'TheButton.Style = vbButtonGraphical
SendMessage TheButton.hwnd, BM_SETSTYLE, BS_PUSHBUTTON, 0&End SubPrivate Sub Form_Load()
Dim cpACP As Long
cpACP = GetACP()
If cpACP = 950 Then Label3.Caption = LoadResString(133) Else Label3.Caption = LoadResString(134) End If
' If cpACP = 950 Then ' Me.Caption = "計算機重啟選項" 'LoadResString(100 + 1)
' Option1.Item(0).Caption = "登出 使用者" 'LoadResString(100 + 2)
' Option1.Item(1).Caption = "重新啟動計算機" 'LoadResString(100 + 3)
' Option1.Item(2).Caption = "關閉 計算機" 'LoadResString(100 + 4)
' Option1.Item(3).Caption = "強制關閉計算機" 'LoadResString(100 + 5)
'
' Frame1.Caption = "啟動何種作業系統" 'LoadResString(100 + 6)
'
' Option2.Item(0).Caption = "繁體" 'LoadResString(100 + 7)
' Option2.Item(1).Caption = "簡體" 'LoadResString(100 + 8)
'
' Label1.Caption = "編製部門: 厚泰模具東莞分公司電腦部" 'LoadResString(100 + 9)
' Label2.Caption = "編 制 人: Marki,Benson" 'LoadResString(100 + 10)
'
' Command1.Caption = "確定" 'LoadResString(100 + 11)
' Command2.Caption = "取消" 'LoadResString(100 + 12) Me.Caption = LoadResString(100 + 1)
Option1.Item(0).Caption = LoadResString(100 + 2)
Option1.Item(1).Caption = LoadResString(100 + 3)
Option1.Item(2).Caption = LoadResString(100 + 4)
Option1.Item(3).Caption = LoadResString(100 + 5) Frame1.Caption = LoadResString(100 + 6) Option2.Item(0).Caption = LoadResString(100 + 7)
Option2.Item(1).Caption = LoadResString(100 + 8) Label1.Caption = LoadResString(100 + 9)
Label2.Caption = LoadResString(100 + 10) Command1.Caption = LoadResString(100 + 11)
Command2.Caption = LoadResString(100 + 12)
' Else
'
' Me.Caption = LoadResString(120 + 1)
' Option1.Item(0).Caption = LoadResString(120 + 2)
' Option1.Item(1).Caption = LoadResString(120 + 3)
' Option1.Item(2).Caption = LoadResString(120 + 4)
' Option1.Item(3).Caption = LoadResString(120 + 5)
'
' Frame1.Caption = LoadResString(120 + 6)
'
' Option2.Item(0).Caption = LoadResString(120 + 7)
' Option2.Item(1).Caption = LoadResString(120 + 8)
'
' Label1.Caption = LoadResString(120 + 9)
' Label2.Caption = LoadResString(120 + 10)
'
' Command1.Caption = LoadResString(120 + 11)
' Command2.Caption = LoadResString(120 + 12)
'
' End If OnTop Me.hwnd ButtonStyle Command1
ButtonStyle Command2
' Option1.Item(0).Value = True
Option1.Item(1).Value = True
' Option1.Item(2).Value = True
' Option1.Item(3).Value = True
Option2.Item(0).Value = True
' Option2.Item(1).Value = TrueEnd SubPrivate Sub Option1_Click(Index As Integer) If (Index = 0) Or (Index = 3) Then Option2.Item(0).Enabled = False
Option2.Item(1).Enabled = False Else Option2.Item(0).Enabled = True
Option2.Item(1).Enabled = True End IfEnd Sub
Public Enum enPowerBroadcastType
PBT_APMQUERYSUSPEND = &H0
PBT_APMQUERYSTANDBY = &H1
PBT_APMQUERYSUSPENDFAILED = &H2
PBT_APMQUERYSTANDBYFAILED = &H3
PBT_APMSUSPEND = &H4
PBT_APMSTANDBY = &H5
PBT_APMRESUMECRITICAL = &H6
PBT_APMRESUMESUSPEND = &H7
PBT_APMRESUMESTANDBY = &H8
End Enum
Public Const BROADCAST_QUERY_DENY = &H424D5144
Public Const WM_POWER = &H48
Public Const WM_POWERBROADCAST = &H218
Public Const PWR_SUSPENDREQUEST = 1
Public Const GWL_WNDPROC = (-4)
Public Const PWR_FAIL = (-1)
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Function VB_WindowProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
On Local Error Resume Next
Dim lRet As Long
If wMsg = WM_POWER And wParam = PWR_SUSPENDREQUEST Then
VB_WindowProc = PWR_FAIL
ElseIf wMsg = WM_POWERBROADCAST And wParam = PBT_APMQUERYSUSPEND Then
VB_WindowProc = BROADCAST_QUERY_DENY
Else
VB_WindowProc = CallWindowProc(oldProcAddress, hWnd, wMsg, wParam, lParam)
End If
End Function
Private Sub Form_Load()
oldProcAddress = SetWindowLong(Me.hWnd, GWL_WNDPROC, AddressOf VB_WindowProc)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call SetWindowLong(Me.hWnd, GWL_WNDPROC, oldProcAddress)
End Sub
执行休眠的函数如何调用啊,能说一下吗?是VB_WindowProc吗,参数怎么添??
'---------------------------------
' 聲明(函數及常量) 應放在 bas 文件中
'---------------------------------' -------------------------------------------
' 其余可自己組織~
'
' -------------------------------------------
' VB_WindowProc 參數說明
' typedef LRESULT (CALLBACK* WNDPROC)
' (HWND, UINT, WPARAM, LPARAM);
' 參數:
' hwnd - window 句柄
' wMsg - window 消息 (WM_..等)
' wParam - 第一個消息參數
' lParam - 第二個消息參數
' 注意: ~,根據自己的情況來看,注意回調的地址~
' ------------------------------------
我只要实现WIN2K 休眠的功能,麻烦写一下吧,能用了马上给分!!!!
老兄玩笑开大了吧
其實道理差不多,重點在三個方面
其一,了解 WM_POWER;WM_POWERBROADCAST等
這類消息(可查相關資料[P1063.visual basic 5.0 win32 api 開發人員指南 美.dan appleman著])
其二,注意系統挂起時各窗口狀態及信息的設置
其三,喚醒時狀態的恢復其時,我也只是業余時思考一下,并未著手去作這個程式,
因考慮可能麻煩很多,亦并不是很實用我曾經有一個想法是,在WIN9X的機器當操作人离開時,通過一個熱鍵
將電腦挂起,喚醒時需輸入密碼,起到保護和省電作用,但限制電腦挂起則
容易多了,如上,你說是嗎~ 
其實道理差不多,重點在三個方面
其一,了解 WM_POWER;WM_POWERBROADCAST等
這類消息(可查相關資料[P1063.visual basic 5.0 win32 api 開發人員指南 美.dan appleman著])
其二,注意系統挂起時各窗口狀態及信息的設置
其三,喚醒時狀態的恢復其時,我也只是業余時思考一下,并未著手去作這個程式,
因考慮可能麻煩很多,亦并不是很實用我曾經有一個想法是,在WIN9X的機器當操作人离開時,通過一個熱鍵
將電腦挂起,喚醒時需輸入密碼,起到保護和省電作用,但限制電腦挂起則
容易多了,如上,你說是嗎~ 