Introduction
It came across my mind that there must be a way to initially hide information on a screen from the user. But he should be able to access the info if he knows where to click or where to go with his mouse pointer. The idea came up to produce an image fader, which initially displays an image and fades out the image if you hover it.
Initial State
This shows how the fade image is shown initially, you don't see what's behind the image:
Fade Out State
Here you see how the control looks like if you hover the control. It will fade out the image after a short delay and show what's behind the control.
Fade Routine
Here, you have the fade routine that uses AlphaBlend
(Win32) to blend the image over the background image taken initially:
SetTrans proc nAlpha:BYTE
local hdc:HDC
local hMemDC:HDC
local hMemDC2:HDC
local hMemDC3:HDC
local hBmpTmp:HBITMAP
local bf:BLENDFUNCTION
invoke GetDC,hWndBitmap
mov hdc, eax
invoke CreateCompatibleDC,hdc
mov hMemDC,eax
invoke SelectObject,hMemDC,hBmpBack
invoke CreateCompatibleDC,hdc
mov hMemDC2,eax
invoke CreateCompatibleBitmap,hdc,nPicWidth,nPicHeight
mov hBmpTmp, eax
invoke SelectObject,hMemDC2,hBmpTmp
invoke BitBlt,hMemDC2,0,0,nPicWidth,nPicHeight,hMemDC,0,0,SRCCOPY
mov bf.AlphaFormat, 0
mov bf.BlendFlags, 0
mov bf.BlendOp, AC_SRC_OVER
mov al,nAlpha
mov bf.SourceConstantAlpha, al
invoke CreateCompatibleDC,hdc
mov hMemDC3,eax
invoke SelectObject,hMemDC3,hBitmap
push bf
push nPicHeight
push nPicWidth
push 0
push 0
push hMemDC3
push nPicHeight
push nPicWidth
push 0
push 0
push hMemDC2
call AlphaBlend
invoke BitBlt,hdc,0,0,nPicWidth,nPicHeight,hMemDC2,0,0,SRCCOPY
invoke DeleteDC,hMemDC3
invoke DeleteDC,hMemDC2
invoke DeleteDC,hMemDC
invoke ReleaseDC,hWndBitmap,hdc
invoke DeleteObject,hBmpTmp
Ret
SetTrans EndP
This example also shows the use of several Win32 GDI functions in MASM. The reason why I use ASM is I think ASM is still a good language, and when it comes to "deep inside" debugging, a basic knowledge of ASM is necessary anyway. It's always good if you can have a look at a routine and you are not completely lost.
Tools Used
- MASM v8.2
- WinASM v5.1.1.0
- OllyDbg v1.10
Feel free to use the source as you want, in any of your applications. If there are any questions or problems, don't hesitate to contact me.
Cheers kim (a.k.a. dave).