Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to use mspaint.exe in my application ?

Status
Not open for further replies.

Johnweida

MIS
Apr 29, 2003
91
CN
hello,

Is there a way to call mspaint.exe in VFP application ?

John Satellite
 
What do you mean by "call mspaint.exe in VFP application "? If you are just trying to run it then you could use the RUN command or an API call to ShellExecute, but if you mean automate it in some fashion then please post back and explain what you are trying to do in a little more detail. Thanks.

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Either:

!/n mspaint

or

o = NEWOBJECT("_shellexecute",HOME()+"ffc\_environ.vcx")
o.ShellExecute("Mspaint")
RELEASE o


I prefer the second method since an instance handle is
returned that can be used for further processing in VFP.

You can also open an existing file with both methods.

Darrell




'We all must do the hard bits so when we get bit we know where to bite' :)
 
Here's the code from _shellexecute modified and tersely explained:

[tt]
CLEAR

* Open the document with mspaint
ShellExecuteVFP("MsPaint","1000.jpg","C:\Documents and Settings\default user\My Documents\My Pictures\","open")

* Open the document with its default application
ShellExecuteVFP("C:\Documents and Settings\default user\My Documents\My Pictures\1000.jpg",,,)

* Open windows explorer
ShellExecuteVFP("c:\\Program Files",,,"open")

* Open the windows search dialog
ShellExecuteVFP("c:\\Program Files",,,"find")

CLEAR DLLS

FUNCTION ShellExecuteVFP(lcFileName, lcParams, lcWorkDir, lcOperation)

* WinApi :: ShellExecute
** Function: Opens a file in the application that it's
** associated with.
** Pass: lcFileName - Name of the file to open or an executable
** lcParams - If lcFileName is an executable, lcParams
** is/are the parameters to the executable
** lcWorkDir - The default directory to use
** lcOperation - The operation/verb to perform on lcFileName
** edit - Launches an editor and opens the document for editing.
** find - Initiates a search starting from the specified directory.
** open - Launches an application. If this file is not an executable file,
** its associated application is launched.
** print - Prints the document file.
** properties - !Displays the file or folder's properties!
** Included here for completeness, you won't be able to
** use this verb in VFP

**
** Return: 2 - Bad Association (e.g., invalid URL)
** 31 - No application association
** 29 - Failure to load application
** 30 - Application is busy
**
** Values over 32 indicate success
** and return an instance handle for
** the application started
LOCAL lcWorkDir,lcOperation

IF EMPTY(lcFileName)
RETURN -1
ENDIF

lcFileName=ALLTRIM(lcFileName)

lcParams = IIF(TYPE("lcParams")=="C",ALLT(lcParams)+CHR(0),"")

lcWorkDir=IIF(TYPE("lcWorkDir")="C",ALLTRIM(lcWorkDir)+CHR(0),"")

lcOperation=IIF(TYPE("lcOperation")="C" .AND. ;
!EMPTY(lcOperation),ALLTRIM(lcOperation),"Open")

*-* HINSTANCE ShellExecute(hwnd, lpszOp, lpszFile, lpszParams, lpszDir, wShowCmd)
*-*
*-* HWND hwnd - handle of parent window
*-* LPCTSTR lpszOp - address of string for operation to perform
*-* LPCTSTR lpszFile - address of string for filename
*-* LPTSTR lpszParams - address of string for executable-file parameters
*-* LPCTSTR lpszDir - address of string for default directory
*-* INT wShowCmd - whether file is shown when opened
DECLARE INTEGER ShellExecute ;
IN SHELL32.DLL ;
INTEGER nWinHandle,;
STRING cOperation,;
STRING cFileName,;
STRING cParameters,;
STRING cDirectory,;
INTEGER nShowWindow
RETURN ShellExecute(0,lcOperation,lcFilename,lcParams,lcWorkDir,1)
ENDFUNC

[/tt]

'We all must do the hard bits so when we get bit we know where to bite' :)
 
Hello,darrellblackhawk,

I've run your API code and it works well. But can I get all the programmes installed in my computer available for open and edit the file I specified ? for example, I want to edit a bitmap file. In which way can I get the list of the available programmes installed in my computer ? So I can choose one to do it. I think maybe API can do it, right ? Thanks.

John Satellite
 
Johnweida

If you want mspaint.exe to open a .bmp through a ShellExecute() WinAPI call, you need to ensure that .bmp files are associated with mspaint.exe.

That is a Windows issue - ShellExecute() will always open and print a file with the windows associated application.

Some graphics applications require user intervention before printing and some will print size for size as opposed to an isometric image which would match the paper size selected.

There are freeware graphics applications such as IrfanView which offer far more scope than mspaint.exe.

IrfanView, for example, will allow you select which image file type to associated with it, and saves the hassle of doing through the Windows interface.

FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
John,

You can look at faq184-3839 to see how to associate a certain program with the .BMP extension...

However, I think you're asking how you can get windows to bring up all the programs on your system that are capable of working with BMP files...and that I am sorry to say I don't know how to do. Windows must have a way of figuring out some of the apps that can work with a certain file since it will sometimes give me a short list when I right-click on a file and go to "open with".

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top