Option ExplicitPrivate Type RECT Left As Long Top As Long Right As Long Bottom As Long End TypePrivate 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 FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long, _ ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As LongPrivate Sub MoveWindowTo(ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long) Dim Rec As RECT If hWnd <> 0 Then GetWindowRect hWnd, Rec MoveWindow hWnd, X, Y, Rec.Right - Rec.Left, Rec.Bottom - Rec.Top, 1 End If End SubPrivate Sub tmrAfterLoadCalc_Timer() Dim WinWnd As Long WinWnd = FindWindow(vbNullString, "计算器") If WinWnd <> 0 Then tmrAfterLoadCalc.Enabled = False MoveWindowTo WinWnd, 200, 200 End If End SubPrivate Sub Command1_Click() Dim WinWnd As Long WinWnd = FindWindow(vbNullString, "计算器") If WinWnd <> 0 Then MoveWindowTo WinWnd, 200, 200 Else ShellExecute Me.hWnd, "open", "calc.exe", "", "", 1 tmrAfterLoadCalc.Interval = 50 tmrAfterLoadCalc.Enabled = True End If End Sub
Left As Long
Top As Long
Right As Long
Bottom As Long
End TypePrivate 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 FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As LongPrivate Sub MoveWindowTo(ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long)
Dim Rec As RECT
If hWnd <> 0 Then
GetWindowRect hWnd, Rec
MoveWindow hWnd, X, Y, Rec.Right - Rec.Left, Rec.Bottom - Rec.Top, 1
End If
End SubPrivate Sub tmrAfterLoadCalc_Timer()
Dim WinWnd As Long
WinWnd = FindWindow(vbNullString, "计算器")
If WinWnd <> 0 Then
tmrAfterLoadCalc.Enabled = False
MoveWindowTo WinWnd, 200, 200
End If
End SubPrivate Sub Command1_Click()
Dim WinWnd As Long
WinWnd = FindWindow(vbNullString, "计算器")
If WinWnd <> 0 Then
MoveWindowTo WinWnd, 200, 200
Else
ShellExecute Me.hWnd, "open", "calc.exe", "", "", 1
tmrAfterLoadCalc.Interval = 50
tmrAfterLoadCalc.Enabled = True
End If
End Sub
判断是否有标题为“计算器”的程序
有的话用MoveWindowTo 移动“计算器”到指定位置
没有就用shellexcute打开,同时让tmrAfterLoadCalc控件运行
tmrAfterLoadCalc的功能就是把“计算器”移动到指定位置.....^_^最近都不想写代码了,好累啊