VB 关于API刷子的

[复制链接]
查看11 | 回复1 | 2009-5-9 22:29:59 | 显示全部楼层 |阅读模式
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function CreatePatternBrush Lib "gdi32" (ByVal hBitmap 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 SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Dim bBytes(1 To 8) As Byte
Private Sub Command1_Click()
Dim R As RECT, mBrush As Long, hBitmap As Long
hBitmap = CreateCompatibleBitmap(Picture1.hdc, 200, 100)
mBrush = CreatePatternBrush(hBitmap)
SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
FillRect Me.hdc, R, mBrush
DeleteObject mBrush
DeleteObject hBitmap
End Sub
上面的代码是我从网络搜来修改的,但怎么改都不对,我在picture1中加载了一 幅小图,我想用这幅小图填充窗体,可一点运行,窗体就变成黑色的了,没有看见图,有高手能告诉我为什么吗?
还有,能不能帮我修改下,怎么才能不用PictureBox控件,就得到app.path & "BS1.dim"的图并填充到窗体去啊?
还有,我怎么才能得到一幅图象的局部区域,比如我想得到图象中间一个方框内的图象,该怎么做到啊?
强烈感谢进来帮助的人,我正在API学习,请多指教,谢谢了

回复

使用道具 举报

千问 | 2009-5-9 22:29:59 | 显示全部楼层
不用PictureBox控件 那就用 StdPicture 对象复制图片用 BitBltPrivate Const SRCCOPYAs Long = &HCC0020Private 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 Lo...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行