Click here to Skip to main content
15,913,027 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: equivalent vc++ class for a vb class Pin
Ozer Karaagac3-May-08 12:25
professionalOzer Karaagac3-May-08 12:25 
GeneralRe: equivalent vc++ class for a vb class Pin
lahom3-May-08 12:49
lahom3-May-08 12:49 
GeneralRe: equivalent vc++ class for a vb class Pin
Ozer Karaagac3-May-08 13:35
professionalOzer Karaagac3-May-08 13:35 
GeneralRe: equivalent vc++ class for a vb class Pin
lahom3-May-08 14:13
lahom3-May-08 14:13 
GeneralRe: equivalent vc++ class for a vb class Pin
Ozer Karaagac3-May-08 14:49
professionalOzer Karaagac3-May-08 14:49 
GeneralRe: equivalent vc++ class for a vb class Pin
lahom4-May-08 3:25
lahom4-May-08 3:25 
QuestionRe: equivalent vc++ class for a vb class Pin
Ozer Karaagac4-May-08 13:05
professionalOzer Karaagac4-May-08 13:05 
AnswerRe: equivalent vc++ class for a vb class Pin
lahom4-May-08 13:28
lahom4-May-08 13:28 
ok this is the associate file function:
CComVariant Associate_File(CString Extension, CString Application, CString &Identifier, CString Description, CString Icon)<br />
{<br />
	CComVariant Associate_File;<br />
<br />
	 LONG lRtn; // Returned Value From API Registry Call<br />
	 HKEY hKey = NULL;  // Handle Of Open Key<br />
	 int lValue; // Setting A Long Data Value<br />
	 CString sValue; // Setting A String Data Value<br />
	 int lsize; // Size Of String Data To Set<br />
	 CString commandline;<br />
     DWORD  dwDisp;<br />
     //const unsigned char* Identifier;<br />
	// Create The New Registry Key, the file extension<br />
	lRtn = RegCreateKeyEx(HKEY_CLASSES_ROOT, Extension, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &hKey, &dwDisp);<br />
<br />
	// Check For An Error.<br />
	if (lRtn!=ERROR_SUCCESS) {<br />
		AfxMessageBox(CreateErr);<br />
	}<br />
<br />
	lsize = Identifier.GetLength(); // Get Size Of identifier String<br />
	// Set "(Default)" String Value to identifier<br />
	lRtn = RegSetValueExA(hKey, "", 0, REG_SZ, (const unsigned char*)&Identifier, lsize);<br />
	// Check For An Error.<br />
	if (lRtn!=ERROR_SUCCESS) {<br />
		AfxMessageBox("Error Setting String Value!");<br />
		RegCloseKey((hKey));<br />
		return Associate_File;<br />
	}<br />
<br />
	// Close The Registry Key.<br />
	RegCloseKey((hKey));<br />
<br />
	// Create The New Registry Key, the file extension identifier<br />
	lRtn = RegCreateKeyEx(HKEY_CLASSES_ROOT, Identifier, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &hKey, &dwDisp);<br />
<br />
	// Check For An Error.<br />
	if (lRtn!=ERROR_SUCCESS) {<br />
		AfxMessageBox(CreateErr);<br />
	}<br />
<br />
	lsize = Description.GetLength(); // Get Size Of file type description String<br />
	// Set (Default) String Value to description of the file type<br />
	lRtn = RegSetValueExA(hKey, "", 0, REG_SZ, (const unsigned char*)&Description, lsize);<br />
	// Check For An Error.<br />
	if (lRtn!=ERROR_SUCCESS) {<br />
		AfxMessageBox("Error Setting String Value!");<br />
		RegCloseKey((hKey));<br />
		return Associate_File;<br />
	}<br />
<br />
	// Close The Registry Key.<br />
	RegCloseKey((hKey));<br />
<br />
<br />
	// Create The New Registry Key, the default icon key within the identifier key<br />
	lRtn = RegCreateKeyEx(HKEY_CLASSES_ROOT, (Identifier+"\\DefaultIcon"), 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &hKey, &dwDisp);<br />
<br />
	// Check For An Error.<br />
	if (lRtn!=ERROR_SUCCESS) {<br />
		AfxMessageBox(CreateErr);<br />
	}<br />
<br />
	lsize = Icon.GetLength(); // Get Size Of String<br />
	// Set (Default) String Value to the full path name of the icon that will be associated with<br />
	// this file type<br />
<br />
	lRtn = RegSetValueExA(hKey, "", 0, REG_SZ, (const unsigned char*)&Icon, lsize);<br />
	// Check For An Error.<br />
	if (lRtn!=ERROR_SUCCESS) {<br />
		AfxMessageBox("Error Setting String Value!");<br />
		RegCloseKey((hKey));<br />
		return Associate_File;<br />
	}<br />
<br />
	// Close The Registry Key.<br />
	RegCloseKey((hKey));<br />
<br />
<br />
<br />
	Identifier += "\\shell";<br />
	// Create The New Registry Key, the "shell" key within the identifier key<br />
<br />
	lRtn = RegCreateKeyEx(HKEY_CLASSES_ROOT, Identifier, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &hKey, &dwDisp);<br />
<br />
	// Check For An Error.<br />
	if (lRtn!=ERROR_SUCCESS) {<br />
		AfxMessageBox(CreateErr);<br />
	}<br />
<br />
	// Close The Registry Key.<br />
	RegCloseKey((hKey));<br />
<br />
<br />
	Identifier += "\\open";<br />
	// Create The New Registry Key, the "open" command key within the shell key<br />
<br />
	lRtn = RegCreateKeyEx(HKEY_CLASSES_ROOT, Identifier, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &hKey, &dwDisp);<br />
<br />
	// Check For An Error.<br />
	if (lRtn!=ERROR_SUCCESS) {<br />
		AfxMessageBox(CreateErr);<br />
	}<br />
<br />
	// Close The Registry Key.<br />
	RegCloseKey((hKey));<br />
<br />
<br />
	Identifier += "\\command";<br />
	// Create The New Registry Key, the "command"  key within the "open" command key<br />
<br />
	lRtn = RegCreateKeyEx(HKEY_CLASSES_ROOT, Identifier, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &hKey, &dwDisp);<br />
<br />
	// Check For An Error.<br />
	if (lRtn!=ERROR_SUCCESS) {<br />
		AfxMessageBox(CreateErr);<br />
	}<br />
<br />
	commandline = (Str(CString(char(34)))+Application+Str(CString(char(34)))+" "+Str(CString(char(34)))+"%1"+Str(CString(char(34))));<br />
	lsize = commandline.GetLength(); // Get Size Of String<br />
	// Set (Default) String Value of the "command" key to the command line to be used to open the file<br />
	lRtn = RegSetValueExA(hKey, "", 0, REG_SZ, (const unsigned char*)&commandline, lsize);<br />
	// Check For An Error.<br />
	if (lRtn!=ERROR_SUCCESS) {<br />
		AfxMessageBox("Error Setting String Value!");<br />
		RegCloseKey((hKey));<br />
		return Associate_File;<br />
	}<br />
<br />
	// Close The Registry Key.<br />
	RegCloseKey((hKey));<br />
	return Associate_File;<br />
}


this is the button event:
void CForm1::OnCommand1()<br />
{<br />
	// TODO: Add your control notification handler code here<br />
	CComVariant retval;	// - "AutoDim"<br />
        CString exten="ccc_ext";<br />
	CString app_path;<br />
	CString Icon;<br />
	char buffer2[2048];<br />
	HANDLE hProcess = GetCurrentProcess();<br />
    char buffer1[2048];<br />
    DWORD r1 = GetModuleBaseName(hProcess, NULL, buffer1, 2048); <br />
    app_path=GetModuleFileName(NULL, buffer2, 2048)+"\\"+r1;<br />
    Icon=r1+"\\book.ico" ;<br />
    retval = Associate_File(".ccc", app_path,exten,"My own extension",Icon);<br />
   AfxMessageBox(("Associated the file extension .ccc with this application!"));<br />
<br />
}

maybe there is something wrong with the type conversion....right
i think iam using UNICODE

thank u
AnswerRe: equivalent vc++ class for a vb class Pin
Ozer Karaagac4-May-08 15:05
professionalOzer Karaagac4-May-08 15:05 
GeneralRe: equivalent vc++ class for a vb class Pin
lahom4-May-08 15:28
lahom4-May-08 15:28 
GeneralRe: equivalent vc++ class for a vb class Pin
Ozer Karaagac4-May-08 15:36
professionalOzer Karaagac4-May-08 15:36 
GeneralRe: equivalent vc++ class for a vb class Pin
Ozer Karaagac3-May-08 15:47
professionalOzer Karaagac3-May-08 15:47 
GeneralRe: equivalent vc++ class for a vb class Pin
Hamid_RT29-Apr-08 1:23
Hamid_RT29-Apr-08 1:23 
GeneralDebug Assertion Failed! help :( Pin
DADADADAD26-Apr-08 11:49
DADADADAD26-Apr-08 11:49 
GeneralRe: Debug Assertion Failed! help :( Pin
Saurabh.Garg26-Apr-08 15:29
Saurabh.Garg26-Apr-08 15:29 
GeneralRe: Debug Assertion Failed! help :( Pin
DADADADAD28-Apr-08 8:51
DADADADAD28-Apr-08 8:51 
QuestionAny tool to make a patch which can decide which application to patch? Pin
followait26-Apr-08 8:59
followait26-Apr-08 8:59 
AnswerRe: Any tool to make a patch which can decide which application to patch? Pin
Saurabh.Garg26-Apr-08 18:00
Saurabh.Garg26-Apr-08 18:00 
AnswerRe: Any tool to make a patch which can decide which application to patch? Pin
Hamid_RT29-Apr-08 1:23
Hamid_RT29-Apr-08 1:23 
Questionwhich c++ stl is right? Pin
Jim Crafton26-Apr-08 6:52
Jim Crafton26-Apr-08 6:52 
AnswerRe: which c++ stl is right? Pin
Saurabh.Garg26-Apr-08 7:37
Saurabh.Garg26-Apr-08 7:37 
GeneralRe: which c++ stl is right? Pin
Jim Crafton26-Apr-08 7:55
Jim Crafton26-Apr-08 7:55 
GeneralRe: which c++ stl is right? Pin
Saurabh.Garg26-Apr-08 9:52
Saurabh.Garg26-Apr-08 9:52 
GeneralRe: which c++ stl is right? Pin
peterchen27-Apr-08 0:47
peterchen27-Apr-08 0:47 
Generalbest book or refernce for Visual c++ Pin
mostafa_h26-Apr-08 6:25
mostafa_h26-Apr-08 6:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.