What's the format of region (RGN) to be used with such functions as SetWindowRgn?
You can create a RGN with CreateRectRgn
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/regions_2h0u.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/regions_2h0u.asp
Hi, bazik
I have already looked through MSDN, but haven't found what I exactly want.
My idea is to make the region out of a bitmap. It is complex enough for making it with rectangles and ellipses. To my mind it is better to get the format of RGN and write it manually (or write a proc that does it automatically).
Can anyone help me with it?
I have already looked through MSDN, but haven't found what I exactly want.
My idea is to make the region out of a bitmap. It is complex enough for making it with rectangles and ellipses. To my mind it is better to get the format of RGN and write it manually (or write a proc that does it automatically).
Can anyone help me with it?
_MAKE_REGION PROTO :DWORD
.CODE
; +------------------------------------------------------------------------------------------------+
; | _MAKE_REGION( bmp_handle ) |
; +------------------------------------------------------+-----------------------------------------+
_MAKE_REGION PROC USES ESI EDI EBX hwnd : DWORD, bhnd : DWORD
LOCAL flag, frun, d_dc, f_dc, tcol, _hdc : DWORD
INVOKE CreateCompatibleDC, NULL ; CREATE A DUMMY DC (->_hdc)
MOV _hdc, EAX
INVOKE SelectObject, _hdc, bhnd ; SELECT THE BACKGROUND INTO THIS DC
MOV flag, FALSE
MOV frun, TRUE
XOR EDI, EDI
XOR ESI, ESI
INVOKE GetPixel, _hdc, 0, 0 ; GET PIXELCOLOR AT X:0 Y:0 (->tcol)
MOV tcol, EAX ; NOW tcol HOLDS THE *TRANSPARENT* COLOR
_XLOOP: INVOKE GetPixel, _hdc, EDI, ESI ; GET PIXELCOLOR AT X:EDI Y:ESI...
CMP EAX, tcol ; CURRENT COLOR = TRANSPARENT???
JZ _LETSGO
CMP EDI, PICTURE_W ; END OF ROW???
JNZ _FNDONE
_LETSGO:CMP flag, TRUE ; ENTIRE TRANSPARENT ROW PASSED???
JNZ _NXTONE
MOV flag, FALSE ; ...SUCCESS
LEA EAX, [ ESI + 1 ] ; EAX = CURRENT Y + 1
INVOKE CreateRectRgn, EBX, ESI, EDI, EAX ; REGION (FIRST X, FIRST Y, LAST X, Y+1)
MOV d_dc, EAX ; SAVE CREATED DC (->d_dc)
CMP frun, TRUE ; FIRST RUN???
JNZ _NOFRUN
MOV frun, FALSE
PUSH d_dc ; f_dc -> d_dc
POP f_dc
JMP _NXTONE
_NOFRUN:INVOKE CombineRgn, f_dc, f_dc, d_dc, RGN_OR ; COMBINE REGION DATA (->d_dc)
INVOKE DeleteObject, d_dc ; DELETE UNUSED DUMMY DC
JMP _NXTONE
_FNDONE:CMP flag, FALSE ; ARE THERE TRANRARENT PIXELS LEFT???
JNZ _NXTONE
MOV flag, TRUE ; MARK END OF ROW
MOV EBX, EDI ; SAVE START OF TRANSPARENT ROW (->EBX)
_NXTONE:INC EDI ; NEXT COL
CMP EDI, PICTURE_W ; X > PICTURE-WIDTH???
JBE _XLOOP
XOR EDI, EDI ; X = 0
INC ESI ; Y = Y + 1 (NEXT ROW)
CMP ESI, PICTURE_H ; WE REACHED THE END?
JB _XLOOP
_EXIT: INVOKE DeleteDC, _hdc ; REGION DATA TO OUR WINDOW AND
;________________________________________________; f_dc -> FINAL REGION
MOV EAX, f_dc ; RETURN REGION-HANDLE
RET ; CLOSE THE BITMAP-DC...
_MAKE_REGION ENDP
example:
[RC]
1000 BITMAP "test.bmp"
[ASM]
_MAKE_REGION PROTO :DWORD
.CONST
PICTURE_W EQU 350 ;width and height of the pic
PICTURE_H EQU 130 ;GetObjectInfo can retrieve this
;automaticaly...
.DATA?
hBitmap01 DD ?
hRegion DD ?
.CODE
.IF uMSG == WM_CREATE
INVOKE LoadBitmap, hInstance, 1000 ; LOAD BACKGROUND-PIC
MOV hBitmap01, EAX
INVOKE _MAKE_REGION, hBitmap01 ; CREATE THE REGION
MOV hRegion, EAX
INVOKE SetWindowRgn, hwnd, EAX, TRUE
.ELSEIF uMSG == WM_DESTROY
INVOKE DeleteObject, hRegion
INVOKE DeleteObject, hBitmap01
sorry PICTURE_W and PICTURE_H are hardcoded constants... you can retrieve this
dynamicaly with GetObjectInfo. oh and you have to use SetWindowsRegion on eax
after calling this routine. this routine uses only rect-regions... i thought about writing
a real one but i was to lazy.
and look at the GetRegionData API in the api-reference... the raw region format is
declared there...
Thanks, mob!
That's exactly what I was looking for :alright: .
That's exactly what I was looking for :alright: .