Welcome to Foxite.COM Community Weblog Sign in | Join | Help

Bernard Bout

May the Fox be with you...

<September 2008>
SuMoTuWeThFrSa
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

Post Categories

Navigation

Some VFP links

Others...

Archives

Who links to this site?

Hey There!!!

Syndication




Emulating the XP Shutdown Effect in VFP9 forms with GDI+

Everyone who has used XP would have seen the effect produced when a user opts to shutdown Windows XP. To see it you click the "Start" button and then select ShutDown, which brings up the windows shutdown dialog similar to the one below.

The question is why would anyone click "Start" when they want to "Stop"? But that is another story...


You may have also noticed that windows slowly fades the coloured background down to grey, leaving the coloured dialogbox to appear more prominent. The colour of the desktop is restored if the user cancels this operation.

This same effect is possible in VFP forms and applications by using the GDI+x classes found on codeplex.

The class I created will do this for you for any form you drop it on, and call its methods. This class (download link below) uses the Imgcanvas object so to use it you will need to download the GDI+x classes.

Usage is extremely simple. You just drop it on the main form of a SDI or add it to _screen. When you need to produce the effect, you just call its SHOWLIGHTBOX() method and to remove the effect call the HIDELIGHTBOX() method. As calling sample is shown below which could be added to an Exit or Quit button:

bb = ThisForm.bbGdilightbox1.Showlightbox()
IF MESSAGEBOX("Are you sure you want to Quit?",308,"GDI+X Lightbox",0) = 7
    bb = ThisForm.bbGdiLightbox1.Hidelightbox()
    RETURN
ELSE
    ThisForm.Release
ENDIF


Basically what happens when the ShowLightbox method is called is that using GDI+ an image of the mainform is captured,  the lightbox class expands to overlay the whole form and the image is painted on the imgcanvas. A timer is kicked off in the background and the class returns control to the code.

The timer in the background increments a variable and calls the imgCanvas.Draw. The variable affects the way the ColorMatrix is created and this changes the colours of the screen image. With repeated calls the colour is "faded" till the image is grey. The timer then stops.

To restore, the class is just made invisible again.

The code to produce this effect comes from an article by Cesar in the UT mag. without which this class would not have been possible.

A sample form where you can test this as well as a pseudo messagebox form is also included in the download for this article. Just make sure you have the GDI+x classes, run SYSTEM.APP and then run the form:


Sample form with coloured background and VFP controls.

Click the "Exit" button to see the effect as the messagebox appears and the background slowly fades to grey.


Sample form with the form and controls faded to grey.

Complete source code is provided for anyone to modify as they please. Enjoy.

Update: Since I do not include the gdiplusx.vcx (as this must be downloaded from the VFPX site) and since I have subclassed the imgcanvas class found in the gdiplusx.vcx classlibrary, you need to resolve the link to the class yourself.

Just open the form in VFP and when it asks you for the Imgcanvas navigate to the gdiplusx.vcx on your computer where you will find the imgcanvas class. The form will then resolve the location correctly. Save the form, set the default path to the directory where the form is (to find the images) and then run the form.

Unfortunately this would happen since I don't supply the gdiplusx.vcx and I don't know where a user might have stored it. Thanks to Mike S for pointing that out.

Published Thursday, September 25, 2008 2:46 PM by bbout
Filed Under:
Attachment(s): bbGDILightbox.zip

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Emulating the XP Shutdown Effect in VFP9 forms with GDI+ @ Thursday, September 25, 2008 1:25 PM

¡Excelente, Bernard!
Muchas gracias por compartirlo

No hay de qué Horacio

Horacio Giménez

# re: Emulating the XP Shutdown Effect in VFP9 forms with GDI+ @ Thursday, September 25, 2008 3:27 PM

I was wondering how long it would take you to get this one up an running :)

When I try to run your form, I receive an "Error instantiating class" message. It is looking for a path "..\aavfpx\gdiplusxfull20080109\source\gdiplusx" which I don't have. If I try to Locate it (in gdilightbox.vcx) I get another error "Cannot find imgcanvas in gdilightbox.vcx".

FYI, I've downloaded the latest GDIPLUSX.

What am I doing wrong?

I dont include the gdiplusc.vcx since you need that from VFPx.

Just open the form in VFP and when it asks you for the Imgcanvas navigate it to the gdiplusx.vcx on your computer. The form will then resolve the location correctly. Save the form, set the default path to the directory where the form is (to find the images) and then run the form. I have subclassed the imgcanvas class from the gdiplusx.vcx class library. Unfortunately this would happen since I don't supply the gdiplusx.vcx and I don't know where a user might have stored it. Thanks for that anyway. Will make a note in the blog.

MikeS

# re: Emulating the XP Shutdown Effect in VFP9 forms with GDI+ @ Friday, September 26, 2008 2:46 AM

Hmmm... Bernard, I can read you mind. I can see what are you thinking next. Based on the aquarium background of the form, you're thinking of putting an animated fish swimming in there, eh? Nice job by the way.

Good guess Dale. But already done in another soon to be released post. Not in this class though.

Dale

# re: Emulating the XP Shutdown Effect in VFP9 forms with GDI+ @ Friday, September 26, 2008 8:40 AM

Bernard,

If I turn off the title bar of the form, error crops up "LOBITMAP is not an object".
Why is that?
(I turn off title bar for my main form and use my own skin)
Vivek

The code in the BeforeDraw of the imgcanvas class in the lightboxclass:

Local lnTitleHeight, lnLeftBorder, lnTopBorder

lnTitleHeight = Sysmetric(9)

lnLeftBorder = Sysmetric(3)

lnTopBorder = Sysmetric(4)

With _Screen.System.Drawing

* get it once

IF VARTYPE(NVL(This.Parent.oBitmap,"")) # "O"

This.Parent.oBitmap = .Bitmap.FromScreen(Thisform.HWnd,;

lnLeftBorder,;

lnTopBorder+lnTitleHeight,;

ThisForm.Width,;

ThisForm.Height)

This.oGfx.clear(.Color.transparent)

ENDIF

Vivek

This code sets the top boubdary of the image as

lnTopBorder+lnTitleHeight,;

If no title then just change the code to :

lnTopBorder,;  (remove the height of the title bar)

If using a borderless form change 

lnLeftBorder,;

lnTopBorder+lnTitleHeight,;

to

0,;

0+lnTitleHeight

If using your own skin, then you will need to get the height of your skin titlebar and use that. The code segment describes the area to be captured as Left,Top,width,Height so change as needed. It must be within the boundaries of your form or you get the error! You have the source so make the changes.

HTH

Bernard

Vivek Deodhar

# re: Emulating the XP Shutdown Effect in VFP9 forms with GDI+ @ Saturday, September 27, 2008 7:15 AM

Bernard,

Thanks, it is working now. However, activex controls are still on top, but I think that can't be helped. or am I wrong?

Vivek

Of course it is.Smile <img src=" src="/emoticons/emotion-1.gif"> Re Activex, you are wrong. It can be helped and I have done it.

Check my previous blog post:

http://weblogs.foxite.com/bernardbout/archive/2008/09/13/6768.aspx

Now you have the source code for both techniques, you combine them and send it to me.

Vivek Deodhar

What do you think?

(required) 
required 
(required) 
Powered by Community Server, by Telligent Systems