/// <summary> /// 清空指定窗体消息队列中的所有的消息 /// </summary> /// <returns>删除的消息个数</returns> public static int ClearMessage(IntPtr hwnd) { int result = 0; while (true) { NativeMSG msg = new NativeMSG(); //if (NativeGetMessage(ref msg, hwnd, 0, 0)) //{ // result++; //} //else //{ // break; //} if (NativePeekMessage(ref msg, hwnd, 0, 0, 0xffffff)) { if (msg.message == 0) { break; } result++; } else { break; } }//while return(result); }
private Win32Message(NativeMSG msg) { _HWnd = new IntPtr(msg.hwnd); _LParam = new IntPtr(msg.lParam); _Msg = msg.message; _WParam = new IntPtr(msg.wParam); }
public static System.Drawing.Point GetMousePositionFromMSG(NativeMSG msg) { NativePOINT pt = new NativePOINT(); pt.x = (short)((uint)msg.lParam & 0x0000FFFFU); pt.y = (short)(((uint)msg.lParam & 0xFFFF0000U) >> 16); ClientToScreen(new IntPtr(msg.hwnd), ref pt); return(new System.Drawing.Point(pt.x, pt.y)); }
/// <summary> /// 从消息队列中获得一个消息,但不从消息队列中删除该消息 /// </summary> /// <returns>获得的消息对象</returns> public static Win32Message Peek() { NativeMSG msg = new NativeMSG(); if (NativePeekMessage(ref msg, IntPtr.Zero, 0, 0, 0)) { return(new Win32Message(msg)); } else { return(null); } }
/// <summary> /// 从消息队列中获得一个消息对象,并从消息队列中删除这个消息 /// </summary> /// <returns>获得的消息对象</returns> public static Win32Message GetMessage() { NativeMSG msg = new NativeMSG(); if (NativeGetMessage(ref msg, IntPtr.Zero, 0, 0)) { Win32Message msg2 = new Win32Message(msg); return(msg2); } else { return(null); } }
[DllImport("user32", CharSet = CharSet.Ansi)] //ANSI public static extern int DispatchMessageA(ref NativeMSG msg);
[DllImport("user32")] //ANSI public static extern bool PeekMessageA(out NativeMSG lpMsg, int hWnd, uint wMsgFilterMin, uint wMsgFilterMax, PeekMessageFlags wRemoveMsg);
[DllImport("user32")] //ANSI public static extern int GetMessageA(out NativeMSG msg, int hwnd, int minFilter, int maxFilter);
public static extern bool PeekMessage(ref NativeMSG msg, IntPtr hWnd, uint wFilterMin, uint wFilterMax, uint wFlag);
public static extern bool GetMessage(ref NativeMSG msg, IntPtr hWnd, uint wFilterMin, uint wFilterMax);
public static extern bool DispatchMessage(ref NativeMSG msg);
public static extern bool TranslateMessage(ref NativeMSG msg);
private static extern bool NativePeekMessage(ref NativeMSG msg, IntPtr hWnd, uint wFilterMin, uint wFilterMax, uint wFlag);
private static extern bool NativeGetMessage(ref NativeMSG msg, IntPtr hWnd, uint wFilterMin, uint wFilterMax);