2010年9月27日 星期一

C#包Swf時,隱藏右鍵選單

1.先匯入API
using System.Runtime.InteropServices;

2.設定屬性
        #region Disable Flash's Context Menu
        private const int GWL_WNDPROC = -4;
        public delegate IntPtr FlaWndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

        private IntPtr OldWndProc = IntPtr.Zero;
        private FlaWndProc Wpr = null;

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, FlaWndProc wndProc);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr CallWindowProc(IntPtr wndProc, IntPtr hWnd, int msg, IntPtr        wParam, IntPtr lParam);


3.隱藏右鍵選單FUNCTION
        private IntPtr FlashWndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam)
        {
            if (msg == 516)
                return (IntPtr)0;
            return CallWindowProc(OldWndProc, hWnd, msg, wParam, lParam);
        }
        #endregion

4.當Form載入完成後,呼叫的Function
        private void AsusWebStorage_Load(object sender, EventArgs e)
        {
            try
            {
                //Console.WriteLine("AsusWebStorage_load");
                this.Wpr = new FlaWndProc(this.FlashWndProc);
                this.OldWndProc = SetWindowLong(swfPanel.Handle, GWL_WNDPROC, Wpr);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Load exception:" + ex.Message);
            }
        }

1 則留言:

ABC 提到...

沒事 到此一遊 ㄎ ㄎ