博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
文件类型及相关打开程序的注册
阅读量:4298 次
发布时间:2019-05-27

本文共 2191 字,大约阅读时间需要 7 分钟。

譬如:注册文件类型.pln,为其指定文件类型图标,并使用当前程序作为默认打开程序。

调用如下:
RegisterShellFileType(".pln","Plan.Documnet", "
规划文件", 1); 
其中参数的含义:
● filterExt
:文件后缀名 
● fileTypeID
:文件类型ID 
● fileTypeDesc
:文件描述 
● iconIndex
:文件图标在当前程序中的索引

 

BOOL CPlanningApp::RegisterShellFileType(CStringfilterExt, CString fileTypeID, CString fileTypeDesc, int iconIndex)

{

       CString strPathName, strTemp;

 

       TCHAR szLongPathName[_MAX_PATH];

       TCHAR szShortPathName[_MAX_PATH];

       ::GetModuleFileName(this->m_hInstance, szLongPathName, _MAX_PATH);

       if (::GetShortPathName(szLongPathName, szShortPathName, _MAX_PATH) == 0)

        {

               // rare failure case (especially on not-so-modern file systems)

               strPathName = szLongPathName;

        }

       else

        {

               strPathName = szShortPathName;

        }

 

       // first register the type ID of our server

       if (!SetClassesKey(fileTypeID, fileTypeDesc))

               return FALSE;       // just skipit

 

       // path\DefaultIcon = path,1

       strTemp.Format("%s\\DefaultIcon", (LPCTSTR)fileTypeID);

       CString strDefaultIcon;

       strDefaultIcon.Format("\"%s\",%d", strPathName,iconIndex);

       if (!SetClassesKey(strTemp, strDefaultIcon))

               return FALSE;       // just skip it

 

       // path\shell\open\command = path filename

       strTemp.Format("%s\\shell\\open\\%s", (LPCTSTR)fileTypeID,

               "command");

       CString strOpenCommand;

       strOpenCommand.Format("\"%s\" \"%%1\"",strPathName);

       if (!SetClassesKey(strTemp, strOpenCommand))

               return FALSE;       // just skipit

 

       // no association for that suffix

       if (!SetClassesKey(filterExt, fileTypeID))

               return FALSE;       // just skipit

 

        return TRUE;

}

 

BOOL CPlanningApp::SetClassesKey(LPCTSTRlpszKey, LPCTSTR lpszValue, LPCTSTR lpszValueName)

{

       if (lpszValueName == NULL)

        {

               if (::RegSetValue(HKEY_CLASSES_ROOT, lpszKey, REG_SZ,

                          lpszValue, lstrlen(lpszValue) *sizeof(TCHAR)) != ERROR_SUCCESS)

               {

                        TRACE1("Warning:registration database update failed for key '%s'.\n",

                                lpszKey);

                        return FALSE;

               }

               return TRUE;

        }

       else

        {

               HKEY hKey;

 

               if(::RegCreateKey(HKEY_CLASSES_ROOT, lpszKey, &hKey) ==ERROR_SUCCESS)

               {

                        LONG lResult = ::RegSetValueEx(hKey,lpszValueName, 0, REG_SZ,

                                (CONSTBYTE*)lpszValue, (lstrlen(lpszValue) + 1) * sizeof(TCHAR));

 

                        if(::RegCloseKey(hKey)== ERROR_SUCCESS && lResult == ERROR_SUCCESS)

                                return TRUE;

               }

               TRACE1("Warning: registration database update failed for key'%s'.\n", lpszKey);

               return FALSE;

        }

}

 

转载地址:http://fqnws.baihongyu.com/

你可能感兴趣的文章
量化策略回测DualThrust
查看>>
量化策略回测BoolC
查看>>
量化策略回测DCCV2
查看>>
mongodb查询优化
查看>>
五步git操作搞定Github中fork的项目与原作者同步
查看>>
git 删除远程分支
查看>>
删远端分支报错remote refs do not exist或git: refusing to delete the current branch解决方法
查看>>
python multiprocessing遇到Can’t pickle instancemethod问题
查看>>
APP真机测试及发布
查看>>
iOS学习之 plist文件的读写
查看>>
通知机制 (Notifications)
查看>>
10 Things You Need To Know About Cocoa Auto Layout
查看>>
C指针声明解读之左右法则
查看>>
一个异步网络请求的坑:关于NSURLConnection和NSRunLoopCommonModes
查看>>
iOS 如何放大按钮点击热区
查看>>
ios设备唯一标识获取策略
查看>>
获取推送通知的DeviceToken
查看>>
Could not find a storyboard named 'Main' in bundle NSBundle
查看>>
CocoaPods安装和使用教程
查看>>
Beginning Auto Layout Tutorial
查看>>