Page 1 of 1

Help with mfc

Posted: Thu Mar 18, 2004 6:48 am
by Anonymous
hi
I have two mfc applications.i want to execute the 2nd mfc application by clicking on any button on the toolbar in the first mfc application.

thanks in advance
archana

Archived topic from Iceteks, old topic ID:2154, old post ID:18315

Help with mfc

Posted: Thu Mar 18, 2004 12:22 pm
by Red Squirrel
Welcome to the forum!

I have not programmed mfc in long, but I think you can still use the win32 winexec(); function. I think for mfc you need to put ::winexec() or something, I forget how it works.

Archived topic from Iceteks, old topic ID:2154, old post ID:18316

Help with mfc

Posted: Wed Mar 31, 2004 10:48 pm
by Fat Cat
Can you use the "ShellExecute" command ?
I use this to call up IE and link to a web page from clicking a button on a Dialog Box in an MFC application. If your second application is an executable (.exe) it should work.


add your button/menu item and then double click on it in the C++ editior to jump to the place to enter the source code to run when the item is selected.

Below is an example of the code I use (but of course mywebsite.com isn't a real site)

void CAboutDlg::OnWebLinkMine()
{
ShellExecute(0, "open", "http://www.mywebsite.com", NULL, NULL, SW_SHOWNORMAL);
}

Archived topic from Iceteks, old topic ID:2154, old post ID:18637

Help with mfc

Posted: Wed Mar 31, 2004 10:53 pm
by Red Squirrel
Forgot about that one. That's usefull because you can use the command of choice, so if you have a file type that has an open option but also an edit option, you can specify which one to use.

Archived topic from Iceteks, old topic ID:2154, old post ID:18638

Help with mfc

Posted: Thu Apr 01, 2004 1:43 am
by Fat Cat
ShellExecute works by opening the filename specified with whatever program is associated with that file type in your registry. If you specify a filename with a .xls extension for eaxmple, it will check the registry and find the application Excel listed under ther shell subkey and then go and open the file with Excel.

To execute an application (.exe file) that doesn't have a filetype associated with it needs a bit of cheating. It can be done by creating a simple text file, saving it with a unique file extension and then associating that extension with your mfc application (ie: right click on the file and use the Open With option and choose the always open these types of files with .... your mfc application).

Now back in your source code, you just enter the filename of the file you just associated with your mfc app. It will now launch your mfc app when clicked on and try to open the file. It doesn'tatter that the file can't be opened by the app, the app will still be left running.

I'f I discover the correct way to link to executables, I'll post it

Archived topic from Iceteks, old topic ID:2154, old post ID:18640