Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


How to close a MsgBox? Please help


How to close a MsgBox? Please help

Author
Message
CaboWaboTortioneer-in-Chee...
CaboWaboTortioneer-in-Cheef
Forum God
Forum God (610 reputation)Forum God (610 reputation)Forum God (610 reputation)Forum God (610 reputation)Forum God (610 reputation)Forum God (610 reputation)Forum God (610 reputation)Forum God (610 reputation)Forum God (610 reputation)

Group: Forum Members
Posts: 2, Visits: 1
Hi everybody. Sorry for my stupid question, but I'm clueless.
In short, here's my problem:
I have a VB prog which tests another one.
It starts the app under test:
ProcID=Shell(App.Path+"MyPrgUnderTestblah", vbNormalFocus)
...the app under test opens fine. The app under test opens a MsgBox by itself, which says some error, and waits for clicking an "OK" button. This is the main point of the test. I wait for that MsgBox to appear, I can take its ID by findW=FindWindow(vbNullString, "its name") - cause I know its name already.
By the same means, I can find AppUnderTest's ID as well.
If the MsgBox appears, I want to close the AppUnderTest (which I succeed by the usual "TerminateProcess" + "CloseHandle") and of course I want to kill the MsgBox too (cause for unknown reasons, when gettin killed, the AppUnderTest does not kill its own MsgBoxes) I can't succeed to kill the MsgBox, no matter what I do. It's my understanding that a msgbox is not a thread (doing "hTask = OpenProcess(PROCESS_TERMINATE, 0&, lTaskID)" gives me a result=0, which is an error). Yet I know its hwnd, I know its processID etc. I only can't kill it.
No "TerminateProcess" helps, no "CloseHandle" helps.
I imagine some "SendKeys" stuff would possibly help, but I'm not very used to that command, nor I found some examples of using it the way I want (I want to send the "Enter" key to THAT specific window, and I havent't found any example about this way of using it)

Can anyone give me some hints? Can anyone imagine a way to kill the damn MsgBox? Please help, cause I'm really clueless and desperate.
TIA, best--

CW Tortioneer
waynespangler
waynespangler
Forum God
Forum God (99K reputation)Forum God (99K reputation)Forum God (99K reputation)Forum God (99K reputation)Forum God (99K reputation)Forum God (99K reputation)Forum God (99K reputation)Forum God (99K reputation)Forum God (99K reputation)

Group: Forum Members
Posts: 910, Visits: 5.4K

This is from AllAPI:

Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As StringByVal lpWindowName As StringAs Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As LongByVal wMsg As LongByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As LongByVal lpClassName As StringByVal nMaxCount As LongAs Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As LongByVal nCmdShow As LongAs Long
Const SW_SHOWNORMAL = 1
Const WM_CLOSE = &H10
Const gcClassnameMSWord = "OpusApp"
Const gcClassnameMSExcel = "XLMAIN"
Const gcClassnameMSIExplorer = "IEFrame"
Const gcClassnameMSVBasic = "wndclass_desked_gsk"
Const gcClassnameNotePad = "Notepad"
Const gcClassnameMyVBApp = "ThunderForm"
Private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
    'Ask for a Window title
    Ret = InputBox("Enter the exact window title:" + Chr$(13) + Chr$(10) + "Note: must be an exact match")
    'Search the window
    WinWnd = FindWindow(vbNullString, Ret)
    If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
    'Show the window
    ShowWindow WinWnd, SW_SHOWNORMAL
    'Create a buffer
    lpClassName = Space(256)
    'retrieve the class name
    RetVal = GetClassName(WinWnd, lpClassName, 256)
    'Show the classname
    MsgBox "Classname: " + Left$(lpClassName, RetVal)
    'Post a message to the window to close itself
    PostMessage WinWnd, WM_CLOSE, 0&, 0&
End Sub


I would recommend you go to http://www.mentalis.org/agnet/apiguide.shtml and download their API guide. Each API has vb code to use it.
 


Wayne

I know enough to be dangerious.

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.

CaboWaboTortioneer-in-Chee...
CaboWaboTortioneer-in-Cheef
Forum God
Forum God (610 reputation)Forum God (610 reputation)Forum God (610 reputation)Forum God (610 reputation)Forum God (610 reputation)Forum God (610 reputation)Forum God (610 reputation)Forum God (610 reputation)Forum God (610 reputation)

Group: Forum Members
Posts: 2, Visits: 1
Thank you very very much. I'll check it as soon as I can. It helps me a lot.
best--
CW Tortioneer-in-Cheef, Head of "Self-inflicting" Dept.
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search