Click here to Skip to main content
16,018,916 members
Articles / Programming Languages / ASM

MASM ImageFader

Rate me:
Please Sign up or sign in to vote.
3.89/5 (15 votes)
19 Jan 2013CPOL1 min read 70.6K   680   26   19
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:

ASM
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;
; 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)


Written By
Software Developer (Senior)
Switzerland Switzerland
programmer and software junkie since 1991 zurich switzerland

Comments and Discussions

 
GeneralMy vote of 1 Pin
Paul_Williams23-Jan-13 1:59
Paul_Williams23-Jan-13 1:59 
GeneralMy vote of 5 Pin
Levintaeyeon21-Jan-13 16:49
Levintaeyeon21-Jan-13 16:49 
GeneralMy vote of 3 Pin
Snorri Kristjansson20-Jan-13 4:09
professionalSnorri Kristjansson20-Jan-13 4:09 
GeneralMy vote of 1 Pin
benjamin231-May-09 9:49
benjamin231-May-09 9:49 
GeneralOld times Pin
paulgafa14-Feb-07 22:41
paulgafa14-Feb-07 22:41 
GeneralMASM32 Still around Pin
Jonas Hammarberg12-Feb-07 22:46
professionalJonas Hammarberg12-Feb-07 22:46 
GeneralGreat! :) Pin
MP3Observer8-Feb-07 4:24
MP3Observer8-Feb-07 4:24 
Generallook's good Pin
Waldermort8-Feb-07 3:20
Waldermort8-Feb-07 3:20 
GeneralRe: look's good Pin
kim.david.hauser8-Feb-07 5:20
kim.david.hauser8-Feb-07 5:20 
GeneralRe: look's good Pin
Waldermort8-Feb-07 20:33
Waldermort8-Feb-07 20:33 
GeneralRe: look's good Pin
Daniel Pistelli8-Feb-07 23:49
Daniel Pistelli8-Feb-07 23:49 
GeneralRe: look's good Pin
Waldermort9-Feb-07 2:41
Waldermort9-Feb-07 2:41 
QuestionWhat's the point? Pin
Jim Crafton8-Feb-07 3:03
Jim Crafton8-Feb-07 3:03 
AnswerRe: What's the point? Pin
kim.david.hauser8-Feb-07 5:09
kim.david.hauser8-Feb-07 5:09 
GeneralRe: What's the point? Pin
Jim Crafton8-Feb-07 5:15
Jim Crafton8-Feb-07 5:15 
GeneralRe: What's the point? Pin
Gerard Nicol8-Feb-07 10:09
Gerard Nicol8-Feb-07 10:09 
I am not sure that Techno Silliness's post was criticism.

I read the article too and I was struggling to see the point. Perhaps there is one there but I think there was a failure to articulate the point.

Why would you hide information as proposed (forget the assembler issue)?

To answer your question; People get married because it is a tradition, they have children because female's can fall pregnant after intercourse and they post comments like Techno Silliness's because they want to know why somebody went to the trouble of posting an article that they fail to see any logic in.

Don't get offended. Read Techno Silliness's post and reply to it.

So far you have only shown that you also fail to understand simple questions.

Gerard

GeneralRe: What's the point? Pin
Jim Crafton9-Feb-07 4:07
Jim Crafton9-Feb-07 4:07 
GeneralRe: What's the point? Pin
ETA8-Feb-07 23:50
ETA8-Feb-07 23:50 
GeneralRe: What's the point? Pin
kim.david.hauser11-Apr-12 7:17
kim.david.hauser11-Apr-12 7:17 

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

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