Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / wxWindows registry functions

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. wxWindows registry functions
#3413
Posted by: 2004-02-26 10:29:14
I know that when coding Win32 API, you can include "winreg.h" (I think thats what its called) and use the functions there to edit the registry.  Is there any way to edit the registry (and yes, I'm assuming that there is only one kind of registry, the MS Windows one =) ) from inside wxWindows.
If not, is there any other way anyone knows of to add file associations to your applications?


Any help will be greatly appreciated, thanks
Message2. Re: wxWindows registry functions
#3414
Posted by: 2004-02-26 12:50:33
Take a look at the wxConfigBase class in wxWindows API. More specifically, perhaps you should take a look at wxRegConfig (it's all explained in the wxConfigBase documentation).
However those classes are primarily intended for you to store your application configurations in the HKCU\\Software section of the registry, so I'm not quite sure if they are suitable for changing the file associations in windows registry.

I know you can read file associations with the wxMimeTypesManager and wxFileType classes. That is documented. What is not documented (at least in official docs) is the ability to change them. I think it's still in development, but works with wxWindows 2.4.2. I got most of this info by looking around in lists.wxwidgets.org and in the header file.

We need the (almost) not documented class:
wxFileTypeInfo(const wxChar *mimeType,
                   const wxChar *openCmd,
                   const wxChar *printCmd,
                   const wxChar *desc,
                   // the other parameters form a NULL terminated list of
                   // extensions
                   ...);

and the documented global variable:
wxMimeTypesManager *wxTheMimeTypesManager;

Here's an example:
#include <wx/mimetype.h>
....
   // Create file associations
   wxFileTypeInfo myinfo("application/myapp",
                         "myexec.exe",
                         "myexec.exe /print",
                         "My application document",
                         "my1", "my2", NULL);
   wxTheMimeTypesManager->Associate(myinfo);
....
   // Remove file associations
   // Both return NULL if not found (don't forget to handle that in your code!)
   wxFileType* ft_1 = wxTheMimeTypesManager->GetFileTypeFromExtension("my1");
   // This one seems to be relative to only the last extension, in this case, my2
   wxFileType* ft_2 = wxTheMimeTypesManager->GetFileTypeFromMimeType("application/myapp");

   wxTheMimeTypesManager->Unassociate(ft_1);
   wxTheMimeTypesManager->Unassociate(ft_2);
   delete ft_1, ft_2;  // Notice we are responsible for freeing the returned objects


This should also be a portable way for registering file extensions in other platforms besides windows, but I haven't tested that yet.
The big problem's that I don't know if this API will remain like this in the future, since you can't find this in the docs. Still, give it a try :)

Good luck!

Message3. Re: wxWindows registry functions
#3416
Posted by: upCASE 2004-02-26 15:06:11
Hi!
Check out the Wiki, too. I remember there was something about modifying the registry.
BTW: Don't rely on portability that much when it comes to things like Mimitypes. I experienced that you can savely use them with Mac, but they don't do what you wanted :) There are some things that seem to be not implemented.

upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message4. Re: wxWindows registry functions
#3425
Posted by: 2004-02-27 09:57:25
Whoa...  Thats a lot of info
It might take me awhile to wade through all that, but I think I got the basic idea, so I'll get started.  Thanks a lot for doin' that research Rodrigo, and thanks for the info about Wiki, and the portabilty issues.

Thanks
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Tue 2024-10-8  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0