文件类型及相关打开程序的注册

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

调用如下:
RegisterShellFileType(".pln", "Plan.Documnet", "规划文件", 1); 

其中参数的含义:

● filterExt:文件后缀名 
● fileTypeID:文件类型ID 
● fileTypeDesc:文件描述 
● iconIndex:文件图标在当前程序中的索引

 

 

BOOL CPlanningApp::RegisterShellFileType(CString filterExt, 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 skip it

 

        // 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 skip it

 

        // no association for that suffix

        if (!SetClassesKey(filterExt, fileTypeID))

                return FALSE;       // just skip it

 

        return TRUE;

}

 

BOOL CPlanningApp::SetClassesKey(LPCTSTR lpszKey, 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,

                                (CONST BYTE*)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;

        }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Pycharm提供了多种打开文件的方式,包括使用快捷键、菜单操作和搜索等方法。首先,可以使用快捷键来打开最近更新的文件,可以按下Ctrl+Shift+E,然后从弹出的"Recently Edited Files"窗口中选择需要打开的文件。另外,可以在主菜单上选择View | Recently Changed Files来打开最近更新的文件。此外,还可以在单独的PyCharm窗口中打开文件,这样可以将文件以独立的方式打开并进行编辑。最后,如果文件类型已经注册,文件将在PyCharm的编辑器中打开。如果文件类型未知,PyCharm会提示您选择是注册新的文件类型还是在关联的应用程序打开此类文件。所以,通过Pycharm,可以便捷地打开文件并进行编辑。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Pycharm打开文件的多种方式](https://blog.csdn.net/update7/article/details/129722724)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [PyCharm入门教程——在编辑器中打开和重新打开文件](https://blog.csdn.net/weixin_33843947/article/details/92425105)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值