Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //In the Form class
- private void CloseTheBox(string caption) //Closing a messagebox by caption
- {
- IntPtr hWnd = CloseMessageBox.FindWindowByCaption(null, caption);
- if (hWnd != IntPtr.Zero)
- CloseMessageBox.SendMessage(new HandleRef(null, hWnd), CloseMessageBox.CloseNumber, IntPtr.Zero, IntPtr.Zero);
- }
- //Class containing the members required.
- public class CloseMessageBox
- {
- [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
- public static extern IntPtr FindWindowByCaption(string lpClassName, string lpWindowName);
- [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
- public static extern IntPtr SendMessage(HandleRef hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
- const UInt32 WM_CLOSE = 0x0010;
- public static UInt32 CloseNumber
- {
- get
- {
- return WM_CLOSE;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment