right mouse button and c++ program

Hello!

I have small program which makes some chars from KBL to BRIM encoding system. It is simple. But I want to do sth like this: I have any KBL text file (.txt) and I click right button on it. AND THEN I FIND sth like 'KBL -> BRIM'.
I found a solution how to make functions in right click menu. But how can I make my script to get file's name?...

int main()
{
char KBL[18] = {220, 221, 222, 223, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253}; //KBL koduotes LTU simboliu kodai
char BRIM[18] = {192, 224, 200, 232, 198, 230, 203, 235, 193, 225, 208, 240, 216, 248, 219, 251, 222, 254}; //BLRIM atitinkami simboliu kodai

FILE *kbl;
FILE *brim;
char failas[99];
char A;
char *ptrA;
ptrA = &A;

cin >> failas;

if ((kbl = fopen(failas, "r")) == NULL)
cout << "Failas nerastas" << endl;
else
{
brim = fopen("brim.txt", "w");
while (!feof(kbl))
{
*ptrA = fgetc(kbl);
for (int i = 0; i < 18; i++)
if (*ptrA == (char) KBL[i])
*ptrA = (char) BRIM[i];
fputc(*ptrA, brim);
}
fclose(kbl);
fclose(brim);
}
}
Last edited on
Let me ask you this, when you need to dry your hair do you use a hammer? or a hairdryer?

It sounds like you are trying to add a right click menu entry to the mouse in Explorer, in which case you are approaching this problem from the wrong direction.

If you are trying to add a right click function for use inside of your program that's a different story and you are better off using the Windows API for that.

Please clarify what it is you want to accomplish.
I have a program and txt file. I press the right mouse button on that txt file and choose my program to decode txt file.

Other word this C++ code needs to enter file's name. I need this code's effect in the right click menu.
kbw is right for that particular method however to do literaly what you are describing in Windows XP you'd be adding an entry to HKCR\*\shellex\ContextMenuHandlers which is why I asked you to clarify. This has more to do with understanding how Windows works then how C++ does.

EDIT: You'll also need to add another under HKCR\CLSID
Last edited on
I already added an entry to HKEY_CLASSES_ROOT\txtfile\shell\KBLtoBRIM. The entry is: "C:\Users\....Visual Studio 2010\Projects\KBL to BRIM\Debug\KBL to BRIM.exe" %1
But sth is wrong... I do not know what code shoude I entry to my program which I copied in my first messagy. What is missing from my program?
I think you need to add entry to HKEY_CLASSES_ROOT\txtfile\shell\KBLtoBRIM\command\
I did it like I said. But I think that my program does not understand what file.txt does it need to open. I need some how to give a name of txt file to my program by pressing right button
Try this
1
2
3
4
5
6
7
int main(int argc, char 
*argv[])
{

cout <<argv[1]<<endl; // notice '%1' in your registry entry

}

should print the file name.
Thank you very much! This code shows full location of file. Thank you once again!
I have one more question.

I have another program (application). There is a button which opens this code:

1
2
3
4
5
6
7
int main(int argc, char 
*argv[])
{

cout <<argv[1]<<endl; // notice '%1' in your registry entry

}


I use system("blablabla.exe"). But how to notice %1 in system("...")? I need to give String path = "C:\Test"
Read this: http://www.cplusplus.com/forum/articles/13355/
1
2
3
string cmdline="blablabla.exe C:\\test";

system(cmdline.c_str());
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
	private: System::Void folderBrowserDialog1_HelpRequest(System::Object^  sender, System::EventArgs^  e) {
			 }
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
					//DialogResult resault = this.folderBrowserDialog1.ShowDialog();
					FolderBrowserDialog ^dlg=gcnew FolderBrowserDialog();
					
					if(dlg->ShowDialog() ==  System::Windows::Forms::DialogResult::OK)
					{
						String ^folderName=dlg->SelectedPath;
						label1->Text = dlg->SelectedPath;
						string path = " C:\\test";
						string file = "Untitled2.exe";
						string atidaro = file + path;
						system(atidaro.c_str());

					}
			 }
	};
}


This code works.

But this dont:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
	private: System::Void folderBrowserDialog1_HelpRequest(System::Object^  sender, System::EventArgs^  e) {
			 }
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
					//DialogResult resault = this.folderBrowserDialog1.ShowDialog();
					FolderBrowserDialog ^dlg=gcnew FolderBrowserDialog();
					
					if(dlg->ShowDialog() ==  System::Windows::Forms::DialogResult::OK)
					{
						String ^folderName=dlg->SelectedPath;
						label1->Text = dlg->SelectedPath;
						string path = dlg->SelectedPath;
						string file = "Untitled2.exe";
						string atidaro = file + path;
						system(atidaro.c_str());

					}
			 }
	};
}


I need do give dlg->SelectedPath (selected folder directory) to Untitled2.exe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
	private: System::Void folderBrowserDialog1_HelpRequest(System::Object^  sender, System::EventArgs^  e) {
			 }
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
					//DialogResult resault = this.folderBrowserDialog1.ShowDialog();
					FolderBrowserDialog ^dlg=gcnew FolderBrowserDialog();
					
					if(dlg->ShowDialog() ==  System::Windows::Forms::DialogResult::OK)
					{
						String ^folderName=dlg->SelectedPath;
						label1->Text = dlg->SelectedPath;
						String ^path = label1->Text;
						String ^file = "Untitled2.exe";
						String ^un = file+" "+ path;
						system(un.c_str());
					}
			 }
	};
}


Okey, un meaning is appropriate for me (e.g. "Untitled2.exe C:\Foler1\Folder2"). But it doesn't appropriate for system(....). Help me, please... :|
System::String doesn't have c_str() method.
I think this thread may help: http://stackoverflow.com/questions/2347665/c-cli-converting-systemstring-to-const-char

And when you'll get that part of code working, read why you should not system(): http://www.cplusplus.com/forum/articles/11153/
Topic archived. No new replies allowed.