Page 1 of 1
Animation of Windows
Posted: Sun Nov 04, 2007 3:28 am
by nageswaragunupudi
I am trying to make some alert message dialogs, which pop up (sliding upwards) in the right bottom corner of the screen, like some instant messengers do.
I am trying with the AnimateWindow( HWND hWnd, DWORD dwTime, DWORD dwFlags) of user32.dll. Borland's winuser.h has the constants and prototype of this function.
I am able to close a window with animation effects by calling this function in the valid clause. But actually I want to activate a window with the animation. ON INIT is of no use because bInit is evaluated after the window is shown. I think this animatewindow should be used in the Activate method instead of the Showwindow function. Perhaps it would be a lot nicer if we can specify the animation type in the cShow parameter of the Activate method and the Activate method responds to it.
Any advice about how can I accomplish this?
Posted: Sun Nov 04, 2007 7:03 pm
by Antonio Linares
Code: Select all
#include "FiveWin.ch"
#define AW_HOR_POSITIVE 0x00000001
#define AW_HOR_NEGATIVE 0x00000002
#define AW_VER_POSITIVE 0x00000004
#define AW_VER_NEGATIVE 0x00000008
#define AW_CENTER 0x00000010
#define AW_HIDE 0x00010000
#define AW_ACTIVATE 0x00020000
#define AW_SLIDE 0x00040000
#define AW_BLEND 0x00080000
function Main()
local oWnd
DEFINE WINDOW oWnd TITLE "Test"
AnimateWindow( oWnd:hWnd, 600, nOr( AW_SLIDE, AW_HOR_POSITIVE ) )
ACTIVATE WINDOW oWnd ;
ON INIT oWnd:Refresh()
return nil
DLL FUNCTION AnimateWindow( hWnd AS LONG, nTime AS LONG, nFlags AS LONG ) AS BOOL PASCAL ;
LIB "user32.dll"
Posted: Mon Nov 05, 2007 5:03 am
by nageswaragunupudi
Mr Antonio
Thanks. It is working. But I dont know why is not working with a Dialog. Why shd not dialog behave like window?
Posted: Mon Nov 05, 2007 7:48 am
by Antonio Linares
NageswaraRao,
The dialog hWnd is not valid until the ACTIVATE of the dialog
You may use oDlg:bStart = { || ... }
Posted: Mon Nov 05, 2007 8:38 am
by nageswaragunupudi
So far my observations:
1) Animation is not working with dialogs. Even with bStart.
2) Working with windows both while opening and closing. While opening, both AW_SLIDE and AW_ACTIVATE are giving the same effect. While closing we need to set flags to AW_HIDE. ( or'd with direction flag ofcourse).
3) Important: While hiding (or closing ) the part of the window that overlaps any FWH window does not get cleared till it is fully closed.
4) Important: I put an xbrowse or wbrowse in the window. During opening and closing animation, the window is totally black. Browse appears after the window is fully open and window gets black immediately before commencing the closing animation. I shall continue experimenting with on paint ownd:say, etc.
I am using opening activation as Mr. Antonio suggested. For closing I am using " VALID ( AnimateWindow( oWnd:hWnd, 200, nOr ( AW_HIDE, AW_VER_POSITVE ), .T. )". Mr. Antonio may suggest, with this usage is the window properly closed and released?.
Posted: Mon Nov 05, 2007 8:49 am
by Antonio Linares
> with this usage is the window properly closed and released?
yes
Posted: Mon Nov 05, 2007 8:50 am
by nageswaragunupudi
ownd:bpainted does not work during animation. colors of window also do not show up during animations.
Posted: Mon Nov 05, 2007 8:55 am
by Antonio Linares
NageswaraRao,
Yes, I have noticed that too.
I would not recommend to use AnimateWindow() as it does not uses FWH windows procedure, but the standard (default) one
Posted: Mon Nov 05, 2007 9:12 am
by StefanHaupt
here is another solution with transparent or fading dialogs. Maybe it´s helpful or you
Code: Select all
#include "Fivewin.ch"
#define LWA_ALPHA 2
#define GWL_EXSTYLE -20
#define WS_EX_LAYERED 524288
FUNCTION MAIN()
LOCAL oDlg, nFactor := 210, btnmais, btnmenos, btnloops
DEFINE DIALOG oDlg;
TITLE "Transparent dialog" pixel from 0, 0 to 400, 400
@10, 10 SAY "This is a test" SIZE 30, 7 pixel
oDlg:bpainted := { || SETTRANSP( oDlg, nFactor ) }
@050, 10 button btnMais prompt "Mais Transparencia" ;
action TRANSPAR( oDlg, @nFactor, "+", btnmais ) size 70, 20 pixel
@050, 100 button btnMenos prompt "Menos Transparencia" ;
action TRANSPAR( oDlg, @nFactor, "-", btnmenos ) size 70, 20 pixel
@100, 50 button btnloops prompt "Alternando Transparencia" ;
action TRANSLOOP( oDlg, @nFactor ) size 70, 20 pixel
ACTIVATE DIALOG oDlg CENTER
RETURN NIL
STATIC FUNCTION SETTRANSP( oDlg, nFactor )
SETWINDOWLONG( oDlg:hWnd, GWL_EXSTYLE, ;
NOR( GETWINDOWLONG( oDlg:hWnd, ;
GWL_EXSTYLE ), WS_EX_LAYERED ) )
SETLAYEREDWINDOWATTRIBUTES( oDlg:hWnd, , ;
nFactor, LWA_ALPHA )
RETURN NIL
static function TRANSPAR( oDlg, nFactor, Sinal, oBtn )
if Sinal = "+"
if nFactor < 10 ; nFactor := 260 ; endif
nFactor -= 5
else
if nFactor > 250 ; nFactor := 5 ; endif
nFactor += 5
endif
SetWindowText( oDlg:hWnd, "Transparent dialog. Transparencia: " + alltrim(str(nFactor)) )
SETLAYEREDWINDOWATTRIBUTES( oDlg:hWnd, , nFactor, LWA_ALPHA )
sysrefresh()
return (nil)
static function TRANSLOOP( oDlg, nFactor, Sinal, oBtn )
local X
for X = 1 to 255
SetWindowText( oDlg:hWnd, "Transparent dialog. Transparencia: " + alltrim(str(x)) )
SETLAYEREDWINDOWATTRIBUTES( oDlg:hWnd, , x, LWA_ALPHA )
next
for X = 255 to 1 step -1
SetWindowText( oDlg:hWnd, "Transparent dialog. Transparencia: " + alltrim(str(x)) )
SETLAYEREDWINDOWATTRIBUTES( oDlg:hWnd, , x, LWA_ALPHA )
next
SetWindowText( oDlg:hWnd, "Transparent dialog. Transparencia: " + alltrim(str(nFactor)) )
SETLAYEREDWINDOWATTRIBUTES( oDlg:hWnd, , nFactor, LWA_ALPHA )
sysrefresh()
return NIL
DLL32 function SetLayeredWindowAttributes( hWnd As LONG, crKey As LONG,;
bAlpha As LONG, dwFlags As LONG ) AS LONG PASCAL ;
from "SetLayeredWindowAttributes" lib "user32.DLL"
Posted: Mon Nov 05, 2007 9:53 am
by nageswaragunupudi
Mr Antonio
I take your advice. Thanks
Mr. Stephan
You know this was not what I was looking for to start with.
But surely I am happier that you shared such a wonderful program with all of us. The effects are amazing and I thank you very much for it. Yes I would definitely use this code. May I ask if you already know any limitations about various windows versions? or should we test now?
Posted: Tue Nov 06, 2007 9:13 am
by StefanHaupt
NageswaraRao,
the sample is working with XP and Vista. Not tested with W98.
Posted: Tue Nov 06, 2007 3:29 pm
by RAMESHBABU
the sample is working with XP and Vista. Not tested with W98.
Not working in Win98!
- Ramesh Babu P