private bool LocalModalMessageLoop(Form form) { try { // Execute the message loop until the active component tells us to stop. // NativeMethods.MSG msg = new NativeMethods.MSG(); bool unicodeWindow = false; bool continueLoop = true; while (continueLoop) { bool peeked = UnsafeNativeMethods.PeekMessage(ref msg, NativeMethods.NullHandleRef, 0, 0, NativeMethods.PM_NOREMOVE); if (peeked) { // If the component wants us to process the message, do it. // The component manager hosts windows from many places. We must be sensitive // to ansi / Unicode windows here. // if (msg.hwnd != IntPtr.Zero && SafeNativeMethods.IsWindowUnicode(new HandleRef(null, msg.hwnd))) { unicodeWindow = true; if (!UnsafeNativeMethods.GetMessageW(ref msg, NativeMethods.NullHandleRef, 0, 0)) { continue; } } else { unicodeWindow = false; if (!UnsafeNativeMethods.GetMessageA(ref msg, NativeMethods.NullHandleRef, 0, 0)) { continue; } } if (!PreTranslateMessage(ref msg)) { UnsafeNativeMethods.TranslateMessage(ref msg); if (unicodeWindow) { UnsafeNativeMethods.DispatchMessageW(ref msg); } else { UnsafeNativeMethods.DispatchMessageA(ref msg); } } if (form != null) { continueLoop = !form.CheckCloseDialog(false); } } else if (form == null) { break; } else if (!UnsafeNativeMethods.PeekMessage(ref msg, NativeMethods.NullHandleRef, 0, 0, NativeMethods.PM_NOREMOVE)) { UnsafeNativeMethods.WaitMessage(); } } return continueLoop; } catch { return false; } }
private bool LocalModalMessageLoop(Form form) { try { System.Windows.Forms.NativeMethods.MSG msg = new System.Windows.Forms.NativeMethods.MSG(); bool flag = false; bool flag2 = true; while (flag2) { if (!System.Windows.Forms.UnsafeNativeMethods.PeekMessage(ref msg, System.Windows.Forms.NativeMethods.NullHandleRef, 0, 0, 0)) { goto Label_00AB; } if ((msg.hwnd != IntPtr.Zero) && System.Windows.Forms.SafeNativeMethods.IsWindowUnicode(new HandleRef(null, msg.hwnd))) { flag = true; if (System.Windows.Forms.UnsafeNativeMethods.GetMessageW(ref msg, System.Windows.Forms.NativeMethods.NullHandleRef, 0, 0)) { goto Label_0074; } continue; } flag = false; if (!System.Windows.Forms.UnsafeNativeMethods.GetMessageA(ref msg, System.Windows.Forms.NativeMethods.NullHandleRef, 0, 0)) { continue; } Label_0074: if (!this.PreTranslateMessage(ref msg)) { System.Windows.Forms.UnsafeNativeMethods.TranslateMessage(ref msg); if (flag) { System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(ref msg); } else { System.Windows.Forms.UnsafeNativeMethods.DispatchMessageA(ref msg); } } if (form != null) { flag2 = !form.CheckCloseDialog(false); } continue; Label_00AB: if (form == null) { break; } if (!System.Windows.Forms.UnsafeNativeMethods.PeekMessage(ref msg, System.Windows.Forms.NativeMethods.NullHandleRef, 0, 0, 0)) { System.Windows.Forms.UnsafeNativeMethods.WaitMessage(); } } return flag2; } catch { return false; } }