protected static Int32 __WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { DuiHostFormBase hostForm = null; if (msg == WindowMessages.WM_NCCREATE) { var lpcs = (LPCREATESTRUCT)Marshal.PtrToStructure((IntPtr)lParam, typeof(LPCREATESTRUCT)); IntPtr pHostForm = new IntPtr(lpcs.lpCreateParams); var gch = GCHandle.FromIntPtr(pHostForm); hostForm = gch.Target as DuiHostFormBase; if (hostForm != null) { hostForm.m_hWnd = hWnd; NativeMethods.SetWindowLong(hWnd, (int)SetWindowLongOffsets.GWL_USERDATA, pHostForm); } } else { IntPtr pHostForm = NativeMethods.GetWindowLong(hWnd, SetWindowLongOffsets.GWL_USERDATA); try { var gch = GCHandle.FromIntPtr(pHostForm); hostForm = gch.Target as DuiHostFormBase; } catch { } if (msg == WindowMessages.WM_NCDESTROY && hostForm != null) { LRESULT lRes = NativeMethods.CallWindowProc(hostForm.m_defWindowProc, hWnd, (int)msg, (IntPtr)wParam, (IntPtr)lParam).ToInt32(); NativeMethods.SetWindowLong(hWnd, (int)SetWindowLongOffsets.GWL_USERDATA, IntPtr.Zero); if (hostForm.m_bSubclassed) { hostForm.Unsubclass(); } hostForm.m_hWnd = IntPtr.Zero; hostForm.OnFinalMessage(hWnd); return(lRes); } } if (hostForm != null) { return(hostForm.HandleMessage(msg, wParam, lParam)); } else { return(NativeMethods.DefWindowProc(hWnd, (int)msg, new IntPtr(wParam), new IntPtr(lParam)).ToInt32()); } }
public static extern bool ReplyMessage( LRESULT lResult);
protected virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) { LRESULT lRes = NativeMethods.CallWindowProc(m_defWindowProc, m_hWnd, (int)uMsg, (IntPtr)wParam, (IntPtr)lParam).ToInt32(); return(lRes); }