public static void MessageLoop() { MSG msg = new MSG(); while (NativeMethods.GetMessage(ref msg, IntPtr.Zero, 0, 0)) { if (!DuiUIManager.TranslateMessage(ref msg)) { NativeMethods.TranslateMessage(ref msg); try { NativeMethods.DispatchMessage(ref msg); } catch { Debug.WriteLine("MessageLoop Error"); #region 调试输出信息 #if DEBUG throw new Exception("MessageLoop Error"); #endif #endregion } } } }
public UINT ShowModal() { Debug.Assert(NativeMethods.IsWindow(m_hWnd)); UINT nRet = 0; //GetWindowOwner HWND hWndParent = NativeMethods.GetWindow(m_hWnd, GetWindowFlags.GW_OWNER); NativeMethods.ShowWindow(m_hWnd, ShowWindowStyles.SW_SHOWNORMAL); NativeMethods.EnableWindow(hWndParent, false); MSG msg = new MSG(); while (NativeMethods.IsWindow(m_hWnd) && NativeMethods.GetMessage(ref msg, IntPtr.Zero, 0, 0)) { if (msg.message == WindowMessages.WM_CLOSE && msg.hwnd == m_hWnd) { nRet = (UINT)msg.wParam; NativeMethods.EnableWindow(hWndParent, true); NativeMethods.SetFocus(hWndParent); } if (!DuiUIManager.TranslateMessage(ref msg)) { NativeMethods.TranslateMessage(ref msg); NativeMethods.DispatchMessage(ref msg); } if (msg.message == WindowMessages.WM_QUIT) { break; } } NativeMethods.EnableWindow(hWndParent, true); NativeMethods.SetFocus(hWndParent); if (msg.message == WindowMessages.WM_QUIT) { NativeMethods.PostQuitMessage((int)msg.wParam); } return(nRet); }