为什么我在内存中画的图复制不到窗体上啊?
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor 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 CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) 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 Arc Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long) As Long
Private Type RECT
t As Long
b As Long
l As Long
r As Long
End Type
Dim re As RECT
Private Sub Form_Click()
mhdc = CreateCompatibleDC(Me.hdc)
mbmp = CreateCompatibleBitmap(Me.hdc, Me.Width, Me.Height)
SelectObject mhdc, mbmp
brush = CreateSolidBrush(RGB(255, 0, 0))
pen = CreatePen(0, 3, RGB(0, 255, 0))
re.l = Me.Left
re.r = Me.Left + Me.Width
re.t = Me.
re.b = Me. + Me.Height
FillRect mhdc, re, brush
SelectObject mhdc, pen
Arc mhdc, 0, 0, 200, 200, 10, 10, 200, 200
BitBlt Me.hdc, 0, 0, Me.Width, Me.Height, mhdc, 0, 0, vbSrcCopy
DeleteDC mhdc
DeleteObject mbmp
DeleteObject brush
DeleteObject pen
End Sub
这么小器?贴多点出来。
你把窗体的Autoredraw设为Flase试试看.
GZ
开头加 Me.AutoRedraw = True
结尾加 Me.Refresh
试试
不好意思,
我运行了一下,我的也是出不来。
但是我知道错误在那里了。
hBmp = CreateCompatibleBitmap(Me.hDC, Me.Width, Me.Height)
在CreateCompatibleBitmap的声明中,要求后两个参数是以象素威单位。
你的hBmp位图句柄是错误的。我试验了
hBmp = CreateCompatibleBitmap(Me.hDC, Me.ScaleWidth, Me.ScaleHeight)
但是还是不行。可能是窗体场景不能兼容。
内存设备场景即与彩色位图兼容,也与单色位图兼容。这个函数的作用是创建一幅与当前选入hdc中的场景兼容。对一个内存场景来说,默认的位图是单色的。倘若内存设备场景有一个DIBSection选入其中,这个函数就会返回DIBSection的一个句柄。如hdc是一幅设备位图,那么结果生成的位图就肯定兼容于设备
如果nWidth和nHeight为零,返回的位图就是一个1×1的单色位图
你也看看,我再试试。
hBmp = CreateCompatibleBitmap(Me.hDC, Me.Width, Me.Height) =>
hBmp = CreateCompatibleBitmap(hDevC, Me.Width, Me.Height) ?
在我这里却不行了!!