using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace HotelPms.Share.Windows.Component
{
///
/// Û¯³êÄ¢éEBhEbZ[Wðí
///
public static class RemovePeekMessage
{
#region è
///
/// Y·éEBhEÉÄ`æªKvÆOSª»fµ½Æ«É|Xg³êébZ[W
///
private const int WM_PAINT = 0xF;
///
/// EBhEÌNCAgÌæÅ[U[ª}EXÌÚ®ðµ½Æ«É|Xg³êébZ[W
///
private const int WM_MOUSEMOVE = 0x200;
///
/// EBhEÌNCAgÌæÅ[U[ª}EX̶{^ðµ½Æ«É|Xg³êébZ[W
///
private const int WM_LBUTTONDOWN = 0x201;
///
/// EBhEÌNCAgÌæÅ[U[ª}EX̶{^𣵽ƫÉ|Xg³êébZ[W
///
private const int WM_LBUTTONUP = 0x202;
///
/// }EX|C^ªÌæOÉo½É|Xg³êébZ[W
///
private const int WM_MOUSELEAVE = 0x2A3;
private const int WM_KEYFIRST = 0x100;
private const int WM_KEYLAST = 0x109;
private const int WM_MOUSEFIRST = 0x200;
private const int WM_MOUSELAST = 0x20D;
#endregion
#region \¢Ì
///
/// MSG \¢Ì^
///
[StructLayout(LayoutKind.Sequential)]
public struct MSG
{
///
/// EBhEnh
///
public IntPtr hWnd;
///
/// MessageID
///
public int msg;
///
/// WParamtB[hiMessageID²ÆÉá¤æ)
///
public IntPtr wParam;
///
/// LParamtB[hiMessageID²ÆÉá¤æ)
///
public IntPtr lParam;
///
/// Ô
///
public int time;
///
/// J[\ÊuiXN[ÀWj
///
public POINTAPI pt;
}
///
/// POINTAPI\¢Ì
///
[StructLayout(LayoutKind.Sequential)]
public struct POINTAPI
{
///
/// XÀW
///
public int x;
///
/// YÀW
///
public int y;
}
#endregion
#region ñ^
///
/// wRemoveMsgÅpÂ\ÈIvV
///
enum EPeekMessageOption
{
///
/// ãbZ[WðL
[©çíµÈ¢
///
PM_NOREMOVE = 0,
///
/// ãbZ[WðL
[©çí·é
///
PM_REMOVE
}
#endregion
#region DllImport
///
/// XbhÌbZ[WL
[ÉbZ[Wª é©Ç¤©ð`FbNµ
/// êÎAwè³ê½\¢ÌÉ»ÌbZ[Wði[µÜ·
///
/// bZ[Wîñði[·éAMSG \¢Ì^ÏÌ|C^ðwèµÜ·
/// bZ[Wðæ¾·éEBhEÌnhðwèµÜ·BSÄÌêÍ NULL
/// bZ[WÌŬlðwèµAtB^OµÜ·BµÈ¢êÍ0
/// bZ[WÌÅålðwèµAtB^OµÜ·BµÈ¢êÍ0
/// ãbZ[WðL
[ðí·é©Û©
/// bZ[Wðæ¾µ½Æ«Í 0 ÈOA澵ȩÁ½Æ«Í 0
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool PeekMessage(
out MSG lpMsg,
int hWnd,
int wMsgFilterMin,
int wMsgFilterMax,
EPeekMessageOption wRemoveMsg
);
///
/// wè³ê½ MSG \¢Ì^ÏÉbZ[Wði[µÜ·
///
/// bZ[Wîñði[·éAMSG \¢Ì^ÏÌ|C^ðwèµÜ·
/// bZ[Wðæ¾·éEBhEÌnhðwèµÜ·BSÄÌêÍ NULL
/// bZ[WÌŬlðwèµAtB^OµÜ·BµÈ¢êÍ0
/// bZ[WÌÅålðwèµAtB^OµÜ·BµÈ¢êÍ0
///
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetMessage(
out MSG lpMsg,
int hWnd,
int wMsgFilterMin,
int wMsgFilterMax
);
///
/// wè³ê½EBhEbZ[WðEBhEvV[WÉfBXpb`µÜ·
///
/// fBXpb`·ébZ[Wði[µ½ MSG \¢ÌÏÌ|C^ðwèµÜ·
/// EBhEvV[WÌßèl
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr DispatchMessage(
out MSG lpMsg
);
#endregion
#region \bh
///
/// Û¯³êÄ¢éEBhEbZ[WðíµÜ·B
///
public static void Invoke()
{
//Console.WriteLine("y¦zRemovePeekMessage.Invoke():±Ì_ÌCxg·×ÄíÀsJn");
MSG wm;
while (PeekMessage(out wm, 0, WM_KEYFIRST, WM_KEYLAST, EPeekMessageOption.PM_REMOVE)) { }
while (PeekMessage(out wm, 0, WM_MOUSEFIRST, WM_MOUSELAST, EPeekMessageOption.PM_REMOVE)) { }
#if false
System.Diagnostics.Debug.WriteLine("Invoke begin");
MSG wm;
while (true)
{
bool ret = PeekMessage(out wm, 0, 0, 0, EPeekMessageOption.PM_REMOVE);
System.Diagnostics.Debug.WriteLine(wm.msg.ToString());
System.Diagnostics.Debug.WriteLine(ret.ToString());
if (!ret) { break; }
switch (wm.msg)
{
case WM_LBUTTONUP:
case WM_MOUSELEAVE:
case WM_PAINT:
System.Diagnostics.Debug.WriteLine(wm.msg.ToString());
DispatchMessage(out wm);
break;
}
}
System.Diagnostics.Debug.WriteLine("Invoke end");
#endif
}
#endregion
}
}