再问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 Any, 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
Dim gs As GpStatus, sTmp$
sTmp$ = App.Path & "\Show.png"
gs = GdipLoadImageFromFile(StrPtr(sTmp$), gdip_pngImage) '加载文件
Debug.Print gs = GpStatus.Ok, gs
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
[ 本帖最后由 ylof1986 于 2010-3-26 10:45 编辑 ]







