Solved

Preventing the user from bringing a form to front by pressing ALT+ESC

Posted on 1998-08-14
22
231 Views
Last Modified: 2010-04-04
I'm writing a multimedia application which is designed to work
at a resolution of 800x600. Above this resolution I have a black
form in the background which covers the entire desktop. All
my other stuff is shown on another form top of the black
one. However this black form can be brought to front by pressing
ALT+ESC keys.

Is there any solution for preventing the user from bringing my black
form to foreground ?

Any help is greatly appreciated.

Levente
0
Comment
Question by:Levente
  • 6
  • 4
  • 4
  • +5
22 Comments
 
LVL 1

Expert Comment

by:Greedy
ID: 1362131
I would guess that you also want to disable alt-tab too so just use this little procedure here

procedure TurnSysKeysOff;
var
  OldVal : LongInt;
begin
  SystemParametersInfo (97, Word (True), @OldVal, 0)
end;

procedure TurnSysKeysBackOn;
var
  OldVal : LongInt;
begin
  SystemParametersInfo (97, Word (False), @OldVal, 0)
end;

You could also use a single form and put the 800x600 part of your form on a TPanel that is centered on this form.  Then set the form to full screen and give it a black background.  That is if you don't just want to make the form scale...lazy programmer? :)

0
 
LVL 20

Expert Comment

by:Madshi
ID: 1362132
Good comment, Greedy...

Levente, you could also try to disable the black window (enabled:=false) or to show the real window (that is before the black window) with ShowModal.
0
 
LVL 2

Expert Comment

by:333
ID: 1362133
Or maybe you can use an MDI app?
0
 
LVL 1

Expert Comment

by:EmmDieh
ID: 1362134
or set the fsStayOnTop attribute of your foreground window,
if that is an option.
0
 

Author Comment

by:Levente
ID: 1362135
Thank you all for your comments. First of all I must tell you i'm not a lazy programmer :-> Since I'm
developing a multimedia app all the background graphics (approx. 10 forms) are drawn by a graphic
designer and he would go crazy if he had to make the design for 640x480, 800x600, 1024x768 etc...

Greedy, disabling system keys (e.g. alt-tab) is not a nice way of approach, isn't it ? (Though it may work ;-)
On the other hand I've thought of creating an MDI app, but:
- when I try to hide my MDIChild form I get an error message (Cannot hide an MDI child form.)
  so I have to change my FormStyle property before I _show_ and _hide_ my form.
- Since I'm creating a MDIChild form I get an ugly caption and frame around my window. (Though I can
  remove it by overriding Createparams procedure.)

Well, IMHO this seems to be quite a tricky solution.

StayonTop attribute doesn't help since I can place any window between my black background window
and my foreground window.

Do you have any better idea ?

Regards,
Levente
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1362136
Maybe try to show the other form when the black form receives the activate event?
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1362137
Levente, have you tried my suggestions?  :-)
0
 

Expert Comment

by:graemef
ID: 1362138
How about capturing the on-paint event for the black form and using this to set the multimedia window to the foreground and the black to the background. Might flick a bit, but should work.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1362139
hey, guyz.

i'm sure i saw something like "drawing on the desktop" some dayz ago. i just can't remember where that was - right now. when i'm back home this evening, i'm gonna scan my machine 4 it.
it went somehow like ...get handle 4 desktop...use this as target 4 drawing commands...gnagnagna.
i'll find it. & post it 2morrow.

bye,

Black Death.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1362140
To be exact it's:

DC := GetDC(GetDGetDesktopWindow)
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1362141
Ooops...

DC := GetDC(GetDesktopWindow)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Levente
ID: 1362142
Yes, Madshi, I've tried your suggestion. Disabling the black form
doesn't work, neither does the ShowModal procedure (it *might* be my fault).
Since I have to pass some parameters to certain forms I'm doing this:

type
 TForm1 = class(TForm)
    ( ... )
 public
    { Public declarations }
    procedure Show(const A, B, C: Integer);
 end;


procedure Tform1.Show(const A, B, C: Integer);
begin
   ( ... )

   inherited Show;    ( inherited ShowModal result in error: Cannot make a
                  visible window modal.}
end;


Well, what's wrong. Any idea ?

Levente

Ps. As soon as I try drawing to desktop I'll come back.
PS. BTW, I've increased proposed points for you all :-)
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1362143
Have you tried showing the other form when the black form receives the activate event?
0
 
LVL 1

Expert Comment

by:Greedy
ID: 1362144
See if this works for you...I made a new application with two forms.  The Form 1 has 1 button on it with this code

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.Show;
end;

this is the code for form2

procedure TForm2.FormShow(Sender: TObject);
begin
  with Form2 do
  begin
    Tag := 0;
    Top := (Form1.Top + (Form1.Height div 2)) - (Height div 2);
    Left := (Form1.Left + (Form1.Width div 2)) - (Width div 2);
  end;
end;

procedure TForm2.FormDeactivate(Sender: TObject);
begin
  if Form2.Tag <> 1 then
  begin
    SetActiveWindow(Form2.Handle);
  end;
end;

procedure TForm2.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  Form2.Tag := 1;
end;

I set the BorderStyle of Form1 to bsNone and the Color to clBlack.  

I still don't see the reason why your doing it with two forms, maby it will come to me...
0
 
LVL 2

Expert Comment

by:333
ID: 1362145
I have tryed this thing with ALT+ESC and the problem is:
if I press ALT+ESC, the Form1 (the black form) goes on top of Form2, but its NOT active. So I think, that things with OnActivate or OnDeactivate will not work. I use TTimer.
Here is my expample:
There are 2 forms - Form1 (black form) and Form2 (blank form). The Form1 has two buttons ( Button1 to show form2, Button2 to exit) and TTimer.

procedure TForm1.Button1Click(Sender: TObject);
begin
  form2.show;
  OnActivate:=Timer1Timer; {just for prevent flickering}
  timer1.enabled:=true;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
h:THandle;
begin
  GetWindow(h,gw_hwndfirst);
  if h<>Form2.handle then
  BringWindowToTop(form2.handle);
end;

Form2.OnClose event {needed to terminate app} :

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Form1.Timer1.Enabled:=false;
  Form1.OnActivate:=nil;
end;

Maybe it looks a little nasty, but it works.
AP
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1362146
tja.

i did NOT find it. whyever. still searching.
but meanwhile i think it doesn't fit the problem so well.
i mean, after ending your app, u'd have 2 restore everything.
who wantz 2 have a black desktop (but me) ?

i've had a similar problem once:
i wanted 2 display a animated gif in a little rectangle above the system desktop icon. i created a tiny form, used itz complete area 2 display the gif, added a context menu und a drag handler (of course it had no captionbar) - & was unable 2 handle just this problem: Alt-TAB, Alt-ESC, Ctrl-Alt-DEL.

all suggestions here sound good, but itz all kinda workaround the actual problem: there must be simple a way 2 pin anything directly 2 the desktop. & directly means that there's no chance 4 anything 2 slip in between desktop und "pin-up" in z-order. like an immediate child. or something like that. or what.

til later,

Black Death.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1362147
Levente,

please try:
(1) First of all create a whole new project with two forms (first/main window: "BackWin", second window "Form1").
(2) Set BackWin.WindowState:=wsMaximized
(3) Add a button to BackWin
(4) (suggestion 1):
    procedure TBackWin.Button1Click(sender: TObject);
    begin
      enabled:=false;
      LeventesShow(1,2,3);
    end;
    procedure TForm1.LeventesShow(i1,i2,i3: integer);
    begin
      Show;
    end;
    (suggestion 1)
    procedure TBackWin.Button1Blick(sender: TObject);
    begin
      LeventesShow(1,2,3);
    end;
    procedure TForm1.LeventesShow(i1,i2,i3: integer);
    begin
      ShowModal;
    end;
With both suggestions Form1 is always in top of BackWin.
I don't know why (in your example) Form1 is visible already.
Do you call your LeventesShow procedure more than once per form?
There are two important differences between "show" and "showModal":
(1) "show" returns immediately; "showModal" return when the form is closed.
(2) "show" doesn't disable "blackWin"; "showModal" does.
So if you want to use "show", you'll have to disable the "blackWin" yourself (see suggestion 1).

So what is the difference between my samples and your program?
Why do my samples work and your program does not?

Regards, Madshi.
0
 

Author Comment

by:Levente
ID: 1362148
Well, guys, I GOT IT. Somewhere else I was advised the following code:

procedure WindowDeActivate(var Msg: TWMActivate); message WM_ACTIVATE;

( ... )

procedure TfMenu1.WindowDeActivate(var Msg: TWMActivate);
begin
   if Msg.Active=WA_INACTIVE then begin
      SetActiveWindow(fMenu1.Handle);
      BringWindowToTop(fMenu1.Handle);
   end;
end;


Madshi, your code works quite well, too. I'm willing to offer you
the promised points.

Thanx all of you for your work.

Regards,
Levente
0
 
LVL 20

Accepted Solution

by:
Madshi earned 150 total points
ID: 1362149
It seems that you like the "deactivate" method the most. Don't you have flickering with that?
Please accept my answer only if you're using my suggestion. Otherwise reject the answer and delete the question...   :-)

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1362150
Or give the points to someone else...
0
 

Author Comment

by:Levente
ID: 1362151
Madshi,

your code works well, though I've found a better one.
I'm giving you my points 'coz I appreciate your work.

Levente
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1362152
O.k., thanx for your appreciation.  :-)

Regards, Madshi.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now