MFC对话框加上PNG图片后,图片上的控件可以设置透明吗?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MFC对话框加上PNG图片后,图片上的控件可以设置透明吗?相关的知识,希望对你有一定的参考价值。

这里的对话框已经设置透明,普通的MFC对话框上面控件使用pDC->SetBkMode( TRANSPARENT );可以变成透明,和对话框颜色都是白色;但是PNG图片不是白色的,导致上面的控件使用这条语句后变成白色的,在PNG图片上非常不好看,请教。
这个图片显示效果

参考技术A 可以啊,你可以搜索一下CxImage这个类
这是百科http://baike.baidu.com/view/2126624.htm
是开源的,效果挺不错的
参考技术B 一种不是很安全但是最方便的方法
增加WM_CTLCOLOR方法,添加

return (HBRUSH)GetStockObject(NULL_BRUSH)即可

怎么在VB的图片框里加载PNG格式的图片,或在窗口上显示PNG图片?

不要从网上复制,本人会追加分

假设你的图片的路径是C:\1.png
在form的load事件中写上
me.picture=loadpicture("c:\1.png")
就可以了,这是直接加载到窗体的,不需要picturebox控件。
参考技术A LoadPicture()肯定不行啦~LoadPicture()只能读取bmp,jpg的图片。
加载PNG图片,要熟练API与GDI+的用法。这个我没学,在加上不能网上复制,难度相当大啊!(我有源代码,如果你需要,可以留下邮箱。)
参考技术B 硬哥你别乱来,别有了颖哥就想在VB里加载你和颖哥PNG的图片,你要明白你跟颖哥的情义天地可鉴。大家都会明白的,这30分我不要了,当做你们的结婚礼物 参考技术C Option Explicit
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type

Private Type PICTDESC
Size As Long
Type As Long
hPic As Long
hPal As Long
End Type

Private Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type

Private Declare Function GdiplusStartup Lib "GDIPlus" (token As Long, _
inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As Long
Private Declare Function GdipCreateBitmapFromFile Lib "GDIPlus" (ByVal filename As Long, bitmap As Long) As Long
Private Declare Function GdipCreateHBITMAPFromBitmap Lib "GDIPlus" (ByVal bitmap As Long, _
hbmReturn As Long, ByVal background As Long) As Long
Private Declare Function GdipDisposeImage Lib "GDIPlus" (ByVal image As Long) As Long
Private Declare Function GdiplusShutdown Lib "GDIPlus" (ByVal token As Long) As Long
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PICTDESC, _
RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long

Public Function LoadImage(ByVal strFName As String) As IPicture
Dim uGdiInput As GdiplusStartupInput
Dim hGdiPlus As Long
Dim hGdiImage As Long
Dim hBitmap As Long

uGdiInput.GdiplusVersion = 1

If GdiplusStartup(hGdiPlus, uGdiInput) = 0 Then
If GdipCreateBitmapFromFile(StrPtr(strFName), hGdiImage) = 0 Then
GdipCreateHBITMAPFromBitmap hGdiImage, hBitmap, 0
Set LoadImage = ConvertToIPicture(hBitmap)
GdipDisposeImage hGdiImage
End If
GdiplusShutdown hGdiPlus
End If

End Function

Public Function ConvertToIPicture(ByVal hPic As Long) As IPicture

Dim uPicInfo As PICTDESC
Dim IID_IDispatch As GUID
Dim IPic As IPicture

Const PICTYPE_BITMAP = 1

With IID_IDispatch
.Data1 = &H7BF80980
.Data2 = &HBF32
.Data3 = &H101A
.Data4(0) = &H8B
.Data4(1) = &HBB
.Data4(2) = &H0
.Data4(3) = &HAA
.Data4(4) = &H0
.Data4(5) = &H30
.Data4(6) = &HC
.Data4(7) = &HAB
End With

With uPicInfo
.Size = Len(uPicInfo)
.Type = PICTYPE_BITMAP
.hPic = hPic
.hPal = 0
End With

OleCreatePictureIndirect uPicInfo, IID_IDispatch, True, IPic

Set ConvertToIPicture = IPic
End Function

以上是关于MFC对话框加上PNG图片后,图片上的控件可以设置透明吗?的主要内容,如果未能解决你的问题,请参考以下文章

在 MFC 中的 groupbox 或图片控件中创建矩形

[ MFC ] 对话框动态控件的创建 在Picture Control控件上显示图片 [大三TJB_708]

猎豹MFC--图片控件CStatic和动画控件CAnimateCtrl

怎么在VB的图片框里加载PNG格式的图片,或在窗口上显示PNG图片?

怎么在VB的图片框里加载PNG格式的图片,或在窗口上显示PNG图片?

MFC的一个对话框中怎样将设置的背景图片替换