473,653 Members | 3,000 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem associating file types, that doesn't exist already, with my app

Hi
I'm having trouble associating file types with my app. Associating a
file type works as long as the file type is already associated with
another program but if the file type doesn't exist already, it isn't
associated. So my question is: how do I associate a file type that
isn't registered already? How can I register this new file type if
that's what I'll have to do before associating it.
I'm programming in Win32 using the Dev-Cpp compiler. Here's the code I
currently use to associate file types:

void associatefile (string filetype)
{
HKEY hKey;
string exepath=AppPath ;
string key = "LibertyExpress ";
string keyval = "LibertyExpress ";

int reg = RegCreateKey( HKEY_CLASSES_RO OT, key.c_str(),&hK ey);
if (reg == ERROR_SUCCESS) {reg=RegSetValu e(hKey, "", REG_SZ,
keyval.c_str(), 0);}
else {return;}

if(reg == ERROR_SUCCESS)
{
key=filetype;
keyval="Liberty Express";
reg=RegCreateKe y(HKEY_CLASSES_ ROOT, key.c_str(),
&hKey);
if(reg == ERROR_SUCCESS)
{
reg=RegSetValue (hKey, "", REG_SZ,
keyval.c_str(), 0);
if(reg == ERROR_SUCCESS)
{
key="LibertyExp ress";
keyval=exepath+ " %1";
reg=RegCreateKe y(HKEY_CLASSES_ ROOT,
key.c_str(), &hKey);
if(reg == ERROR_SUCCESS)
{reg=RegSetValu e(hKey, "shell\\open\\c ommand", REG_SZ, keyval.c_str(),
MAX_PATH);}
}
}
}
}

Feb 18 '07 #1
1 1722
as***********@y ahoo.com wrote:
Hi
I'm having trouble associating file types with my app. Associating a
file type works as long as the file type is already associated with
another program but if the file type doesn't exist already, it isn't
associated. So my question is: how do I associate a file type that
isn't registered already? How can I register this new file type if
that's what I'll have to do before associating it.
I'm programming in Win32 using the Dev-Cpp compiler. Here's the code I
currently use to associate file types:

void associatefile (string filetype)
{
HKEY hKey;
string exepath=AppPath ;
string key = "LibertyExpress ";
string keyval = "LibertyExpress ";

int reg = RegCreateKey( HKEY_CLASSES_RO OT, key.c_str(),&hK ey);
if (reg == ERROR_SUCCESS) {reg=RegSetValu e(hKey, "", REG_SZ,
keyval.c_str(), 0);}
else {return;}

if(reg == ERROR_SUCCESS)
{
key=filetype;
keyval="Liberty Express";
reg=RegCreateKe y(HKEY_CLASSES_ ROOT, key.c_str(),
&hKey);
if(reg == ERROR_SUCCESS)
{
reg=RegSetValue (hKey, "", REG_SZ,
keyval.c_str(), 0);
if(reg == ERROR_SUCCESS)
{
key="LibertyExp ress";
keyval=exepath+ " %1";
reg=RegCreateKe y(HKEY_CLASSES_ ROOT,
key.c_str(), &hKey);
if(reg == ERROR_SUCCESS)
{reg=RegSetValu e(hKey, "shell\\open\\c ommand", REG_SZ, keyval.c_str(),
MAX_PATH);}
}
}
}
}
This is Windows API specific code; not C++ related.
Try a Microsoft Windows news group.

Feb 19 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7298
by: Michael J Whitmore | last post by:
I am getting tired of losing hair over this. Here is a function that simply inserts one of three images into a document right before printing. It is called for every element that has a specific id in the document with the onbeforeprint window call. The chosen image will then be inserted into the document as a child element of ‘fig'. The problem is the images decide on their own whether or not to show up to the party. Random images...
1
20691
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function init() {
0
1085
by: zerodot | last post by:
string keyName; string keyValue; keyName = "MyApp"; keyValue = "My App"; RegistryKey key,subkey; key = Registry.ClassesRoot.CreateSubKey(keyName); key.SetValue("",keyValue); subkey = key.CreateSubKey("shell");
2
4442
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c */ #include <time.h>
6
2340
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any solution. My code can be downloaded from here: http://www.tprimke.net/konto/PyObject-problem.tar.bz2. There are some scripts for GNU/Linux system (bash to be precise). All you need to know is that there are four classes. (Of course, you may...
39
19617
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1) What's the difference between these 3 statements: (i) memcpy(&b, &KoefD, n); // this works somewhere in my code
159
6219
by: Bob Timpkinson | last post by:
Hi, I have a 32-bit machine... Is there anyway I can get gcc to use the following integer sizes? char: 8 bits short: 16 bits int: 32 bits long: 64 bits long long: 128 bits
12
3370
by: K. | last post by:
Hello! I have a problem with SWFupload class1. I have the page with uses SWFUpload class. Everything worked fine until (I suppose my admin) implemented some changes into the server. Now uploading file doesn`t work 2. I select one small file which is uploading 3. I get the status "Complete", but file is not being uploaded, because it doesn`t exist on my server. On the beginning of the upload.php file I`ve added easy insert query into the...
0
8283
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8704
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.