|
-
Oct 29th, 2006, 12:00 AM
#1
Posting a Tab
this code sends 2 Tabs when it should only send one, shouldn't it?
VB Code:
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" ( _
ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Sub Command1_Click()
Dim lhWnd As Long
lhWnd = FindWindowEx(FindWindowEx(0&, 0&, "notepad", vbNullString), 0&, "Edit", vbNullString)
PostMessage lhWnd, WM_KEYDOWN, vbKeyTab, 1&
PostMessage lhWnd, WM_KEYUP, vbKeyTab, 1&
End Sub
both WM_KEYDOWN and WM_KEYUP are causing a tab to be fired.
Should I be expecting this? I'm tired and confused...
-
Oct 29th, 2006, 07:52 AM
#2
Addicted Member
Re: Posting a Tab
VB Code:
PostMessage lhWnd, WM_KEYDOWN, vbKeyTab, 1&
Post a tab
VB Code:
PostMessage lhWnd, WM_KEYUP, vbKeyTab, 1&
post another one.
Why you need both ???
-
Oct 29th, 2006, 10:43 AM
#3
Re: Posting a Tab
Because you are posting a message and not invoking a keyboard stroke, so you dont need to set the UP message. I think you are doing it like keybd_event API.
When you post a message, the API will return back without waiting for the client thread to process the message. So your app thinks that you are posting the same message twice.
Sorry if I am wrong, but wait....
 Originally Posted by AllAPI..net
The PostMessage function places (posts) a message in the message queue associated with the thread that created the specified window and then returns without waiting for the thread to process the message.
I think I am quite close.
-
Oct 31st, 2006, 01:43 PM
#4
Re: Posting a Tab
i forgot about this thread.
it seemed that both the WM_KEYDOWN and the WM_KEYUP message were triggering a WM_CHAR message - but sure why, maybe because I hadn't set the 30th bit of the WM_KEYUP lParam (haven't checked). Anyway - i just decided to send the WM_CHAR message instead.
Regarding PostMessage, that just sticks the message in the queue and it gets processed when it reaches the top - when you use the keyboard normally the messages are posted not sent (i believe) - so that's probably not the cause
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|