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

TheIronDuke
TheIronDuke used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2012
Commented:
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial