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

Thread: Opening file

  1. #1
    Join Date
    Aug 1999
    Posts
    25

    Opening file

    Hi
    I am having a Open file optionin my application menu where from I need to open up some jpg files in the corr default editor. So how can I open up the default editor (say MSPaint) with the jpg file displayed.
    I am using like this
    void CMainFrame::OnFileDisp()
    {
    CSpecialFileDialog dlgFile(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
    "JPG files (*.jpg)|*.jpg; *.jpg||");
    dlgFile.m_ofn.lpstrTitle = "Open Image";
    if(dlgFile.DoModal() != IDOK)
    return ;
    CString strFilePath = dlgFile.GetPathName();
    }

    Now once I have the FilePath shall I use the WinExec command to open it and if so how. Do let me know
    Thanks



  2. #2
    Join Date
    Apr 1999
    Location
    Sofia, Bulgaria
    Posts
    57

    Re: Opening file

    you can use ShellExecute or ShellExecuteEx
    one of its parameters is verb. It is important what verb you specify - do not believe the documentation that NULL = "open" it is not. for example NULL opens mp3 (with winamp) "open" does not.
    ShellExecute with NULL opens jpeg file in Internet Explorer on my computer - i guess you should find better verb (all verbs are located in registry HKEY_CLASSES_ROOT)
    try with "edit" ...


  3. #3
    Join Date
    Jul 1999
    Location
    B'lore India
    Posts
    9

    Re: Opening file

    Hi
    The WinExec function is provided only for compatibility with 16-bit Windows.
    Win32-based applications should use the CreateProcess function.

    UINT WinExec(
    LPCSTR lpCmdLine, // address of command line
    UINT uCmdShow // window style for new application
    );


    lpCmdLine points to the string that contains the command line i.e file name plus optional parameters.
    for u r application : <path>\MSPaint.exe <filename>
    if the path is not given then the system searches in the following order
    1.The Windows directory.
    2. Current Directory
    3.The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.
    4. The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.
    5.The directories listed in the PATH environment variable.

    uCmdShow : Specifies how a Windows-based application window is to be shown and is used to supply the wShowWindow member of the STARTUPINFO parameter to the CreateProcess function
    See ShowWindow -

    Sam




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