Kill all Messagebox in Visual studio 2008

I want to kill all messagebox from external program , or kill all open messagebox  in windows. thanks a lot
GknrsyAsked:
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.

GknrsyAuthor Commented:
i found some c# codes but i don't know how in vb2008

// showbox.cs

using System;
using System.Windows.Forms;

class Program
{
    static void Main()
    {
       Application.Run(new ShowBox());      
    }
}

class ShowBox : Form
{
    private Button btn;

    public ShowBox()
    {
       btn = new Button();
       btn.Text = "Press me";
       btn.Click += new EventHandler(button_Click);
       this.Controls.Add(btn);
    }

    private void button_Click(object sender, EventArgs e)
    {
       MessageBox.Show(this, "Hello from Show Box", "Greeting");
    }
}  

// capturebox.cs

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;

class CaptureBox
{
    [DllImport("user32.dll")]
    static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);


    static IntPtr hwndParent;

    static void Main()
    {
        Process[] procs = Process.GetProcessesByName("showbox");

        if (procs.Length == 0)
        {
            Console.WriteLine("Showbox isn't running");
            return;
        }
     
        hwndParent = procs[0].MainWindowHandle;

        bool hasAppeared = false;

        do        
        {
            if (!procs[0].HasExited)
            {
               hasAppeared = CheckMessageBox();
               Thread.Sleep(1000); // check every second
            }
            else
            {
               Console.WriteLine("Showbox has exited");
               break;
            }
        }          
        while(!hasAppeared);
    }

    static bool CheckMessageBox()
    {
        // IntPtr hwndMB = FindWindowEx(hwndParent, IntPtr.Zero, "#32770", "Greeting");
        // Apparently MessageBox is always top level in .NET
        IntPtr hwndMB = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32770", "Greeting");
        if (hwndMB == IntPtr.Zero)
        {
           Console.WriteLine("MessageBox not showing");
           return false;
        }
        else
        {          
           Console.WriteLine("MessageBox has appeared");
           return true;
        }
    }
}
0
käµfm³d 👽Commented:
Below is a VB translation of the code you posted. For the class CaptureBox, I started a VB Console Application project and put the code inside a module file.
''''''''''''''''''''''''''''''''''''''''''''
'' Showbox code
''''''''''''''''''''''''''''''''''''''''''''
Public Class ShowBox
    Private btn As Button
 
    Public Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
 
        ' Add any initialization after the InitializeComponent() call.
        btn = New Button()
        btn.Text = "Press me"
        AddHandler btn.Click, AddressOf button_Click
        Controls.Add(btn)
    End Sub
 
    Private Sub button_Click(ByVal sender As Object, ByVal e As EventArgs)
        MessageBox.Show(Me, "Hello from Show Box", "Greeting")
    End Sub
 
End Class
 
''''''''''''''''''''''''''''''''''''''''''''
'' CaptureBox code
''''''''''''''''''''''''''''''''''''''''''''
Imports System.Runtime.InteropServices
Imports System.Diagnostics
Imports System.Threading
 
Module Module1
    Dim hwndParent As IntPtr
 
    Sub Main()
        Dim procs() As Process = Process.GetProcessesByName("showbox")
 
        If procs.Length = 0 Then
            Console.WriteLine("Showbox isn't running.");
            Return
        End If
 
        hwndParent = procs(0).MainWindowHandle
 
        Dim hasAppeared As Boolean = False
 
        Do
            If Not procs(0).HasExited Then
                hasAppeared = CheckMessageBox()
                Thread.Sleep(1000)
            Else
                Console.WriteLine("Showbox has exited")
                Exit Do
            End If
        Loop While Not hasAppeared
    End Sub
 
    Function CheckMessageBox() As Boolean
        Dim hwndMB As IntPtr = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32770", "Greeting")
 
        If hwndMB = IntPtr.Zero Then
            Console.WriteLine("MessageBox not showing.")
            Return False
        Else
            Console.WriteLine("MessageBox has appeared")
            Return True
        End If
    End Function
 
    <DllImport("user32.dll")> _
    Function FindWindowEx(ByVal hwndParent As IntPtr, ByVal hwndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
    End Function
 
 
End Module

Open in new window

0
GknrsyAuthor Commented:
i just found this code in internet. is it working??
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

GknrsyAuthor Commented:
i asked because just tomarrow i will try :)
0
GknrsyAuthor Commented:
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Imports System.Threading
Module Module1



    Dim hwndParent As IntPtr



    Function CheckMessageBox() As Boolean
        Dim hwndMB As IntPtr = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32770", "Greeting!")

        If hwndMB = IntPtr.Zero Then
            MsgBox("MessageBox not showing.")
            Return False
        Else
            MsgBox("MessageBox has appeared")
            Return True
        End If
    End Function

    <DllImport("user32.dll")> _
    Function FindWindowEx(ByVal hwndParent As IntPtr, ByVal hwndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
    End Function


End Module

with this code i am checking messagebox working or not .

now if messagebox working how i will close this message box?


0
GknrsyAuthor Commented:

    Function CheckMessageBox() As Boolean
        Dim hwndMB As IntPtr = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32770", "Hello")

        If hwndMB = IntPtr.Zero Then
            Exit Function
            Return False
        Else
            Dim procs() As Process = Process.GetProcessesByName("ABC")
            AppActivate(procs(0).Id)
            SendKeys.Send("{enter}") ' this sends F5 to the window
            Return True
        End If
    End Function

i wite this code , but this code working with focus i mean when sending enter key to messagebox it becomes active. i want to send enter key or just kill message box background , i don't want to it brings front :) sorry for bad explanation.
0
GknrsyAuthor Commented:
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Imports System.Threading
Module Module1

    Dim hwndParent As IntPtr

    Function CheckMessageBox() As Boolean
        Dim hwndMB As IntPtr = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32770", "")

        If hwndMB = IntPtr.Zero Then
            Exit Function
            Return False
        Else
           SendMessage(hwndMB, WM_CLOSE, 0, 0)
            Return True
        End If
    End Function

    <DllImport("user32.dll")> _
   Function SendMessage(ByVal hwnd As IntPtr, ByVal wMsg As IntPtr, ByVal wParam As Long, _
    ByVal lParam As Long) As Long

    End Function

    Private Const WM_CLOSE = &H10


    <DllImport("user32.dll")> _
    Function FindWindowEx(ByVal hwndParent As IntPtr, ByVal hwndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
    End Function


End Module


This is working very well :)
0

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
Microsoft Development

From novice to tech pro — start learning today.