Message boxes

I currently have my ISP through Netzero..(Free Internet).   It is pretty cool.   But one problem is after about  30min-45min their program(Netzero) pops up a message box saying "Your connection has been inactive.  Please click Resume button to stay online..."  Or something like that.....They do this to make sure you are online.  So this really sucks for big down loads.  The message box will pop up and give you 60 seconds to press resume, also I can go to the task manager or task list and see that the message box shows up in the task list titled "Netzero Inactivity Warning".   My question is...
I already have a DLL that can check to see if a process is running....I now want to write a VB program that will use the dll...basicly put it on a timer every 45 seconds it will scan to see if the process "Netzero Inactivity Warning" is running...
How do I get VB to click the Resume Button on that message box.  Resume Button is the only button on the message box..  When a message comes up...."Netzero Inactivity Warning" message box has focus.  Can I tell VB to execute a Enter key on my keyboard???
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

ryanvsConnect With a Mentor Commented:
Using an API will work better.  There are two catches.  One is that you need to have handle to the window for the message box.  Two is that you need to know the control ID of the button that you want VB to press.  Getting the hwnd isn't difficult and I'm going to assume you can do this (but if you need some help just ask).  The control ID is usually 1 for OK and similar messages.  You can use Spy++ (under Visual Studio Tools) and use the find window and select the button you want to press.  Under Window Properties is a value called Control ID which is the value you want.

So, to make a long story short...

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Const WM_COMMAND = &H111

Dim hwnd As Long
Dim lCtrlID As Long
Dim lResult As Long

' hwnd = FindMessageBox...
lResult = SendMessage(hwnd, WM_COMMAND, ByVal lCtrlID, ByVal 0&)

' Zero lResult means application processed message, but not necessarily a success.  
' Although when I tested this, it worked and it returned 1.  Your mileage may vary

Here is a little documentation on wParam and lParam for WM_COMMAND:

The high-order word specifies the notification code if the message is from a control. If the message is from an accelerator, this value is 1. If the message is from a menu, this value is zero.
The low-order word specifies the identifier of the menu item, control, or accelerator.

Handle to the control sending the message if the message is from a control. Otherwise, this parameter is NULL.

Good luck.
Use Sendkeys
SendKeys "{ENTER}"
To do it all from VB
Declare the following
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
         (ByVal lpClassName As String, ByVal lpWindowName As String) As Long


Private Sub Timer1_Timer()
  Dim lRet As Long
  lRet = FindWindow(vbNullString, "Netzero Inactivity Warning" )
  If (lRet <> 0) Then
   SendKeys "{ENTER}"
  End If
End Sub
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

You can also use a SendMessage API after you find the handle of that button and send i thinkmessage wm_button i think to click that button to stay on line.
The only problem with the sendkeys is you need to make sure the Netzero message box has the keyboard focus.

There is a windows API to do that but it escapes my memory.
strongdAuthor Commented:
Thanks I think this wil work...
All Courses

From novice to tech pro — start learning today.