Click to See Complete Forum and Search --> : Opening file


Rojer
September 10th, 1999, 04:16 PM
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

Vasko
September 10th, 1999, 07:01 PM
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" ...

Sameer Pise
September 12th, 1999, 08:46 AM
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