[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

David Youngblood

6/3/2012 12:04:00 AM

How to create a Windows Metafile? The below sample errors on the LoadPicture
line (Error 481 - Invalid picture). The resulting file can be opened in
Windows Picture Viewer and MS Paint, but not by VB's LoadPicture.

David

Private Declare Function CreateMetaFile Lib "gdi32" _
Alias "CreateMetaFileA" ( _
ByVal lpString As String) As Long

Private Declare Function SetMapMode Lib "gdi32" ( _
ByVal hdc As Long, _
ByVal nMapMode As Long) As Long

Private Declare Function SetWindowExtEx Lib "gdi32" ( _
ByVal hdc As Long, _
ByVal nX As Long, _
ByVal nY As Long, _
lpSize As Long) As Long

Private Declare Function SetWindowOrgEx Lib "gdi32" ( _
ByVal hdc As Long, _
ByVal nX As Long, _
ByVal nY As Long, _
lpPoint As Long) As Long

Private Declare Function CloseMetaFile Lib "gdi32" ( _
ByVal hMF As Long) As Long

Private Declare Function DeleteMetaFile Lib "gdi32" ( _
ByVal hMF As Long) As Long

Private Declare Function Rectangle Lib "gdi32" ( _
ByVal hdc As Long, _
ByVal X1 As Long, _
ByVal Y1 As Long, _
ByVal X2 As Long, _
ByVal Y2 As Long) As Long

Private Declare Function SetViewportExtEx Lib "gdi32" ( _
ByVal hdc As Long, _
ByVal nX As Long, _
ByVal nY As Long, _
lpSize As Long) As Long

Private Declare Function SetViewportOrgEx Lib "gdi32" ( _
ByVal hdc As Long, _
ByVal nX As Long, _
ByVal nY As Long, _
lpPoint As Long) As Long

Private Declare Function PlayMetaFile Lib "gdi32" ( _
ByVal hdc As Long, _
ByVal hMF As Long) As Long

Private Const MM_ANISOTROPIC = 8

Private Sub Command1_Click()

Dim hdcMF As Long
Dim hMF As Long

hdcMF = CreateMetaFile("I:\Temp\Graph.wmf")
SetMapMode hdcMF, MM_ANISOTROPIC
Debug.Print SetWindowOrgEx(hdcMF, 0, 0, ByVal 0)
Debug.Print SetWindowExtEx(hdcMF, 100, 100, ByVal 0)
Debug.Print SetViewportExtEx(hdcMF, Me.ScaleWidth, Me.ScaleHeight, ByVal
0)

Rectangle hdcMF, 10, 10, 90, 90

hMF = CloseMetaFile(hdcMF)
PlayMetaFile Me.hdc, hMF
DeleteMetaFile hMF
Set Form1.Picture1 = LoadPicture("I:\Temp\Graph.wmf")

End Sub


4 Answers

Chris Douce

6/3/2012 8:50:00 AM

0

You might have a look at this article

http://support.microsoft.com...

Regards




On 3/06/2012 2:04, David Youngblood wrote:
> How to create a Windows Metafile? The below sample errors on the LoadPicture
> line (Error 481 - Invalid picture). The resulting file can be opened in
> Windows Picture Viewer and MS Paint, but not by VB's LoadPicture.
>
> David
>
> Private Declare Function CreateMetaFile Lib "gdi32" _
> Alias "CreateMetaFileA" ( _
> ByVal lpString As String) As Long
>
> Private Declare Function SetMapMode Lib "gdi32" ( _
> ByVal hdc As Long, _
> ByVal nMapMode As Long) As Long
>
> Private Declare Function SetWindowExtEx Lib "gdi32" ( _
> ByVal hdc As Long, _
> ByVal nX As Long, _
> ByVal nY As Long, _
> lpSize As Long) As Long
>
> Private Declare Function SetWindowOrgEx Lib "gdi32" ( _
> ByVal hdc As Long, _
> ByVal nX As Long, _
> ByVal nY As Long, _
> lpPoint As Long) As Long
>
> Private Declare Function CloseMetaFile Lib "gdi32" ( _
> ByVal hMF As Long) As Long
>
> Private Declare Function DeleteMetaFile Lib "gdi32" ( _
> ByVal hMF As Long) As Long
>
> Private Declare Function Rectangle Lib "gdi32" ( _
> ByVal hdc As Long, _
> ByVal X1 As Long, _
> ByVal Y1 As Long, _
> ByVal X2 As Long, _
> ByVal Y2 As Long) As Long
>
> Private Declare Function SetViewportExtEx Lib "gdi32" ( _
> ByVal hdc As Long, _
> ByVal nX As Long, _
> ByVal nY As Long, _
> lpSize As Long) As Long
>
> Private Declare Function SetViewportOrgEx Lib "gdi32" ( _
> ByVal hdc As Long, _
> ByVal nX As Long, _
> ByVal nY As Long, _
> lpPoint As Long) As Long
>
> Private Declare Function PlayMetaFile Lib "gdi32" ( _
> ByVal hdc As Long, _
> ByVal hMF As Long) As Long
>
> Private Const MM_ANISOTROPIC = 8
>
> Private Sub Command1_Click()
>
> Dim hdcMF As Long
> Dim hMF As Long
>
> hdcMF = CreateMetaFile("I:\Temp\Graph.wmf")
> SetMapMode hdcMF, MM_ANISOTROPIC
> Debug.Print SetWindowOrgEx(hdcMF, 0, 0, ByVal 0)
> Debug.Print SetWindowExtEx(hdcMF, 100, 100, ByVal 0)
> Debug.Print SetViewportExtEx(hdcMF, Me.ScaleWidth, Me.ScaleHeight, ByVal
> 0)
>
> Rectangle hdcMF, 10, 10, 90, 90
>
> hMF = CloseMetaFile(hdcMF)
> PlayMetaFile Me.hdc, hMF
> DeleteMetaFile hMF
> Set Form1.Picture1 = LoadPicture("I:\Temp\Graph.wmf")
>
> End Sub
>
>

Mike Williams

6/3/2012 9:13:00 AM

0

"David Youngblood" <dwy@flash.net> wrote in message
news:jqe9nj$qfm$1@dont-email.me...

> How to create a Windows Metafile? The below sample errors
> on the LoadPicture line (Error 481 - Invalid picture). The
> resulting file can be opened in Windows Picture Viewer and
> MS Paint, but not by VB's LoadPicture.

You need to include a placeable header (or use the alternative enhanced
metafile funtions). The format of a placeable header is as shown at the
following link:

http://msdn.microsoft.com/en-us/librar...(v=vs.85).aspx

Mike


David Youngblood

6/4/2012 1:44:00 PM

0

"Mike Williams" <Mike@WhiskyAndCoke.com> wrote in message
news:jqf9qf$6p8$1@dont-email.me...
> "David Youngblood" <dwy@flash.net> wrote in message
> news:jqe9nj$qfm$1@dont-email.me...
>
>> How to create a Windows Metafile? The below sample errors
>> on the LoadPicture line (Error 481 - Invalid picture). The
>> resulting file can be opened in Windows Picture Viewer and
>> MS Paint, but not by VB's LoadPicture.
>
> You need to include a placeable header (or use the alternative enhanced
> metafile funtions). The format of a placeable header is as shown at the
> following link:
>
> http://msdn.microsoft.com/en-us/librar...(v=vs.85).aspx
>

Thanks Mike, Chris

That will solve the invalid picture problem, if I can tranlate the C code.
However, I still can't get it to scale properly on different devices.
Enhanced metafile is not an option. I'm using a (out of support)
spreadsheet control that takes a handle to a metafile.

David


Chris Douce

6/4/2012 7:18:00 PM

0

Hi David,

If you are going to do a lot of programming around metafiles,
it may be an option to have a look at MetaDraw from Bennet-Tec.
Not free however.

Chris



On 4/06/2012 15:43, David Youngblood wrote:
> "Mike Williams"<Mike@WhiskyAndCoke.com> wrote in message
> news:jqf9qf$6p8$1@dont-email.me...
>> "David Youngblood"<dwy@flash.net> wrote in message
>> news:jqe9nj$qfm$1@dont-email.me...
>>
>>> How to create a Windows Metafile? The below sample errors
>>> on the LoadPicture line (Error 481 - Invalid picture). The
>>> resulting file can be opened in Windows Picture Viewer and
>>> MS Paint, but not by VB's LoadPicture.
>>
>> You need to include a placeable header (or use the alternative enhanced
>> metafile funtions). The format of a placeable header is as shown at the
>> following link:
>>
>> http://msdn.microsoft.com/en-us/librar...(v=vs.85).aspx
>>
>
> Thanks Mike, Chris
>
> That will solve the invalid picture problem, if I can tranlate the C code.
> However, I still can't get it to scale properly on different devices.
> Enhanced metafile is not an option. I'm using a (out of support)
> spreadsheet control that takes a handle to a metafile.
>
> David
>
>