CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: text files

  1. #1
    Guest

    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


  2. #2
    Join Date
    Apr 1999
    Posts
    22

    Re: text files

    You can try this:
    system("start notepad " + file);


  3. #3
    Join Date
    May 1999
    Posts
    28

    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]

  4. #4
    Join Date
    May 1999
    Posts
    12

    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


  5. #5
    Join Date
    May 1999
    Posts
    123

    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
  •  





Click Here to Expand Forum to Full Width

Featured