Click here to Skip to main content
Click here to Skip to main content

MASM ImageFader

, 19 Jan 2013
Rate this:
Please Sign up or sign in to vote.
An Image fader application. This hides information behinde an image and fades it out onMouseOver to display the content behind the image. Useful for hiding something, or as a stylish accessory.

Sample image

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:

; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;
; Procedure: SetTrans
; Parameter: nAlpha (new AlphaValue)
; Version: 1.0
; Date/Author: 10.09.2005, dave (juniorsoft)
; Description: This procedure draws the backround together with the
; new bitmap with a given alphavalue to get a 
; transparent effect.
;
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SetTrans proc nAlpha:BYTE
local hdc:HDC 
local hMemDC:HDC 
local hMemDC2:HDC 
local hMemDC3:HDC 
local hBmpTmp:HBITMAP
local bf:BLENDFUNCTION

;invoke GetWindowDC,hWndBitmap
invoke GetDC,hWndBitmap
mov hdc, eax
invoke CreateCompatibleDC,hdc 
mov hMemDC,eax
invoke SelectObject,hMemDC,hBmpBack
;Create copy of Bitmap
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

;Alpha blending bitmap over background
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

;Call the AlphaBlend Func direct cuz "invoke" Macro 
;doesn't work right (addr bf)
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 AlphaBlend,hMemDC2,0,0,nPicWidth,nPicHeight,
;       addr hMemDC3,0,0,nPicWidth,nPicHeight,addr bf

;Copy new bitmap back to Ctrl
invoke BitBlt,hdc,0,0,nPicWidth,nPicHeight,hMemDC2,0,0,SRCCOPY

;Cleanup
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).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

kim.david.hauser
Software Developer (Senior)
Switzerland Switzerland
programmer and software junkie since 1991 zurich switzerland
Follow on   Twitter   Google+

Comments and Discussions

 
GeneralMy vote of 1 PingroupPaul @ The Computer Station23-Jan-13 1:59 
GeneralMy vote of 5 PinmemberLevintaeyeon21-Jan-13 16:49 
GeneralMy vote of 3 PinmemberSnorri20-Jan-13 4:09 
GeneralMy vote of 1 Pinmemberbenjamin231-May-09 9:49 
GeneralOld times Pinmemberpaulgafa14-Feb-07 22:41 
GeneralMASM32 Still around PinmemberJonas Hammarberg12-Feb-07 22:46 
GeneralGreat! :) PinmemberMP3Observer8-Feb-07 4:24 
Generallook's good PinmemberWalderMort8-Feb-07 3:20 
GeneralRe: look's good Pinmemberkim.david.hauser8-Feb-07 5:20 
GeneralRe: look's good PinmemberWalderMort8-Feb-07 20:33 
GeneralRe: look's good PinmemberDaniel Pistelli8-Feb-07 23:49 
GeneralRe: look's good PinmemberWalderMort9-Feb-07 2:41 
QuestionWhat's the point? PinmemberJim Crafton8-Feb-07 3:03 
AnswerRe: What's the point? Pinmemberkim.david.hauser8-Feb-07 5:09 
GeneralRe: What's the point? PinmemberJim Crafton8-Feb-07 5:15 
GeneralRe: What's the point? PinmemberGerard Nicol8-Feb-07 10:09 
GeneralRe: What's the point? PinmemberJim Crafton9-Feb-07 4:07 
GeneralRe: What's the point? PinmemberETA8-Feb-07 23:50 
GeneralRe: What's the point? Pinmemberkim.david.hauser11-Apr-12 7:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 20 Jan 2013
Article Copyright 2007 by kim.david.hauser
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid