class UnityWebPlayerEx : AxUnityWebPlayerAXLib.AxUnityWebPlayer
{
#region MyRegion
//private const int WM_RBUTTONDOWN = 0x204;
//private const int WM_RBUTTONUP = 0x205;
//private const int WM_RBUTTONBLCLK = 0x206;
//public override bool PreProcessMessage(ref Message msg)
//{
// switch (msg.Msg)
// {
// case 0x204://鼠标右键按下消息
// this.SendMessage("ThiredViewCamera", "RightMouseButtonDown", null);
// this.SendMessage("FirstViewCamera", "RightMouseButtonDown", null);
// this.SendMessage("Main Camera", "RightMouseButtonDown", null);
// this.Focus();
// return true;
// case 0x205://鼠标右键抬起消息
// this.SendMessage("ThiredViewCamera", "RightMouseButtonUp", null);
// this.SendMessage("FirstViewCamera", "RightMouseButtonUp", null);
// this.SendMessage("Main Camera", "RightMouseButtonUp", null);
// return true;
// case 0x206://鼠标右键点击消息
// return true;
// }
// return base.PreProcessMessage(ref msg);
//}
#endregion
public UnityWebPlayerEx()
{
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int MoveWindow(IntPtr hwnd, int x, int y, int nWidth, int nHeight, bool bRepaint);
[DllImport("user32")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
private const int WM_PARENTNOTIFY = 0x210;
protected override void WndProc(ref Message m)
{
_menuHided = false;
switch (m.Msg)
{
case WM_PARENTNOTIFY:
HideContextMenu(m);
break;
}
base.WndProc(ref m);
}
/// <summary>
/// 是否隐藏右键菜单,默认还是要显示的,new出来后要设置一下
/// </summary>
public bool DisableContextMenu{ get; set; }
private bool _menuHided { get; set; }
private void HideContextMenu(Message m)
{
if (_menuHided) return;
if (DisableContextMenu == false) return;
if (m.ToString().Contains("WM_RBUTTONDOWN"))
{
if (_menuHided == false)
{
new Thread(() =>
{
while (_menuHided == false)
{
HideContextMenu();
}
}).Start();
}
}
}
private void HideContextMenu()
{
//Unity.ContextSubmenu 为右键快键菜单的Form
IntPtr handle = FindWindow("Unity.ContextSubmenu", null);
if (handle != IntPtr.Zero)
{
//把快捷菜单Form移到左上角并设置其大小为0
MoveWindow(handle, 0, 0, 10, 10, true);
MoveWindow(handle, 0, 0, 0, 0, true);
_menuHided = true;
}
}
}