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 DuiHostBase(Control host) { m_HostControl = host; m_PatientUIMagager = new DuiUIManager(); m_PatientUIMagager.Init(this); AssignHandle(host.Handle); }
public bool RegisterWindowClass() {//此处错误,不是注册ClassEx WNDCLASSEX wc = new WNDCLASSEX(); wc.style = GetClassStyle(); wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hIcon = IntPtr.Zero; wc.lpfnWndProc = __WndProc; wc.hInstance = DuiUIManager.GetInstance(); wc.hCursor = NativeMethods.LoadCursor(IntPtr.Zero, (UINT)CursorType.IDC_ARROW); int COLOR_WINDOW = 5; wc.hbrBackground = new IntPtr(COLOR_WINDOW + 1); wc.lpszMenuName = null; wc.lpszClassName = GetWindowClassName(); ATOM ret = NativeMethods.RegisterClassEx(ref wc); Debug.Assert(Marshal.GetLastWin32Error() == ERROR_CLASS_ALREADY_EXISTS); return(Marshal.GetLastWin32Error() == ERROR_CLASS_ALREADY_EXISTS); }
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); }
public HWND Create(HWND hwndParent, LPCTSTR strName, DWORD dwStyle, DWORD dwExStyle, int x, int y, int cx, int cy, HMENU hMenu) { if (GetSuperClassName() != null && !RegisterSuperclass()) { return(IntPtr.Zero); } if (GetSuperClassName() == null && !RegisterWindowClass()) { return(IntPtr.Zero); } m_hWnd = NativeMethods.CreateWindowEx(dwExStyle, GetWindowClassName(), strName, dwStyle, x, y, cx, cy, hwndParent, hMenu, DuiUIManager.GetInstance(), m_pointer); Debug.Assert(m_hWnd != IntPtr.Zero); return(m_hWnd); }