如何用bmp画窗体中的不规则区域

大脚板 2004-07-15 04:59:17
如题
...全文
96 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kvls 2004-07-15
  • 打赏
  • 举报
回复
刚好机子上有代码,虽然是汇编,不过应该没问题。
;设置窗口大小
invoke GetObject, g_hbmBackground, sizeof BITMAP, addr bm
invoke GetWindowRect, hWnd, addr rcWindow
invoke MoveWindow, hWnd, rcWindow.left, rcWindow.top, bm.bmWidth, bm.bmHeight, TRUE

;设置不规则性
invoke GetDC, hWnd
mov hdc, eax
invoke CreateCompatibleDC, hdc
mov hmemdc, eax
invoke SelectObject, hmemdc, g_hbmBackground
invoke GetPixel, hmemdc, 0, 0
mov colMask, eax
mov x, 0
mov y, 0
invoke CreateRectRgn, 0, 0, bm.bmWidth, bm.bmHeight
mov rgnWnd, eax

.while TRUE
.while TRUE
invoke GetPixel, hmemdc, x, y
.if colMask == eax
mov ebx, x
inc ebx
mov edx, y
inc edx
invoke CreateRectRgn, x, y, ebx, edx
mov rgnTmp, eax
invoke CombineRgn, rgnWnd, rgnWnd, rgnTmp, RGN_XOR
invoke DeleteObject, rgnTmp
.endif
inc x
mov eax, x
.if eax >= bm.bmWidth
mov x, 0
.break
.endif
.endw
inc y
mov eax, y
.break .if eax >= bm.bmHeight
.endw
invoke SetWindowRgn, hWnd, rgnWnd, TRUE
lixiaosan 2004-07-15
  • 打赏
  • 举报
回复
SetWindowRgnSee Also
GetLastError, GetWindowRgn

Requirements
Runs on Versions Defined in Include Link to
Windows CE OS 2.12 and later Winuser.h Winmgr.lib
This function sets the window region of a window. The window region determines the area within the window where the system permits drawing. The system does not display any portion of a window that lies outside of the window region

int SetWindowRgn(
HWND hWnd,
HRGN hRgn,
BOOL bRedraw
);
快乐鹦鹉 2004-07-15
  • 打赏
  • 举报
回复
获取这个不规则区域的最大矩形外框。然后将图片显示到这个矩形中,显示时,设置CDC的裁剪区域为这个不规则区域即可。SetClipRgn(pRgn);
taianmonkey 2004-07-15
  • 打赏
  • 举报
回复
重载OnEraseBkgnd(HDC hdc)来绘制图片!
gaotianpeng 2004-07-15
  • 打赏
  • 举报
回复
代码多的是,我说一下原理
获取BMP大小,用CDC类中的API判断获取的点是不是透明的
再SETWINDOWSRGN一下!

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧