为什么GDI+绘图失败啊
在窗口中就正常,如果将源码转到用户控件中想在用户控件中绘图就会失败啊Option Explicit
Private Type GdiplusStartupInput
GdiplusVersion As Long ' Must be 1 for GDI+ v1.0, the current version as of this writing.
DebugEventCallback As Long ' Ignored on free builds
SuppressBackgroundThread As Long ' FALSE unless you're prepared to call
' the hook/unhook functions properly
SuppressExternalCodecs As Long ' FALSE unless you want GDI+ only to use
' its internal image codecs.
End Type
Private Enum GpStatus ' aka Status
Ok = 0
GenericError = 1
InvalidParameter = 2
OutOfMemory = 3
ObjectBusy = 4
InsufficientBuffer = 5
NotImplemented = 6
Win32Error = 7
WrongState = 8
Aborted = 9
FileNotFound = 10
ValueOverflow = 11
AccessDenied = 12
UnknownImageFormat = 13
FontFamilyNotFound = 14
FontStyleNotFound = 15
NotTrueTypeFont = 16
UnsupportedGdiplusVersion = 17
GdiplusNotInitialized = 18
PropertyNotFound = 19
PropertyNotSupported = 20
End Enum
Private Declare Function GdiplusStartup Lib "gdiplus" (token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As GpStatus
Private Declare Function GdiplusShutdown Lib "gdiplus" (ByVal token As Long) As GpStatus
Private Declare Function GdipDrawImage Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, ByVal x As Single, ByVal y As Single) As GpStatus
Private Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hDC As Long, graphics As Long) As GpStatus
Private Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal graphics As Long) As GpStatus
Private Declare Function GdipLoadImageFromFile Lib "gdiplus" (ByVal filename As String, Image As Long) As GpStatus
Private Declare Function GdipDisposeImage Lib "gdiplus" (ByVal Image As Long) As GpStatus
Dim gdip_Token As Long
Dim gdip_pngImage As Long
Dim gdip_Graphics As Long
Private Sub UserControl_Initialize()
Dim GpInput As GdiplusStartupInput
GpInput.GdiplusVersion = 1
If GdiplusStartup(gdip_Token, GpInput) <> Ok Then
MsgBox "加载GDI+失败!", vbCritical, "加载错误"
End
End If
If GdipCreateFromHDC(UserControl.hDC, gdip_Graphics) <> Ok Then
MsgBox "出现错误!", vbCritical, "错误"
GdiplusShutdown gdip_Token
End
Else
Debug.Print UserControl.hDC
End If
GdipLoadImageFromFile StrConv(App.Path & "\Show.png", vbUnicode), gdip_pngImage '加载文件
End Sub
Private Sub UserControl_Paint()
If GdipDrawImage(gdip_Graphics, gdip_pngImage, 0, 0) <> Ok Then Debug.Print "显示失败。。。" '就是这步会失败
End Sub
Private Sub UserControl_Terminate()
GdipDisposeImage gdip_pngImage
GdipDeleteGraphics gdip_Graphics
GdiplusShutdown gdip_Token
End Sub
======================================
我知道那里错误了,是StrConv(App.Path & "\Show.png", vbUnicode)这里错误了,app.path中含有透明两个字,结果如果换了其他字就好了,但是也不知道还有没有其他中文不行,这是怎么搞的啊
[ 本帖最后由 ylof1986 于 2010-3-24 10:51 编辑 ]