Here's my problem: we have an automated build process for our product. During the compilation of one of the VB6 projects a message box is spit out that requires the user to click 'ok' before it can move on. Being an automated process this is a bad thing because it can end up sitting there for hours not moving until someone clicks ok. We've looked into the VB6 code to try and suppress the message box, but no one can seem to figure out how to right now. So as a temp fix I'm working on a program that will run in the background and when the message box pops up, closes it. So far I'm able to detect when the message pops up but I can't seem to find a function to close it properly. The program is being written in C# and I'm using the FindWindow function in user32.dll to get a pointer to the window. So far I've tried closeWindow, endDialog, and postMessage to try and close it but none of them seem to work. closeWindow just minimizes it, endDialog comes up with a bad memory exception, and postMessage does nothing. Does anyone know of any other functions that will take care of this, or any other way of going about getting rid of this message? Thanks in advance.
here's the code I have currently:
class Program
{
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
static void Main(string[] args)
{
IntPtr window = FindWindow(null, "Location Browser Error");
while(window != IntPtr.Zero)
{
Console.WriteLine("Window found, closing...");
//use some function to close the window
window = IntPtr.Zero;
}
}
}
Right-click the icon referring to the dialog box from the Windows taskbar and click “Close”.
Close(), TaskScheduler. FromCurrentSynchronizationContext()); MessageBox. Show(w, message, caption); Based on the effect that closing the form that owns the message box will close the box as well.
You can use the methods Process. Kill or Process. CloseMainWindow to stop a process. If the app has no GUI then just call Kill, otherwise a well-designed GUI application should respond to the CloseMainWindow method and allow the user to save his work before the application closes.
You have to found the window, that is the first step. After you can send the SC_CLOSE
message using SendMessage
.
[DllImport("user32.dll")]
Public static extern int SendMessage(int hWnd,uint Msg,int wParam,int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;
IntPtr window = FindWindow(null, "Location Browser Error");
if (window != IntPtr.Zero)
{
Console.WriteLine("Window found, closing...");
SendMessage((int) window, WM_SYSCOMMAND, SC_CLOSE, 0);
}
When you find the message box, try sending it WM_NOTIFY
with a BN_CLICKED
type and the ID of the OK button.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With