Option Explicit
Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Long) As Long
Private Declare Function SetBitmapBits Lib "GDI32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
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 SelectObject Lib "GDI32" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private MyHdc As Long, MyBmp As Long, MyOldBmp As Long, BmpDat() As Byte, RevByte As Long
Private myByte() As Byte
Private ScrW As Long, ScrH As Long
Private Sub Command1_Click()
Open "C:\Documents and Settings\Administrator\桌面\1.bmp" For Binary As #1
ReDim myByte(LOF(1) - 1)
Get #1, , myByte
Close #1
SetBitmapBits MyBmp, UBound(myByte) + 1, myByte(0)
BitBlt Pict.hDC, 0, 0, ScrW, ScrH, MyHdc, 0, 0, vbSrcCopy
End Sub
Private Sub Form_Load()
ScrW = Screen.Width \ Screen.TwipsPerPixelX
ScrH = Screen.Height \ Screen.TwipsPerPixelY
MyHdc = CreateCompatibleDC(Pict.hDC)
MyBmp = CreateCompatibleBitmap(Pict.hDC, ScrW, ScrH)
MyOldBmp = SelectObject(MyHdc, MyBmp)
End Sub
为什么PICT 控件显示的图片乱七八糟的?