How to control another applications message box from VB6

I have a program that runs the ImportExportFavorites command of ShellUIHelper.  Natually this causes IE to ask "are you sure you wanna import your favs?" and "operation complete (click okay)".  Ideally i'd like to run ShellUIHelper with an option that tells it not to show these messages, but i didnt see that as an option.  So now the only thing i can think of is sendkeys "y" and "<enter>".  Problem is that since this is an import command, the time varies.  I could just loop for a while, or set a timer and send them- but that is sloppy.  I'm trying to find a way to search for the message box, but i have know idea what its name is.  It has no taskbar real estate and the name "Import Favorites" (which is shown ontop of the box) didnt work with appactivate.  My plan is to have this program run late at night when no one is using the computer; however i cant be sure that someone wont send an IM or something.  Please help.... running out of ideas.

e
irkgreenAsked:
Who is Participating?
 
vinnyd79Connect With a Mentor Commented:
It will return the handle for the window,then you could use FindWindowEx to get the handle of the button that needs to be clicked.It would have to be running in the background.You could use a Timer with the interval set to 1000 and use something like this:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Const BM_CLICK = &HF5

Private Sub Timer1_Timer()
Dim lWin As Long, Control As Long
' get handle to the window by finding caption
lWin = FindWindow(vbNullString, "The Windows Caption Goes Here")
If lWin <> 0 Then
    ' get handle to Ok button
    Control = FindWindowEx(lWin, 0, "Button", "Ok")
    ' click the button
    SendMessage Control, BM_CLICK, 0, 0
End If

End Sub
0
 
vinnyd79Commented:
Have you already tried using FindWindow API to find the handle of the Window?
0
 
irkgreenAuthor Commented:
No... how can i do that?  Will it give me a unique name for that window?  Will i hafta run findwindow while the message is open?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
irkgreenAuthor Commented:
I tried that and i think i am close.  I think "import favorites" is not the actual caption name though.  My code:

Again:
lWin = FindWindow(vbNullString, "Import Favorites")
If lWin <> 0 Then
    'get handle to Ok button
    Control = FindWindowEx(lWin, 0, "Button", "Yes")
    'click the button
    SendMessage Control, BM_CLICK, 0, 0
Else
GoSub Again:
End If

"Import Favorites" is the tilte of the message box (yes/no) but perhaps not the caption.  Sicnce it doesnt have a taskbar slot i dont think finwindow is finding it. or perhaps it has a different name that i dont know about.  Any ideas???
0
 
irkgreenAuthor Commented:
i changed the lwin line to:

lWin = FindWindow("#32770", Null)

lWin = FindWindow("#32770", "Import Favorites")

I used a small app to determine the classname of the message box window and found it (and most messageboxes) to be named #32770.  A null for the caption is supposed to accept anything... but neither worked :(

not sure what to do.  I think that it is possible that the message box is actually part of my application and not an extension of Internet Explorer (which i assumed it was).  So i might rephrase my question to "How to control an application's message box from VB6"?
0
 
irkgreenAuthor Commented:
ok this actually made it into the IF satement:

Again:

lWin = FindWindow("#32770", vbNullString)
If lWin <> 0 Then
    MsgBox ""
    'get handle to Ok button
    Control = FindWindowEx(lWin, 0, "Button", "Okay")
    'click the button
    SendMessage Control, BM_CLICK, 0, 0
Else
GoSub Again:
End If

it seems the vbnullstring is the proper variable to use; however i have to click yes to import favorites and okay to dismiss the successful import before lwin<>0.  So it seems that perhaps the program is on hold until the user clicks an option.

Could there be a way to start a new sub that triggers when a message box appears?
0
 
irkgreenAuthor Commented:
I've solved my problem, sorta.  I realized that the message box was putting a stop on the thread and since VB6 only supports a single thread I had to go another route. Since i dont have VB.NET i had to compile a second exe to enumarate all of the windows searching for the message box and send a key to dismiss it.  The original exe simply called on the 2nd to do this.  Works fine.

I am not sure how or if i can close this thread.
0
 
satishpreddyCommented:
general function, that will display message boxes with minimun width and height. If message exceeds minimum width and height, then it should resize and adjust to text.
 
And, for errors, show exlamation, for successful messages show question mark.
 
So, on a high level, the message box function shall look like,
 
displaymessage(tMessage as string, tMessageType, tMessageIcon)
 
Include parameters as required.
 
Thanks and regards

Sai Gopal
0
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.

All Courses

From novice to tech pro — start learning today.