Re: Sending a picture to a paint program?
From: Mike D Sutton (EDais_at_mvps.org)
Date: 12/02/04
- Next message: Ken Halter: "Re: Sending a picture to a paint program?"
- Previous message: John Walker: "VB6 Directory\File Maintenance"
- In reply to: Webbee: "Sending a picture to a paint program?"
- Next in thread: Ken Halter: "Re: Sending a picture to a paint program?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 2 Dec 2004 19:19:52 -0000
> I'm using the MshflexGrid and want to send a picture of the grid to the
> program that is setup to open picture files. So when I click a button I would
> like to be able to send the picture to MSPaint. Now if the user has some
> other app setup to view bmp's then that app should open.
You'd need to write the image file out to a .BMP file, then call ShellExecute() on this file:
'***
Private Declare Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" ( _
ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_NORMAL As Long = &H1
...
Call SavePicture(Picture1.Picture, FileName) ' Use your own picture here rather than Picture1.Picture
Call ShellExecute(Me.hWnd, "open", FileName, vbNullString, vbNullString, SW_NORMAL)
'***
Of course you need a file name to write this to, so here's a method that will generate you a temporary unique file name:
'***
Private Declare Function GetTempPath Lib "Kernel32.dll" Alias "GetTempPathA" ( _
ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetTempFileName Lib "Kernel32.dll" Alias "GetTempFileNameA" ( _
ByVal lpszPath As String, ByVal lpPrefixString As String, _
ByVal wUnique As Long, ByVal lpTempFileName As String) As Long
Private Const MAX_PATH As Long = 260
...
Public Function GetTemporaryFilePath() As String
Dim BufLen As Long
BufLen = GetTempPath(0, vbNullString)
If (BufLen) Then
GetTemporaryFilePath = Space$(BufLen)
Call GetTempPath(BufLen, GetTemporaryFilePath)
End If
End Function
Public Function GetTemporaryFileName( _
Optional ByRef inPath As String = "", _
Optional ByRef inPrefix As String = "") As String
Dim UsePath As String
Dim RetPath As String
Dim NullPos As Long
RetPath = Space$(MAX_PATH)
If (Len(inPath)) Then UsePath = inPath Else UsePath = GetTemporaryFilePath()
If (GetTempFileName(UsePath, inPrefix, 0&, RetPath) <> 0) Then
NullPos = InStr(1, RetPath, vbNullChar)
If (NullPos) Then _
GetTemporaryFileName = Left$(RetPath, NullPos - 1) Else _
GetTemporaryFileName = RetPath
End If
End Function
'***
Just call GetTemporaryFileName() to get the file name.
Your other option to get the picture into the other application is to use the clipboard, you can copy the picture to the clipboard
buffer using this:
'***
Call Clipboard.SetData(Picture1.Picture, vbCFDIB)
'***
If for some reason this does not work then here's the API method:
http://groups.google.co.uk/groups?selm=%23tanKWrqDHA.2488%40TK2MSFTNGP09.phx.gbl
Hope this helps,
Mike
- Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: http://EDais.mvps.org/
- Next message: Ken Halter: "Re: Sending a picture to a paint program?"
- Previous message: John Walker: "VB6 Directory\File Maintenance"
- In reply to: Webbee: "Sending a picture to a paint program?"
- Next in thread: Ken Halter: "Re: Sending a picture to a paint program?"
- Messages sorted by: [ date ] [ thread ]