免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
C#程序關(guān)聯(lián)文件、系統(tǒng)右鍵、跨進(jìn)程消息
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.Win32; 
using System.Runtime.InteropServices; 
 
 
namespace Xplayer 

    public class LinkFile 
    { 
        #region 程序關(guān)聯(lián)到文件 
        [DllImport("shell32.dll")]//立即刷新顯示而不重啟電腦 
        public static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2); 
        /// <summary> 
        /// 關(guān)聯(lián)文件 雙擊啟動(dòng)程序的文件 
        /// </summary> 
        public static string[] FileNameWhoInvokeEXE = null; 
 
        /// <summary> 
        /// 設(shè)置關(guān)聯(lián)文件 
        /// </summary> 
        /// <param name="ExName">文件擴(kuò)展名</param> 
        /// <param name="TypeName">文件類型名</param> 
        /// <param name="IconPath">文件圖標(biāo)</param> 
        /// <param name="AppPath">啟動(dòng)程序</param> 
        public static void SetLink(string ExName, string TypeName, string IconPath, string AppPath) 
        { 
            try 
            { 
                RegistryKey root = Registry.ClassesRoot;//root key 
 
                //change extendname link 
                root.CreateSubKey(ExName); 
                root.DeleteSubKeyTree(ExName); 
                root.CreateSubKey(ExName); 
 
                RegistryKey ExKey = root.OpenSubKey(ExName, true); 
                ExKey.SetValue("", TypeName); 
                ExKey.SetValue("Content Type", TypeName);//add value 
 
                //create new filetype 
                root.CreateSubKey(TypeName); 
                root.DeleteSubKeyTree(TypeName); 
                root.CreateSubKey(TypeName); 
 
                RegistryKey TypeKey = root.OpenSubKey(TypeName, true); 
                TypeKey.SetValue("", TypeName); 
                TypeKey.CreateSubKey("DefaultIcon").SetValue("", IconPath);//new subkey icon 
                TypeKey.CreateSubKey("shell\\Open\\Command").SetValue("""\"" + AppPath + "\"" + "\"" + " %1" + "\"");//new subkey command 
                TypeKey.Close(); 
                root.Close(); 
                SHChangeNotify(0x80000000, IntPtr.Zero, IntPtr.Zero);//not need reboot 
            } 
            catch { } 
        } 
        /// <summary> 
        /// 解除關(guān)聯(lián)文件 
        /// </summary> 
        /// <param name="TypeName"></param> 
        public static void DelLink(string TypeName) 
        { 
            try 
            { 
                RegistryKey root = Registry.ClassesRoot; 
                root.DeleteSubKeyTree(TypeName);//delete type key 
                root.Close(); 
                SHChangeNotify(0x80000000, IntPtr.Zero, IntPtr.Zero);//not need reboot 
            } 
            catch { } 
        }  
        #endregion 
 
        #region 程序加入系統(tǒng)右鍵 
        /// <summary> 
        /// 程序關(guān)聯(lián)擴(kuò)展名文件右鍵菜單 
        /// </summary> 
        /// <param name="ExName">擴(kuò)展名文件</param> 
        /// <param name="MenuName">右鍵顯示名稱</param> 
        /// <param name="AppPath">程序</param> 
        public static void SetRightMenuLink(string MenuName, string AppPath) 
        { 
            try 
            { 
                RegistryKey shellKey = Registry.ClassesRoot.OpenSubKey("*\\shell"true); 
                shellKey.CreateSubKey(MenuName).CreateSubKey("command").SetValue("""\"" + AppPath + "\"" + "\"" + " %1" + "\""); 
                shellKey.Close(); 
            } 
            catch { } 
 
        } 
        /// <summary> 
        /// 解除程序關(guān)聯(lián)擴(kuò)展名文件右鍵菜單 
        /// </summary> 
        /// <param name="ExName">擴(kuò)展名文件</param> 
        public static void DeleteRightMenuLink(string MenuName) 
        { 
            try 
            { 
                RegistryKey fileshellKey = Registry.ClassesRoot.OpenSubKey("*\\shell"true); 
                fileshellKey.DeleteSubKeyTree(MenuName); 
                fileshellKey.Close(); 
            } 
            catch { } 
        }  
        #endregion 
 
        #region 跨進(jìn)程通信 
 
        public const int WM_COPYDATA = 0x004A
        [DllImport("User32.dll", EntryPoint = "SendMessage")] 
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, ref COPYDATASTRUCT lParam); 
 
        /// <summary> 
        /// 所需傳遞的結(jié)構(gòu)體 
        /// </summary> 
        public struct COPYDATASTRUCT 
        { 
            public IntPtr dwData;//用戶定義數(shù)據(jù) 
            public int cbData;//數(shù)據(jù)大小 
            [MarshalAs(UnmanagedType.LPStr)] 
            public string lpData;//指向數(shù)據(jù)的指針 
        } 
 
        /// <summary> 
        /// 發(fā)送字符串 
        /// </summary> 
        /// <param name="hWnd"></param> 
        /// <param name="str"></param> 
        public static void SendStr(IntPtr hWnd, string str) 
        { 
            try 
            { 
                byte[] sarr = System.Text.Encoding.Default.GetBytes(str); 
                int len = sarr.Length; 
                COPYDATASTRUCT cds; 
                cds.dwData = (IntPtr)100
                cds.lpData = str; 
                cds.cbData = len + 1
                SendMessage(hWnd, WM_COPYDATA, 0, ref cds); 
            } 
            catch { } 
        } 
 
        //#region 跨進(jìn)程通信 接收消息 
        ///// <summary> 
        ///// 重寫(xiě)接收函數(shù) 放到主窗體類中 
        ///// </summary> 
        ///// <param name="m"></param> 
        //protected override void DefWndProc(ref Message m) 
        //{ 
        //    if (m.Msg == LinkFile.WM_COPYDATA) 
        //    { 
        //        LinkFile.COPYDATASTRUCT mystr = new LinkFile.COPYDATASTRUCT(); 
        //        Type mytype = mystr.GetType(); 
        //        mystr = (LinkFile.COPYDATASTRUCT)m.GetLParam(mytype);//獲取類型 
        //        string str = mystr.lpData; 
        //        wmplayer1.URL = str; 
        //        listBox1.Items.Add(str); 
        //        listBox1.SelectedItems.Clear(); 
        //        listBox1.SetSelected(listBox1.Items.Count - 1, true); 
        //        labelFormTitle.Text = str; 
        //    } 
        //    base.DefWndProc(ref m); 
        //} 
        //#endregion 
        #endregion 
 
 
    } 

 
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
C#Winform開(kāi)發(fā),Listview根據(jù)文件路徑或擴(kuò)展名顯示系統(tǒng)文件圖標(biāo)
C# API 的一些用法,API控制另一個(gè)程序,API控制另一個(gè)窗體,觸發(fā)另一個(gè)窗體按鈕事件,設(shè)置文本
驅(qū)動(dòng)程序安裝類(C#)
[原創(chuàng)]C#應(yīng)用WindowsApi實(shí)現(xiàn)查找\枚舉(FindWindow、EnumChildWindows)窗體控件,并發(fā)送消息。
通達(dá)信客戶端程序化下單
C#調(diào)用DLL函數(shù)方法(下)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服