|
第四课:几个实用的API
前面说了那么API的用法,下面说几个实用的API吧:
1、ExitWindowsEx:
这个程序用于Window系统的关机方面,声明如下:
Public Declare Function ExitWindowsEx Lib "user32" Alias "ExitWindowsEx" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
定义如下常量:
Const EWX_LOGOFF = 0 '中止进程后然后注销
Const EWX_SHUTDOWN = 1 '关机
Const EWX_REBOOT = 2 '重新启动系统
Const EWX_FORCE = 4 '强迫中止没有响应的进程、强制关机
且定义一个Long变量来接收返回值:Dim tempL As Long,则
tempL=ExitWindowsEx(EWX_LOGOFF, 0) '注销
tempL=ExitWindowsEx(EWX_SHUTDOWN, 0) '关机
tempL=ExitWindowsEx(EWX_REBOOT, 0) ‘ 重启
tempL=ExitWindowsEx(EWX_FORCE, 0) ’强行关机
2、ShellExecute:
这个API用于打开指定的URL,声明如下:
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
定义如下常量:
Const SW_SHOW = 5
Const SW_SHOWMAXIMIZED = 3
Const SW_SHOWNOACTIVATE = 4
以下常量用在API中不知有什么区别,但可以用如下方法打开一个网页:
Dim tempL As Long
tempL = ShellExecute(Me.hwnd, "open", "http://www.baidu.com", "", "", SW_SHOWNOACTIVATE)
3、SetWindowPos:
可用于将窗体放在所有窗体的前面,如千千静听变成迷你模式时,条将窗体将在所有的窗体的将面,声明如下:
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
定义如下常量:
Const TOP = -1 '设定为最上层
Const CANCELTOP= -2 '取消最上层设定
Const SWP_NOSIZE& = &H1
Const SWP_NOMOVE& = &H2
Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
将窗体放在最上层:
SetWindowPos Me.hwnd,TOP, 0, 0, 0, 0, FLAGS
取消放在最上层:
SetWindowPos Me.hwnd, CANCELTOP, 0, 0, 0, 0, FLAGS
4、Sleep:
用于延时(单位为微秒),声明如下:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
如延时2秒:
Sleep 2000
|
|