• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 533
  • Last Modified:

Auto Press OK on Msgbox

Hello,

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.

Thanks,

Dean
0
Lucree
Asked:
Lucree
1 Solution
 
vb_elmarCommented:
needs:
=======
1 Timer
2 Buttons
1 Label
1 Textbox ( MultiLine = True )


==========
Form1:
==========

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
Const EM_GETLINECOUNT = &HBA

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
    Command1_Click
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
myHeight
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


0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now