Results 1 to 5 of 5

Thread: SendMessage only works once on same object

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    SendMessage only works once on same object

    I have two apps, App1 and App2. App1 has the HWND of App2's Command1 button. In App1 I have this code:


    App1 Code
    Code:
    Private Sub Command1_Click()
     If Command1.Caption = "Start" Then
       Command1.Caption = "Stop"
       SetForegroundWindow App2Command1Hwnd
       SendMessageByString App2Command1Hwnd, BM_CLICK, 0, 0
     Else
       Command2.Caption = "Start"
       SetForegroundWindow App2Command1Hwnd
       SendMessageByString App2Command1Hwnd, BM_CLICK, 0, 0
      End If
    End Sub
    The first time I click on Command1 in App1 it sends the BM_CLICK to App2's Command1 and clicks it. Code under Start in App2 runs

    The second time I click on Command1 in App1 nothing changes in App2's Command1 click event. Processing continues; does not stop. Actually the button is not fired at all because I have MsgBoxes telling me where control is. First time MsgBox prints "Inside If", second time no message is displayed where I thought it would have been "Inside Else".

    App2's Form gets the Focus on both times I click on App1's Command1 button

    App2 Code
    Code:
    Private Sub Command1_Click()
     If Command1.Caption = "Start" Then
       '
       ' ENTERS HERE
       '
       MsgBox "Inside If"
       Command1.Caption = "Stop"
     Else
       '
       ' NEVER ENTERS HERE
       '
       MsgBox "Inside Else"
       Command1.Caption = "Start"
     End If
    End Sub
    Last edited by jmsrickland; Jun 10th, 2013 at 04:06 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

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