Auto Press OK on Msgbox


I have an issue where I am controlling another application with the Function SendMessage.  The problem is when  I press one of the buttons on this other application it gives me an OK message box.  

How can I auto click this 'OK' button on an message box.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

1 Timer
2 Buttons
1 Label
1 Textbox ( MultiLine = True )


Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long

Private Sub Command1_Click()
Timer1.Enabled = False: MsgBox "You clicked 'Yes'"
End Sub

Private Sub Command2_Click()
Timer1.Enabled = False: MsgBox "You clicked 'No'"
End Sub

Private Sub Timer1_Timer()
    Timer1.Enabled = False
End Sub

Private Sub Form_Load()
Timer1.Interval = 4000
Command1.Caption = "Yes"
Command2.Caption = "No"
Command1.Move 720, 840, 1095, 375
Command2.Move 2280, 840, 1095, 375
Me.Width = 4245: Me.Height = 1920
Label1.Move 720, 360, 2895, 615
Text1.Move 720, 360, 2895, 615
Text1.Visible = False

Caption = "Registration"
zz = zz & "This Program is not registered."
zz = zz & vbCrLf
zz = zz & vbCrLf
zz = zz & vbCrLf
zz = zz & vbCrLf
zz = zz & vbCrLf
zz = zz & vbCrLf
zz = zz & vbCrLf
zz = zz & vbCrLf
zz = zz & vbCrLf
zz = zz & vbCrLf
zz = zz & vbCrLf
zz = zz & vbCrLf
zz = zz & vbCrLf
zz = zz & vbCrLf
zz = zz & vbCrLf
zz = zz & vbCrLf
zz = zz & "Would you like to register it now?"

Text1 = zz ' Text1 only needed to measure the label1 height.
Label1 = zz
End Sub

Private Sub myHeight() 'calculate the height of Label1 (for long text, the label must be higher)
    RowsT1 = SendMessage(Text1.hWnd, &HBA, 0, 0) 'how many lines has text1 ?
    Label1.Height = 360 + (195 * (RowsT1 - 1)) 'calculate the height for label1
    Form1.Height = 1995 + (195 * (RowsT1 - 1))
    Command1.Top = Me.Height - 1080
    Command2.Top = Me.Height - 1080
Me.Move Screen.Width / 2 - Width / 2, Screen.Height / 2 - Height / 2 'display msgbox to center screen
End Sub


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.