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
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