Windows Registry About Double Click File To Startup Application
2017-08-01 15:47
441 查看
Win Registry
Question
One day, my boss want me to finish one function which let the users can double click project file(*.opr) to startup application easy and quickly. oh, This function is very common, Just like double clicked the Microsoft Word Document(*doc,*docx), then, we can startup Micrsoft Word Application to edit frich text. Ok, let's do it.Win And Mac OS use the different way to associated file type.
Now the App only process one project at same time. if use the double click to open opr file. how to do when opend one project now?
Current App mode is single-one mode.
How
When we get the new task about program, First to think about it. What's i will finish? Did i do it before? How i should to do ? If you think nothing, There is better way to get the answer from internet for you.I think nothing. But, I know it is associate windows registry in Windows OS and List.Info file In Mac OS. So, I want to know how to finished it use the C++ or Qt. I also searched some documents about how to read/write registry with Qt. I was feel better that time. But when i tried all ways what them said, they are both failed. I spend half of the day, but not working. Their blogs not have the good introduction.
Now, I get the right answer from blogs of cnblogs.com. cnblogs.com is bester web site bout the programe than others.
Done
I used Qt frame to finished it. if you knowQSettingsclasses, it will be very easy, if not, please to see thw Qt help manual about the
QSettingsclass at first.
/** some include file */ #ifdef Q_OS_WIN #include <QSettings> #endif #ifdef Q_OS_WIN void checkWinRegistry() { QString val; QString exePath = qApp->applicationFilePath(); exePath.replace("/", "\\"); QSettings regType("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc", QSettings::NativeFormat); QSettings regIcon("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc\\DefaultIcon", QSettings::NativeFormat); QSettings regShell("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc\\Shell\\Open\\Command", QSettings::NativeFormat); /** . means default value, you can also use the "Default" string */ if("" != regType.value(".").toString()){ regType.setValue(".",""); } /** 0 使用当前程序内置图标 */ val = exePath + ",0"; if(val != regIcon.value(".").toString()){ regIcon.setValue(".",val); } val = exePath + " \"%1\""; if(val != regShell.value(".").toString()){ regShell.setValue(".",val); } } #endif int main(int argc, char *argv[]) { QApplication a(argc, argv); checkWinRegistry(); /** if you want to get the file path, please use argv[1], if argc >= 2 */ QString text; text = QString::number(argc); text += "\n"; for(int i=0; i<argc; i++){ text += QString(argv[i]);///< This way to get the QString may be is unreadable code. eg, include chinese language, we should use `QStringList ltArguments = a.arguments();` text += "\n"; } Widget w(text); w.show(); return a.exec(); }
Compared
if you don't clear about my way. Now, you could to see the following images about How to associate file type in QtCreater. we know that double *.pro file, we can startup QtCreater application to programing. How ?In Windows we can use
Ctrl+Rand input
regedit,
Enterto open the windows registry editer.
Let we find
HKEY_CURRENT_USER\SOFTWARE\Classes\.pro, you can see what keys and values under this item;
Then let we find
HKEY_CURRENT_USER\SOFTWARE\Classes\QtProject.QtCreator.pro, what keys and values under this item;
There are other file type of qt.
Compared and to finished your work by try and try.
Reference
相关文章推荐
- About UID and How to autostart an application on boot up in 3rd- Startup List Management API
- Error 1406. Setup cannot write the value DisableExceptionChainValidation to the registry key \SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File
- How to achieve the boot, clear cache, kill the process, floating windows single double-click to distinguish, with source
- How to add application to right click menu in Windows
- How to register a keyboard shortcut (hot key) in a .NET Windows Forms Application
- 'Application windows are expected to have a root view controller at the end of application launch'
- This application failed to start because it could not find or load the Qt platform plugin "windows"
- How to deploy a web application on Windows Azure
- How to configure windows machine to allow file sharing with dns alias (CNAME)
- How To Add Simple "Install WebPart" Menu to the Right Click On a CAB File
- MySql使用全记录5 -----解决Windows下用命令导入sql文件时"Failed to open file"的问题
- Use Registry to Open Application
- “Application windows are expected to have a root view controller at the end of application launch”
- Windows Streams - An Introduction to File System Streams
- System.IO.Directory.GetCurrentDirectory与System.Windows.Forms.Application.StartupPath用法浅谈
- QT5.0.1在Windows下 出现QApplication: No such file or directory 问题的解决办法
- This application is currently offline. To enable the application, remove the app_offline.htm file from the application
- windows编译ffmpeg出现gcc is unable to create an executable file 的一般情况
- Source Insight in Ubuntu+Windows+Samba:has been changed outside of the editor. Do you want to reload the file?
- How to install a Windows software file in Ubuntu