level 13
Option Explicit
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Const SRCCOPY = &HCC0020
Private Sub Command1_Click()
Dim mDC As Long
Dim tmpPic As StdPicture
Set tmpPic = LoadPicture("C:\Users\Administrator\Desktop\hbt_login.bmp")
'这里加载图片文件如果是jpg,bmp格式,窗体可以显示图片,如果是ico,cur格式,则窗体不显示图片,也不报错
Dim aHdc As Long
aHdc = GetDC(0) '获取桌面DC
mDC = CreateCompatibleDC(aHdc) '创建mDC
SelectObject mDC, tmpPic.Handle '将图片装入mdc
ReleaseDC 0, aHdc '释放aHdc
BitBlt Me.hdc, 0, 0, 200, 200, mDC, 0, 0, vbSrcCopy '将mDC画入窗体
DeleteDC mDC '删除mDC
End Sub
Private Sub Command2_Click()
Dim tmpPic As StdPicture
Set tmpPic = LoadPicture("C:\Users\Administrator\Desktop\hand.cur")
'用PaintPicture方式,jpg,bmp,ico,cur格式图片都可以显示
Me.PaintPicture tmpPic, 0, 0
End Sub
2020年03月21日 12点03分
2
level 13
二楼贴代码,不知道有没有贴出来。还望指教。
或者还有什么别的办法,将stdPicure 显示到DC场景中吗?
2020年03月21日 12点03分
3
level 13
bmpPic.type =3时用DrawIcon绘制,selectobject没有选入图标的句柄
2020年03月21日 12点03分
5
好,非常感谢,我试下。随风大神,刚才想艾特你,不知道怎么艾特
2020年03月21日 12点03分
我当时也测试的type,jpg和bmp 的type 是1,ico和cur的type是3。网上找这写type的说明也没找到
2020年03月21日 12点03分