Results 1 to 4 of 4

Thread: Posting a Tab

  1. #1

    Thread Starter
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Posting a Tab

    this code sends 2 Tabs when it should only send one, shouldn't it?
    VB Code:
    1. Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" ( _
    2.     ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    3.  
    4. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
    5.     ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    6.  
    7. Private Const WM_KEYDOWN = &H100
    8. Private Const WM_KEYUP = &H101
    9.  
    10. Private Sub Command1_Click()
    11.     Dim lhWnd As Long
    12.    
    13.     lhWnd = FindWindowEx(FindWindowEx(0&, 0&, "notepad", vbNullString), 0&, "Edit", vbNullString)
    14.     PostMessage lhWnd, WM_KEYDOWN, vbKeyTab, 1&
    15.     PostMessage lhWnd, WM_KEYUP, vbKeyTab, 1&
    16. 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...

  2. #2
    Addicted Member
    Join Date
    Jun 2006
    Location
    Egypt
    Posts
    162

    Re: Posting a Tab

    VB Code:
    1. PostMessage lhWnd, WM_KEYDOWN, vbKeyTab, 1&
    Post a tab

    VB Code:
    1. PostMessage lhWnd, WM_KEYUP, vbKeyTab, 1&
    post another one.

    Why you need both ???
    Mohammed Sayed - Egypt - Anesthetist



    =

    =

  3. #3
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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....
    Quote 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.
    Show Appreciation. Rate Posts.

  4. #4

    Thread Starter
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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
  •  



Click Here to Expand Forum to Full Width