...Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExe...
发布网友
发布时间:2024-03-20 21:20
我来回答
共2个回答
热心网友
时间:2024-08-28 03:17
是VB运行速度是很快的,ShellExecute 0&, "open", "D:\calc.exe", "", "", 1
这一句固然是打开了一个计算器,但是打开的过程中,VB早已运行到下一个语句了,当然找不到这个程序,也就不能返回句柄,也就不能改变标题。
解决办法:设定延迟,使VB等待程序打开以后,再向下运行。
代码如下。
==============
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) '延迟函数
Private 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
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Const GWL_STYLE = (-16)
Private Const SWP_SHOWWINDOW = &H40
Private Const HWND_BOTTOM = 1
Private Const WS_CAPTION = &HC00000
Private Sub Form_Load()
Dim chwnd As Long
ShellExecute 0&, "open", "calc", "", "", 1
Sleep 50 '我这里延迟50就可以,请根据自己情况修改。
chwnd = FindWindow(vbNullString, "计算器")
SetWindowText chwnd, "jisuanqi"
End Sub
热心网友
时间:2024-08-28 03:14
完整的声明
Private 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