Declare Function SetTextFocus Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As LongSetTextFocus 你的句柄
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Const WM_SETFOCUS = &H7Private Sub Command1_Click() SendMessage Text1.hwnd, WM_SETFOCUS, 0, 0 End Sub
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long Private Const WM_SETFOCUS = &H7Private Sub Command1_Click() SetForegroundWindow Text1.hwnd SendMessage Text1.hwnd, WM_SETFOCUS, 0, 0 End Sub
对于外部程序,一般都用SendMessage来对它发送消息
以上Text1.hwnd仅仅是个表示,你可用你获取的句柄代替
Private Declare Function GetFocus Lib "user32" () As Long 这个也可以吧
Private Const WM_SETFOCUS = &H7Private Sub Command1_Click()
SendMessage Text1.hwnd, WM_SETFOCUS, 0, 0
End Sub
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Const WM_SETFOCUS = &H7Private Sub Command1_Click()
SetForegroundWindow Text1.hwnd
SendMessage Text1.hwnd, WM_SETFOCUS, 0, 0
End Sub
这个也可以吧