1先用findwindow找到记事本的hwnd,然后 用SetForegroundWindow把记事本设为前台窗口 Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As LongSetForegroundWindow 记事本hwnd
1)需要注册系统热键,不会 2) Public Declare Function SendMessageByStr& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)Public Function vbSetWindowText(ahWnd As Long, strSetText As String) As Integer
回复人: litsnake1(litsnake) 你是按照我的这个一样做的吗,在我这里是没有问题, 我的跟你所说的不一样的,看清楚一点 ========================================= 不能按照你的这样做都不能, 说什么 “DLL 的调用约定错误(错误 49)” ’========================================用SetForegroundWindow把记事本设为前台窗口 Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long========================================== 这个都不能
加上这个: 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
Declare Function SendMessageByStr& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long两都的用法有什么不同
第一个问题的参考 Option ExplicitPrivate Const MOD_ALT = &H1 Private Const MOD_CONTROL = &H2 Private Const MOD_SHIFT = &H4 Private Const PM_REMOVE = &H1 Private Const WM_HOTKEY = &H312 Private Type POINTAPI x As Long y As Long End Type Private Type Msg hWnd As Long Message As Long wParam As Long lParam As Long time As Long pt As POINTAPI End Type Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long Private Declare Function WaitMessage Lib "user32" () As Long Private bCancel As Boolean Private Sub ProcessMessages() Dim Message As Msg 'loop until bCancel is set to True Do While Not bCancel 'wait for a message WaitMessage 'check if it's a HOTKEY-message If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then WindowState = vbMaximized Me.SetFocus End If 'let the operating system process other events DoEvents Loop End Sub Private Sub Form_Load() Dim ret As Long bCancel = False 'register the Ctrl-F hotkey 'ret = RegisterHotKey(Me.hWnd, &HBFFF&, MOD_CONTROL, vbKeyA) ret = RegisterHotKey(Me.hWnd, &HBFFF&, 0, vbKeyA) 'show some information Me.AutoRedraw = True Me.Print "按 a 本窗口便被呼叫,并最大化!" 'show the form and Show 'process the Hotkey messages ProcessMessages End Sub Private Sub Form_Unload(Cancel As Integer) bCancel = True 'unregister hotkey Call UnregisterHotKey(Me.hWnd, &HBFFF&) End Sub
'回复人: dsclub(▁▂▃▄▅▆▇█ 騩鹬←短发男生)
Option ExplicitPrivate Const MOD_ALT = &H1 Private Const MOD_CONTROL = &H2 Private Const MOD_SHIFT = &H4 Private Const PM_REMOVE = &H1 Private Const WM_HOTKEY = &H312 Private Type POINTAPI x As Long y As Long End Type Private Type Msg hWnd As Long Message As Long wParam As Long lParam As Long time As Long pt As POINTAPI End Type Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long Private Declare Function WaitMessage Lib "user32" () As Long Private bCancel As Boolean Private Sub ProcessMessages() Dim Message As Msg 'loop until bCancel is set to True Do While Not bCancel 'wait for a message WaitMessage 'check if it's a HOTKEY-message If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
Select Case Message.wParam Case &HBFFF& WindowState = vbMaximized Case &HC000& WindowState = vbMinimized Case &HC001& WindowState = vbNormal Case Else End Select Me.SetFocus End If 'let the operating system process other events DoEvents Loop End Sub Private Sub Form_Load() Dim ret As Long bCancel = False 'register the Ctrl-F hotkey Call RegisterHotKey(Me.hWnd, &HBFFF&, 0, vbKeyF9) 'vbMaximized Call RegisterHotKey(Me.hWnd, &HC000&, 0, vbKeyF10) 'vbMinimized Call RegisterHotKey(Me.hWnd, &HC001&, 0, vbKeyF11) 'vbNormal
'show some information Me.AutoRedraw = True Me.Print "按 F9 本窗口便被呼叫,并最大化!" & vbCrLf & "按 F10 本窗口便被呼叫,并最小化!" & vbCrLf & "按 F11 本窗口便被呼叫,并正常化!" 'show the form and Show 'process the Hotkey messages ProcessMessages End Sub Private Sub Form_Unload(Cancel As Integer) bCancel = True 'unregister hotkey Call UnregisterHotKey(Me.hWnd, &HBFFF&) End Sub
我试过可以做到,但是 出现乱码问题
用SetForegroundWindow把记事本设为前台窗口
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As LongSetForegroundWindow 记事本hwnd
2)
Public Declare Function SendMessageByStr& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)Public Function vbSetWindowText(ahWnd As Long, strSetText As String) As Integer
Dim t As String
Dim c As String
vbSetWindowText = SendMessageByStr(ahWnd, WM_SETTEXT, 0, strSetText)
End Function
你是按照我的这个一样做的吗,在我这里是没有问题,
我的跟你所说的不一样的,看清楚一点
=========================================
不能按照你的这样做都不能,
说什么
“DLL 的调用约定错误(错误 49)”
’========================================用SetForegroundWindow把记事本设为前台窗口
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long==========================================
这个都不能
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
第二问搞定了,还有第一个问,
1.请问怎样做 才可以与 Win 下的"记事本" 互相 设换 焦点????????????
当然不用鼠标点击设换,又不用 TAB 键
如 按“A”,就可以把焦点转到 "记事本" 中 ,按“B”了就可以把焦点转到窗口中的某个控件上。
Option ExplicitPrivate Const MOD_ALT = &H1
Private Const MOD_CONTROL = &H2
Private Const MOD_SHIFT = &H4
Private Const PM_REMOVE = &H1
Private Const WM_HOTKEY = &H312
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type Msg
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private bCancel As Boolean
Private Sub ProcessMessages()
Dim Message As Msg
'loop until bCancel is set to True
Do While Not bCancel
'wait for a message
WaitMessage
'check if it's a HOTKEY-message
If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
WindowState = vbMaximized
Me.SetFocus
End If
'let the operating system process other events
DoEvents
Loop
End Sub
Private Sub Form_Load()
Dim ret As Long
bCancel = False
'register the Ctrl-F hotkey
'ret = RegisterHotKey(Me.hWnd, &HBFFF&, MOD_CONTROL, vbKeyA)
ret = RegisterHotKey(Me.hWnd, &HBFFF&, 0, vbKeyA)
'show some information
Me.AutoRedraw = True
Me.Print "按 a 本窗口便被呼叫,并最大化!"
'show the form and
Show
'process the Hotkey messages
ProcessMessages
End Sub
Private Sub Form_Unload(Cancel As Integer)
bCancel = True
'unregister hotkey
Call UnregisterHotKey(Me.hWnd, &HBFFF&)
End Sub
Option ExplicitPrivate Const MOD_ALT = &H1
Private Const MOD_CONTROL = &H2
Private Const MOD_SHIFT = &H4
Private Const PM_REMOVE = &H1
Private Const WM_HOTKEY = &H312
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type Msg
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private bCancel As Boolean
Private Sub ProcessMessages()
Dim Message As Msg
'loop until bCancel is set to True
Do While Not bCancel
'wait for a message
WaitMessage
'check if it's a HOTKEY-message
If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
Select Case Message.wParam
Case &HBFFF&
WindowState = vbMaximized
Case &HC000&
WindowState = vbMinimized
Case &HC001&
WindowState = vbNormal
Case Else
End Select
Me.SetFocus
End If
'let the operating system process other events
DoEvents
Loop
End Sub
Private Sub Form_Load()
Dim ret As Long
bCancel = False
'register the Ctrl-F hotkey
Call RegisterHotKey(Me.hWnd, &HBFFF&, 0, vbKeyF9) 'vbMaximized
Call RegisterHotKey(Me.hWnd, &HC000&, 0, vbKeyF10) 'vbMinimized
Call RegisterHotKey(Me.hWnd, &HC001&, 0, vbKeyF11) 'vbNormal
'show some information
Me.AutoRedraw = True
Me.Print "按 F9 本窗口便被呼叫,并最大化!" & vbCrLf & "按 F10 本窗口便被呼叫,并最小化!" & vbCrLf & "按 F11 本窗口便被呼叫,并正常化!"
'show the form and
Show
'process the Hotkey messages
ProcessMessages
End Sub
Private Sub Form_Unload(Cancel As Integer)
bCancel = True
'unregister hotkey
Call UnregisterHotKey(Me.hWnd, &HBFFF&)
End Sub
=====================
你是不是问我
=========================
正在试源码…………………………
WindowState = vbMaximized
Me.SetFocus‘错误 在这个
End If
====================================
'回复人: dsclub(▁▂▃▄▅▆▇█ 騩鹬←短发男生)
还没有试试
==============================还有,是问 “廊坊” 还是“良芳” 呀