Help!
I want to do the following in Visual C++ Dev studio:
When the user presses a button on a dialog, Microsoft Notepad opens, automaticaly loading a predefined text file.
Yikes! Any ideas??
Thanks
Stu
Printable View
Help!
I want to do the following in Visual C++ Dev studio:
When the user presses a button on a dialog, Microsoft Notepad opens, automaticaly loading a predefined text file.
Yikes! Any ideas??
Thanks
Stu
You can try this:
system("start notepad " + file);
Look at the ShellExecute function. Here is an example from an app we wrote that opens a Windows calculator process. It even checks to see if the application exists and brings it to the front if it does. You may be able to use that for notepad.
void CMainFrame::OnSpecialCalculator()
{
// See if we can find an existing calculator window
HWND hwndCalc = ::FindWindow(_T("SciCalc"), _T("Calculator"));
if (hwndCalc == NULL)
{
// We couldn't. Let's launch it.
ShellExecute(NULL,"open","calc.exe",NULL,NULL,SW_SHOWNORMAL);
}
else
{
// We found it. Let's move it to the top and make sure it's visible.
::SetWindowPos(hwndCalc, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
::ShowWindow(hwndCalc,SW_SHOWNORMAL);
}
}
This is called from a Toolbar/Menu Item/Accelerator event handler.
Chris R. Wheeler, MCP
Pensacola Christian College
Desktop Programmer
[email protected]
WinExec("notepad.exe mytextfile.txt", SW_SHOWNORMAL);
or WinExec("notepad.exe c:\sss\mytextfile.tt", SW_SHOWNORMAL); if the text file isnt located in a pre-defined search directory
If you insist on doing this, you can use WinExec to do it. I'd _strongly_ advise against doing it at all though -- it's a _terrible_ thing to do.
If you insist on spawning a separate program for this purpose, at least use ShellExecute to spawn whatever program the user has associated with the type of file involved -- the user may prefer to use (for example) MS Word to look at text files; I don't have notepad installed on my computer at all.
Better yet, since notepad is simply a thin bit of a wrapper around an edit control anyway, you're _far_ better off just creating a view (or even just a dialog) containing an edit control, and being done with it -- this usually ends up easier than spawning a copy of the external program anyway.
The universe is a figment of its own imagination.