Open an MFC dialog based application using the Windows context menu Send To command

It has been a long time since school, and I am beating my head against the wall trying to figure out how to do this. I am writing an MFC program using Visual Studio 2008. I want to be able to right click on a file and send it to the program using the Windows Explorer Context menu Send To menu. Could be any type of file, but for now we can just say a text file. The send To command needs to open the program and process the file.

I remember that it will involve InitInstance and the GetCommandLine function, but I am drawing a blank here.
TheIronDukeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
You're abolutley right about 'InitInstance()' (https://msdn.microsoft.com/en-us/library/ae6yx0z0.aspx), the MSDN docs even have sample code how this works using 'CCommandLineInfo'. You're also right about 'GetCommandLine()' (https://msdn.microsoft.com/en-us/library/windows/desktop/ms683156(v=vs.85).aspx), which is a Windows API that returns the command line 'as is', i.e. you would have to parse it yourself, or use a utility class that does this for you like http://www.codeproject.com/Articles/1406/A-Command-Line-Class - which in your case can indeed be as simple as the sample snippet from that article:

BOOL CTestApp::InitInstance()
{
	CCommandLine pCmd;
	CString strFlag = _T("");
	CString strParam = _T("");

	BOOL bRet = pCmd.GetFirstParameter(strFlag, strParam);
	while(bRet)
	{
		DoSomethingWithTheParameter(strFlag, strParam);
		bRet = pCmd.GetNextParameter(strFlag, strParam);
	}
	.....
	.....
}

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.