How to grayscale the screen for a period of time


Using Delphi 7

i want to fade the screen to gray to prevent user input, just like xp does when changing themes or Avast when disable shields. i want it to cover the whole screen including the taskbar, i will search in disabling user input later, but what i need is the fading to gray screen, any idea or code ?
avast.JPG
AgentAmineAsked:
Who is Participating?
 
CodedKCommented:
This is an old Delphi 7 source i had in my folders... So it should work !


Create a Delphi 7 Form.
Inside drop an Image component and set its Align property to alClient.


On Form Create :

procedure TForm1.FormCreate(Sender: TObject);
var
  DeskTop : TCanvas ;
  X,Y: Integer;

begin
  DeskTop := TCanvas.Create ;
  Image1.Picture.Bitmap.Canvas.Brush.Style := bsSolid;
  Image1.Picture.Bitmap.Width := Screen.Width;
  Image1.Picture.Bitmap.Height := Screen.Height;
  try
    with DeskTop do
      Handle := GetWindowDC (GetDesktopWindow) ;

    with Image1.Picture.BitMap.Canvas do
      CopyRect (Rect (0, 0, Screen.Width, Screen.Height), DeskTop,
                        Rect (0, 0, Screen.Width, Screen.Height))

  finally
    DeskTop.Free
  end;
  x := 0;
  y := 0;
  while y < Screen.Height do
  begin
    Image1.Picture.Bitmap.Canvas.MoveTo(0, y);
    Image1.Picture.Bitmap.Canvas.LineTo(Screen.Width, y+Screen.Width);
    Inc(y,2);
  end;
  while x < Screen.Width do
  begin
    Image1.Picture.Bitmap.Canvas.MoveTo(x, 0);
    Image1.Picture.Bitmap.Canvas.LineTo(x+Screen.Height, Screen.Height);
    Inc(x,2);
  end;
end;


Change :
WindowState property to wsMaximize.


I just compiled it with Delphi 2007, this is the code you can write it and compile it
0
 
pgnatyukCommented:
Actually there is a special API - EnableWindow that enable or disable the mouse and keyboard input:
http://msdn.microsoft.com/en-us/library/ms646291(VS.85).aspx

I do not know if it will work for the desktop. Probably not. If you have a lot of memory, you can grab the desktop into a bitmap, make your own window that will cover the desktop and show this bitmap (with any graphic event).

Here is an article about such things:
http://www.codeproject.com/KB/winsdk/AntonioWinLock.aspx

You can use hooking, if you need. For example, here a way proposed by Microsoft:
http://support.microsoft.com/?kbid=226359

There is a special style: WS_EX_TOPMOST
I think you simply need to use this style.
http://msdn.microsoft.com/en-us/library/ms632680(VS.85).aspx

You can try to apply that:
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_TOPMOST);

You can read this article:
A more powerful Delphi Form
http://delphi.about.com/od/formsdialogs/l/aa073101b.htm

0
 
CodedKCommented:
Hi AgentAnime,

I've uploaded an example here:

www.jump.fm/LXPMI

Hope this will help you. You can also disable desktop with enable disable window Api.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
CodedKCommented:
0
 
AgentAmineAuthor Commented:

@pgnatyuk:: thanks for your comment, the links are useful, but not exactly what i want

@CodedK : i appreciate your work, but i just could not compile it (using delphi 7, "image1.ExplicitWidth property does not exit") !!
0
 
AgentAmineAuthor Commented:
thanks CodedK, this is what iam looking for,
BUT, what about the fading motion ?
0
 
CodedKCommented:
This is not hard i guess.
You ve got to set a timer and do 3 or 4 sequential passes.
0
 
cebassoCommented:
Hello,
Thanks @CodeK, i have searched for this too!
I have improved your code just a little... with the fade out effect and with other grayscale effect...
i don't wanna points for this!

http://www.sunsetsolutions.com.br/priv/grayscreen.zip
Regards
0
 
AgentAmineAuthor Commented:

You helped me alot, so thanks to both of you

@cebasso : thanks for responding, your code was really usefullllll

@CodedK : You are right, this is not so hard to do,  forgive my ignorance,  i'm not a good programmer. the points are yours.

Regards
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.