|
-
April 20th, 1999, 07:46 AM
#1
text files
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
-
April 20th, 1999, 02:17 PM
#2
Re: text files
You can try this:
system("start notepad " + file);
-
April 20th, 1999, 03:07 PM
#3
Re: text files
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]
-
May 18th, 1999, 10:52 AM
#4
Re: text files
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
-
May 25th, 1999, 04:32 PM
#5
Re: text files
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|