Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SetForeGround and Peter B's ALT-TAB work around

197 views
Skip to first unread message

Jon Alexander

unread,
Sep 19, 2001, 8:04:22 PM9/19/01
to

I am very grateful for the work around in trying to get the handle of the previously focused / foreground window.

When my app starts I use the alt-tab work around to shift focus to the previous foreground window.

As I change from form to form via system hotkey (WMHotkeys), a conditional of if all forms are nil then perform alt-tab.

My problem is that if a user presses the hotkeys too fast, the alt-tab gets mixed up.

I have presumed that I need to find out how to have my application wait until the alt-tab key sequence is complete before continuing on, OR the order of my code is incorrect.

Any and all help would be greatly appreciated.

Below is the main application 'APPBAR' which is an taskbar like app and is set not visible so alt-tab does not see it:

procedure TAppBarForm1.FormCreate(Sender: TObject);
begin { TAppBarForm1.FormCreate }
Timer1.Enabled := True;
Timer1.Interval := 100;
//--------------------------------
{Simulate an Alt-Tab to switch to the previous application}
keybd_event(VK_MENU, Mapvirtualkey(VK_MENU, 0), 0, 0);
keybd_event(VK_TAB, Mapvirtualkey(VK_TAB, 0), 0, 0);
keybd_event(VK_TAB, Mapvirtualkey(VK_TAB, 0), KEYEVENTF_KEYUP,
0);
keybd_event(VK_MENU, Mapvirtualkey(VK_MENU, 0), KEYEVENTF_KEYUP,
0);
//--------------------------------
AppBarForm1.SetEnabled(false); { keep user from accessing appbar }
AppBarForm1.HorzDockSize := 20; { sets fixed size for app bar height }
AppBarForm1.AlwaysOnTop := True; { sets appbar to Always On Top of All Apps }
AppBarForm1.SetEdge(abeTOP); { sets appbar docking edge to TOP }
AppBarForm1.UpdateBar; { updates / refreshes appbar display }
RegisterHotKey(AppBarForm1.Handle, 5, 0, VK_F5); { FORM 5 register system hotkey }
RegisterHotKey(AppBarForm1.Handle, 6, 0, VK_F6); { FORM 6 register system hotkey }
RegisterHotKey(AppBarForm1.Handle, 7, 0, VK_F7); { FORM 7 register system hotkey }
RegisterHotKey(AppBarForm1.Handle, 8, 0, VK_F8); { FORM 8 register system hotkey }
RegisterHotKey(AppBarForm1.Handle, 9, 0, VK_F9); { FORM 9 register system hotkey }
RegisterHotKey(AppBarForm1.Handle, 10, 0, VK_F10); { CLOCKS FORM register system hotkey }
RegisterHotKey(AppBarForm1.Handle, 11, 0, VK_F11); { EXIT APP register system hotkey }
Form5 := nil; { sets FORM 5 variable to nil for hotkey create cycle }
Form6 := nil; { sets FORM 6 variable to nil for hotkey create cycle }
Form7 := nil; { sets FORM 7 variable to nil for hotkey create cycle }
Form8 := nil; { sets FORM 8 variable to nil for hotkey create cycle }
Form9 := nil; { sets FORM 9 variable to nil for hotkey create cycle }
Form10 := nil; { sets FORM 10 variable to nil for hotkey create cycle }
hTaskBarWnd := FindWindow('Shell_TrayWnd', nil) { sets windows taskbar variable }
end; { TAppBarForm1.FormCreate }


The below is one of 6 hotkeys that create individual forms.

The code order problem, I believe is in the form close, below.

procedure TAppBarForm1.WMHotKey(var Msg: TWMHotKey);
begin { TAppBarForm1.WMHotKey }
//--------------------------------
if Msg.HotKey = 5 then begin { Form5 system hotkey open / close }
Msg.Result := 0; { eats system hotkey and prevents from affecting other apps }
if Form5 = nil then begin { if Form5 does not exist then }
ShowWindow(hTaskBarWnd, SW_HIDE); { hide windows taskbar }
Application.CreateForm(TForm5, Form5) { create Form5 }
end { Form5 = nil }
else begin
if Form5 <> nil then begin { if Form5 does exists then }
ShowWindow(hTaskBarWnd, SW_Show); { show windows taskbar }
Form5.Close; { close Form5 }
end; { Form5 <> nil }
end; { not (Form5 = nil) }
end; { Msg.HotKey = 5 }
//--------------------------------

On Form create I close all other forms:

procedure TForm5.FormCreate(Sender: TObject);
begin { TForm5.FormCreate } { closes all other forms on creation }
Application.NormalizeAllTopMosts; { clears system Z order }
SetWindowPos(Form5.Handle, HWND_TopMost, 0, 0, 0, 0, SWP_NoMove or
SWP_NoSize or SWP_NoActivate); { sets window absolute ON TOP }
BringWindowToTop(Form5.Handle); { bring window to top of z order }
SetForegroundWindow(Form5.Handle); { shifts keyboard focus to window }
Form5.Color := $008080FF; { set background color of form }
Form5.BorderStyle := bsNone; { make form borderless }
Form5.Align := alTOP; { set form align to top for maximum screen usage }
Form5.Height := Screen.Height; { set form to screen height }
Form5.Visible := True; { show form AFTER setting form properties }
Form5.SetFocus; { set keyboard focus to Form }
Form5.BringToFront; { bring Form to front }
//------------------------------ forces all forms to close
if Form6 <> nil then begin
Form6.Close
end; { Form6 <> nil }
if Form7 <> nil then begin
Form7.Close
end; { Form7 <> nil }
if Form8 <> nil then begin
Form8.Close
end; { Form8 <> nil }
if Form9 <> nil then begin
Form9.Close
end; { Form9 <> nil }
if Form10 <> nil then begin
Form10.Close
end; { Form10 <> nil }
end; { TForm5.FormCreate }

On Form Close, is where I believe the code order is wrong or I need to add something to have the alt-tab key sequence complete before my app continues:

procedure TForm5.FormClose(Sender: TObject; var Action: TCloseAction);
begin { TForm5.FormClose }
{ only shows windows taskbar if all forms are closed }
if Form5 = nil then begin
if Form6 = nil then begin
if Form7 = nil then begin
if Form8 = nil then begin
if Form9 = nil then begin
if Form10 = nil then begin
{Simulate an Alt-Tab to switch to the previous application}
Application.ProcessMessages;
keybd_event(VK_MENU, Mapvirtualkey(VK_MENU, 0), 0,
0);
keybd_event(VK_TAB, Mapvirtualkey(VK_TAB, 0), 0,
0);
keybd_event(VK_TAB, Mapvirtualkey(VK_TAB, 0), KEYEVENTF_KEYUP,
0);
keybd_event(VK_MENU, Mapvirtualkey(VK_MENU, 0), KEYEVENTF_KEYUP,
0);
end; { Form10 = nil }
end; { Form9 = nil }
end; { Form8 = nil }
end; { Form7 = nil }
end; { Form6 = nil }
end; { Form5 = nil }
Form5 := nil; { reset Form Variable to nil for app hotkey cycle REQUIRED }
Action := CAFree; { free Form from memory }
end; { TForm5.FormClose }


Thank you.

Please advise, should you have time.

Cordially,

Jon Alexander
jal...@hotmail.com


Paul Nicholls

unread,
Sep 20, 2001, 1:20:52 AM9/20/01
to
You should post attachments to the borland.public.attachments newsgroup
instead...

--
Paul Nicholls (Delphi 5) Live long and optimise!
"Life is a beach - every so often you are swept out to sea by a rip and get
into trouble!" - Paul Nicholls

Home Page: www.southcom.com.au/~phantom
< IF YOU WANT TO EARN MONEY WHILE YOU SURF ON THE NET GO HERE: >
< http://www.alladvantage.com/go.asp?refid=BEM-274 >


Anthony Richardson (Viewpoint SA)

unread,
Sep 20, 2001, 1:55:41 AM9/20/01
to
"Paul Nicholls" <paul_f_...@hotmail.com> wrote in message
news:3ba97c21_1@dnews...

> You should post attachments to the borland.public.attachments newsgroup
> instead...

Paul,

Jon's post didn't actually have an attachment, outlook express incorrectly
thinks it does for whatever reason. If you select File|Properties > Details
> Message Source, you can see the post as Jon intended it.

Cheers,

Anthony Richardson
ant...@viewpointsa.com


David J Taylor

unread,
Sep 20, 2001, 4:28:44 AM9/20/01
to
"Anthony Richardson (Viewpoint SA)" <ant...@viewpointsa.com> wrote in
message news:3ba98533_2@dnews...

> Paul,
>
> Jon's post didn't actually have an attachment, outlook express
incorrectly
> thinks it does for whatever reason. If you select File|Properties >
Details
> > Message Source, you can see the post as Jon intended it.

Anthony, it seems the OE interprets a line starting "Begin" as the start
of an attachment. Presumably the start of a MIME or UUencoded stream or
something!

David

Chris Luck

unread,
Sep 20, 2001, 10:00:47 PM9/20/01
to
"David J Taylor" <david-...@blueyonder.co.uk> wrote in message
news:3ba9a8bc$1_2@dnews...

> Anthony, it seems the OE interprets a line starting "Begin" as the start
> of an attachment. Presumably the start of a MIME or UUencoded stream or
> something!

It is indeed the Outlook Express "Begin" bug. MS know about it and show no
inclination to deal with it ("a rare bug").

Trigger -
Any line starting with the word "Begin" and followed by at least two spaces
plus at least two other characters which can also be spaces. i.e. "Begin"
followed by four spaces will trigger it - that can catch you out even when
you know about the problem. It is usually triggered, as here, by the
inclusion of "helpful" notes! "Begin" followed by one space + text will not
trigger it.

Symptoms -
The appearance of a spurious attachment (with rubbish content) and
truncation of the message in the preview pane.

Sending in HTML prevents the creation of the attachment but that won't go
down well in these ng's, of course. The bug exists in all versions of OE5
and persists in OE6. Thank you, Mr. Gates.

I would recommend Outlook Express users to be familiar with using Ctrl+F3 to
view the plain-text message source.


--
Regards,
Chris Luck


Jon Alexander

unread,
Sep 20, 2001, 10:56:45 AM9/20/01
to

I hope I made the proper corrections, as I did not have any attachments, as noted, but I learned something about using Outlook, but also, I did not post via Outlook. I posted on the web site via IE browser.

I really need to find out how to solve the below problem as it dramatically affects the quality of my application, the below code works AS LONG AS the user does not hit the hotkeys that switch between the various form creations TOO FAST, as the ALT-TAB gets mixed up, also, the problem may also be affected by the hiding and showing of the windows taskbar and the resetting of the z order of the newly created form. I have a 186k compiled version of the app, which is easy to demonstrate the problem.

Anyone have any ideas?

Please advise.

Cordially,

Jon Alexander
jal...@hotmaill.com

Jon Alexander

unread,
Sep 20, 2001, 11:05:36 AM9/20/01
to

Thank you, I really appreciate the professionalism and ettiquete of the Borland Development newsgroups, as noted I did not have any attachments, but also, I did not post via Outlook Express, but posted via the web site with IE.

Thank you.

Cordially,


Jon Alexander
jal...@hotmail.com

ps. Chris, I do have a 186k compiled version of the code that I was having a problem with, it makes it very easy to see the problem I am having. The app works great EXCEPT if the user switches between forms TOO FAST via hotkey form creates then ALT-TAB gets mixed up in the keyboard buffer and the flow order of keyboard delivery mixes up, the ALT-TAB is not waiting for the conditional check if all forms are closed before executing, the problem may be with the conditional of 'if form = nil'.

Any suggestions?

Thank you.

David J Taylor

unread,
Sep 20, 2001, 11:44:44 AM9/20/01
to
Jon,

The fault is in viewing the messages with OE, not when posting. I hope
you get an answer to your problems, though.

David

"Jon Alexander" <jal...@hotmail.com> wrote in message
news:3baa05c0$2_1@dnews...

Jon Alexander

unread,
Sep 20, 2001, 1:43:51 PM9/20/01
to

Thanks for the info, also, I solved my problem and will post for others to use, it was in the close method and the code execution order.

Cordially,

Jon Alexander
jal...@hotmail.com

Jon Alexander

unread,
Sep 20, 2001, 1:50:43 PM9/20/01
to

Note: There may be some redundancy in the code with the focus but right now it works, clean up later.

The answer was a combination of the close method.

I used free instead and have found that close is still called for the form, also the show and hide task bar needs to be called after the free method.

It works sooooo great now! I can hit multiple hotkeys a hundred times and watch my screen flash and the keyboard buffer keeps its order.

Below is the code for others to use:

MAIN APPLICATION CODE:

unit AppBarUnit1;

interface

uses
AppBar, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
ExtCtrls, StdCtrls;

type
TAppBarForm1 = class(TAppBar)
pnl_DateTime: TPanel;
lbl_Date: TLabel;
lbl_Time: TLabel;
lbl_FormName: TLabel;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
public
{ Public declarations }
end;

var
AppBarForm1: TAppBarForm1;
x : string; { date variable for conversion }
y : string; { time variable for conversion }
textZ: string; { current window focus title variable for text }
vivoZ: integer; { current window focus title variable for size }
winZ: HWnd; { current window focus variable }
hTaskBarWnd: HWnd;
{ variable to show & hide windows taskbar }
implementation

uses
Form5Unit5, Form6Unit6, Form7Unit7, Form8Unit8, Form9Unit9, Form10Unit10;

{$R *.DFM}

procedure TAppBarForm1.Timer1Timer(Sender: TObject);
begin { TAppBarForm1.Timer1Timer }
DateTimeToString(x, 'ddd MMM DD YYYY', now); { convert current date format }
DateTimeToString(y, 'hh:mm:ss AM/PM', now); { convert current time }
AppBarForm1.lbl_Date.Caption := 'F5-F6-F7-F8-F9-F10' + #13#10 + UpperCase(x); { set formatted date to label }
AppBarForm1.lbl_Time.Caption := 'F11 EXIT' + #13#10 + UpperCase(y); { set formatted time to label }
winZ := GetForegroundWindow; { set keyboard focused window variable }
if winZ > 0 then begin { if it has a caption title then }
SetLength(textZ, 256); { set window title length }
vivoZ := GetWindowText(winZ, PChar(textZ), 256);
SetLength(textZ, vivoZ);
AppBarUnit1.AppBarForm1.lbl_FormName.Caption := textZ;
//------------------------ keeps appbar continuously on top via timer


AppBarForm1.AlwaysOnTop := True; { sets appbar to Always On Top of All Apps }
AppBarForm1.SetEdge(abeTOP); { sets appbar docking edge to TOP }
AppBarForm1.UpdateBar { updates / refreshes appbar display }

end; { winZ > 0 }
end; { TAppBarForm1.Timer1Timer }

procedure TAppBarForm1.FormCreate(Sender: TObject);
begin { TAppBarForm1.FormCreate }
Timer1.Enabled := True;
Timer1.Interval := 100;

procedure TAppBarForm1.WMHotKey(var Msg: TWMHotKey);


begin { TAppBarForm1.WMHotKey }
//--------------------------------
if Msg.HotKey = 5 then begin { Form5 system hotkey open / close }
Msg.Result := 0; { eats system hotkey and prevents from affecting other apps }
if Form5 = nil then begin { if Form5 does not exist then }
ShowWindow(hTaskBarWnd, SW_HIDE); { hide windows taskbar }

//----forces all forms closed
if Form5 <> nil then begin Form5.Free; end; { Form5 <> nil }
if Form6 <> nil then begin Form6.Free; end; { Form6 <> nil }
if Form7 <> nil then begin Form7.Free; end; { Form7 <> nil }
if Form8 <> nil then begin Form8.Free; end; { Form8 <> nil }
if Form9 <> nil then begin Form9.Free; end; { Form10 <> nil }
if Form10 <> nil then begin Form10.Free; end; { Form10 <> nil }


Application.CreateForm(TForm5, Form5) { create Form5 }
end { Form5 = nil }
else begin
if Form5 <> nil then begin { if Form5 does exists then }

Form5.Free; { close Form5 }


ShowWindow(hTaskBarWnd, SW_Show); { show windows taskbar }

end; { Form5 <> nil }
end; { not (Form5 = nil) }
end; { Msg.HotKey = 5 }
//--------------------------------

if Msg.HotKey = 6 then begin { Form6 system hotkey open / close }


Msg.Result := 0; { eats system hotkey and prevents from affecting other apps }

if Form6 = nil then begin { if Form6 does not exist then }


ShowWindow(hTaskBarWnd, SW_HIDE); { hide windows taskbar }

//----forces all forms closed
if Form5 <> nil then begin Form5.Free; end; { Form5 <> nil }
if Form6 <> nil then begin Form6.Free; end; { Form6 <> nil }
if Form7 <> nil then begin Form7.Free; end; { Form7 <> nil }
if Form8 <> nil then begin Form8.Free; end; { Form8 <> nil }
if Form9 <> nil then begin Form9.Free; end; { Form10 <> nil }
if Form10 <> nil then begin Form10.Free; end; { Form10 <> nil }
Application.CreateForm(TForm6, Form6) { create Form6 }
end { Form6 = nil }
else begin
if Form6 <> nil then begin { if Form6 does exists then }
Form6.Free; { close Form6 }


ShowWindow(hTaskBarWnd, SW_Show); { show windows taskbar }

end; { Form6 <> nil }
end; { not (Form6 = nil) }
end; { Msg.HotKey = 6 }
//--------------------------------
if Msg.HotKey = 7 then begin { Form7 system hotkey open / close }


Msg.Result := 0; { eats system hotkey and prevents from affecting other apps }

if Form7 = nil then begin { if Form7 does not exist then }


ShowWindow(hTaskBarWnd, SW_HIDE); { hide windows taskbar }

//----forces all forms closed
if Form5 <> nil then begin Form5.Free; end; { Form5 <> nil }
if Form6 <> nil then begin Form6.Free; end; { Form6 <> nil }
if Form7 <> nil then begin Form7.Free; end; { Form7 <> nil }
if Form8 <> nil then begin Form8.Free; end; { Form8 <> nil }
if Form9 <> nil then begin Form9.Free; end; { Form10 <> nil }
if Form10 <> nil then begin Form10.Free; end; { Form10 <> nil }
Application.CreateForm(TForm7, Form7) { create Form7 }
end { Form7 = nil }
else begin
if Form7 <> nil then begin { if Form7 does exists then }
Form7.Free; { close Form7 }


ShowWindow(hTaskBarWnd, SW_Show); { show windows taskbar }

end; { Form7 <> nil }
end; { not (Form7 = nil) }
end; { Msg.HotKey = 7 }
//--------------------------------
if Msg.HotKey = 8 then begin { Form8 system hotkey open / close }


Msg.Result := 0; { eats system hotkey and prevents from affecting other apps }

if Form8 = nil then begin { if Form8 does not exist then }


ShowWindow(hTaskBarWnd, SW_HIDE); { hide windows taskbar }

//----forces all forms closed
if Form5 <> nil then begin Form5.Free; end; { Form5 <> nil }
if Form6 <> nil then begin Form6.Free; end; { Form6 <> nil }
if Form7 <> nil then begin Form7.Free; end; { Form7 <> nil }
if Form8 <> nil then begin Form8.Free; end; { Form8 <> nil }
if Form9 <> nil then begin Form9.Free; end; { Form10 <> nil }
if Form10 <> nil then begin Form10.Free; end; { Form10 <> nil }
Application.CreateForm(TForm8, Form8) { create Form8 }
end { Form8 = nil }
else begin
if Form8 <> nil then begin { if Form8 does exists then }
Form8.Free; { close Form8 }


ShowWindow(hTaskBarWnd, SW_Show); { show windows taskbar }

end; { Form8 <> nil }
end; { not (Form8 = nil) }
end; { Msg.HotKey = 8 }
//--------------------------------
if Msg.HotKey = 9 then begin { Form9 system hotkey open / close }


Msg.Result := 0; { eats system hotkey and prevents from affecting other apps }

if Form9 = nil then begin { if Form9 does not exist then }


ShowWindow(hTaskBarWnd, SW_HIDE); { hide windows taskbar }

//----forces all forms closed
if Form5 <> nil then begin Form5.Free; end; { Form5 <> nil }
if Form6 <> nil then begin Form6.Free; end; { Form6 <> nil }
if Form7 <> nil then begin Form7.Free; end; { Form7 <> nil }
if Form8 <> nil then begin Form8.Free; end; { Form8 <> nil }
if Form9 <> nil then begin Form9.Free; end; { Form10 <> nil }
if Form10 <> nil then begin Form10.Free; end; { Form10 <> nil }
Application.CreateForm(TForm9, Form9) { create Form9 }
end { Form9 = nil }
else begin
if Form9 <> nil then begin { if Form9 does exists then }
Form9.Free; { close Form9 }


ShowWindow(hTaskBarWnd, SW_Show); { show windows taskbar }

end; { Form9 <> nil }
end; { not (Form9 = nil) }
end; { Msg.HotKey = 9 }
//--------------------------------
if Msg.HotKey = 10 then begin { Form10 system hotkey open / close }


Msg.Result := 0; { eats system hotkey and prevents from affecting other apps }

if Form10 = nil then begin { if Form10 does not exist then }


ShowWindow(hTaskBarWnd, SW_HIDE); { hide windows taskbar }

//----forces all forms closed
if Form5 <> nil then begin Form5.Free; end; { Form5 <> nil }
if Form6 <> nil then begin Form6.Free; end; { Form6 <> nil }
if Form7 <> nil then begin Form7.Free; end; { Form7 <> nil }
if Form8 <> nil then begin Form8.Free; end; { Form8 <> nil }
if Form9 <> nil then begin Form9.Free; end; { Form10 <> nil }
if Form10 <> nil then begin Form10.Free; end; { Form10 <> nil }
Application.CreateForm(TForm10, Form10) { create Form10 }
end { Form10 = nil }
else begin
if Form10 <> nil then begin { if Form10 does exists then }
Form10.Free; { close Form10 }


ShowWindow(hTaskBarWnd, SW_Show); { show windows taskbar }

end; { Form10 <> nil }
end; { not (Form10 = nil) }
end; { Msg.HotKey = 10 }
//--------------------------------
if Msg.HotKey = 11 then begin { EXIT APP system hotkey }


Msg.Result := 0; { eats system hotkey and prevents from affecting other apps }

AppBarForm1.Close { exit application }
end; { Msg.HotKey = 11 }
end; { TAppBarForm1.WMHotKey }

procedure TAppBarForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin { TAppBarForm1.FormClose }
Timer1.Enabled := false;
UnRegisterHotKey(AppBarForm1.Handle, 5); { FORM 5 UNregister system hotkey }
UnRegisterHotKey(AppBarForm1.Handle, 6); { FORM 6 UNregister system hotkey }
UnRegisterHotKey(AppBarForm1.Handle, 7); { FORM 7 UNregister system hotkey }
UnRegisterHotKey(AppBarForm1.Handle, 8); { FORM 8 UNregister system hotkey }
UnRegisterHotKey(AppBarForm1.Handle, 9); { FORM 9 UNregister system hotkey }
UnRegisterHotKey(AppBarForm1.Handle, 10); { CLOCKS FORM UNregister system hotkey }
UnRegisterHotKey(AppBarForm1.Handle, 11); { EXIT APP UNregister system hotkey }


ShowWindow(hTaskBarWnd, SW_Show); { show windows taskbar }

AppBarForm1.ResetSystemKnowledge; { refresh screen write without app bar }
Action := CAFree; { free application memory }
end; { TAppBarForm1.FormClose }

procedure TAppBarForm1.FormDestroy(Sender: TObject);
begin { TAppBarForm1.FormDestroy }
UnRegisterHotKey(AppBarForm1.Handle, 5); { FORM 5 UNregister system hotkey }
UnRegisterHotKey(AppBarForm1.Handle, 6); { FORM 6 UNregister system hotkey }
UnRegisterHotKey(AppBarForm1.Handle, 7); { FORM 7 UNregister system hotkey }
UnRegisterHotKey(AppBarForm1.Handle, 8); { FORM 8 UNregister system hotkey }
UnRegisterHotKey(AppBarForm1.Handle, 9); { FORM 9 UNregister system hotkey }
UnRegisterHotKey(AppBarForm1.Handle, 10); { CLOCKS FORM UNregister system hotkey }
UnRegisterHotKey(AppBarForm1.Handle, 11); { EXIT APP UNregister system hotkey }


ShowWindow(hTaskBarWnd, SW_Show); { show windows taskbar }

AppBarForm1.Close; { close application }
AppBarForm1.ResetSystemKnowledge { refresh screen write without app bar }
end; { TAppBarForm1.FormDestroy }

end.

FORM CODE (note the other forms are identical with exception to the part of the code that references its own form)

unit Form5Unit5;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm5 = class(TForm)
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form5: TForm5;

implementation

uses
Form6Unit6, Form7Unit7, Form8Unit8, Form9Unit9, Form10Unit10;

{$R *.DFM}

procedure TForm5.FormCreate(Sender: TObject);
begin { TForm5.FormCreate }

Form5.Color := $008080FF; { set background color of form }
Form5.BorderStyle := bsNone; { make form borderless }
Form5.Align := alTOP; { set form align to top for maximum screen usage }
Form5.Height := Screen.Height; { set form to screen height }
Form5.Visible := True; { show form AFTER setting form properties }
Form5.SetFocus; { set keyboard focus to Form }
Form5.BringToFront; { bring Form to front }

//------------------------------ sets z order and focus


Application.NormalizeAllTopMosts; { clears system Z order }
SetWindowPos(Form5.Handle, HWND_TopMost, 0, 0, 0, 0, SWP_NoMove or
SWP_NoSize or SWP_NoActivate); { sets window absolute ON TOP }
BringWindowToTop(Form5.Handle); { bring window to top of z order }
SetForegroundWindow(Form5.Handle); { shifts keyboard focus to window }

end; { TForm5.FormCreate }

procedure TForm5.FormClose(Sender: TObject; var Action: TCloseAction);
begin { TForm5.FormClose }

Form5 := nil; { reset Form Variable to nil for app hotkey cycle REQUIRED }
Action := CAFree; { free Form from memory }

{Simulate an Alt-Tab to switch to the previous application}
keybd_event(VK_MENU, Mapvirtualkey(VK_MENU, 0), 0, 0);
keybd_event(VK_TAB, Mapvirtualkey(VK_TAB, 0), 0, 0);
keybd_event(VK_TAB, Mapvirtualkey(VK_TAB, 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_MENU, Mapvirtualkey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);

end; { TForm5.FormClose }

procedure TForm5.FormDestroy(Sender: TObject);
begin { TForm5.FormDestroy }
Close { process close actions }
end; { TForm5.FormDestroy }

end.


FORM 6 INCLUDED TO SHOW DIFFERENCES or CHANGES BETWEEN FORMS:

unit Form6Unit6;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm6 = class(TForm)
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form6: TForm6;

implementation

uses
Form5Unit5, Form7Unit7, Form8Unit8, Form9Unit9, Form10Unit10;

{$R *.DFM}

procedure TForm6.FormCreate(Sender: TObject);
begin { TForm6.FormCreate }
Form6.Color := $0080FFFF; { set background color of form }
Form6.BorderStyle := bsNone; { make form borderless }
Form6.Align := alTOP; { set form align to top for maximum screen usage }
Form6.Height := Screen.Height; { set form to screen height }
Form6.Visible := True; { show form AFTER setting form properties }
Form6.SetFocus; { set keyboard focus to Form }
Form6.BringToFront; { bring Form to front }
//------------------------------ sets z order and focus


Application.NormalizeAllTopMosts; { clears system Z order }

SetWindowPos(Form6.Handle, HWND_TopMost, 0, 0, 0, 0, SWP_NoMove or


SWP_NoSize or SWP_NoActivate); { sets window absolute ON TOP }

BringWindowToTop(Form6.Handle); { bring window to top of z order }
SetForegroundWindow(Form6.Handle); { shifts keyboard focus to window }
end; { TForm6.FormCreate }

procedure TForm6.FormClose(Sender: TObject; var Action: TCloseAction);
begin { TForm6.FormClose }
Form6 := nil; { reset Form Variable to nil for app hotkey cycle REQUIRED }


Action := CAFree; { free Form from memory }

{Simulate an Alt-Tab to switch to the previous application}
keybd_event(VK_MENU, Mapvirtualkey(VK_MENU, 0), 0, 0);
keybd_event(VK_TAB, Mapvirtualkey(VK_TAB, 0), 0, 0);
keybd_event(VK_TAB, Mapvirtualkey(VK_TAB, 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_MENU, Mapvirtualkey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);

end; { TForm6.FormClose }

procedure TForm6.FormDestroy(Sender: TObject);
begin { TForm6.FormDestroy }
Close { process close actions }
end; { TForm6.FormDestroy }

end.


Ryan J. Mills

unread,
Sep 20, 2001, 2:13:45 PM9/20/01
to
"Jon Alexander" <jal...@hotmail.com> wrote in message
news:3baa03ad$1_1@dnews...

>
> I really need to find out how to solve the below problem as it
dramatically affects the quality of my application, the below code works AS
LONG AS the user does not hit the hotkeys that switch between the various
form creations TOO FAST, as the ALT-TAB gets mixed up, also, the problem may
also be affected by the hiding and showing of the windows taskbar and the
resetting of the z order of the newly created form. I have a 186k compiled
version of the app, which is easy to demonstrate the problem.
>
> Anyone have any ideas?
>
> Please advise.
>


I've taken a look at the code but I'm still not sure what it is your trying
to accomplish?

Ryan.


Jon Alexander

unread,
Sep 20, 2001, 2:33:01 PM9/20/01
to

The ALT-TAB alternated between previous focus app, the below is the corrected code:

NOTE the problem was in the closing method.

MAIN APPLICATION:

unit AppBarUnit1;

interface

{$R *.DFM}

end.


FORM CODE: (ALL OTHER FORMS ARE IDENTICAL WITH EXCEPTION TO THEIR OWN REFERENCES)

unit Form5Unit5;

interface

{$R *.DFM}

end; { TForm5.FormClose }

procedure TForm5.FormDestroy(Sender: TObject);
begin { TForm5.FormDestroy }
Close { process close actions }
end; { TForm5.FormDestroy }

end.


SECOND FORM CODE: (ALL OTHER FORMS ARE IDENTICAL WITH EXCEPTION TO THEIR OWN REFERENCES)

unit Form6Unit6;

interface

{$R *.DFM}

Chris Luck

unread,
Sep 20, 2001, 8:31:45 PM9/20/01
to
"Jon Alexander" <jal...@hotmail.com> wrote in message
news:3baa05c0$2_1@dnews...

>
> Thank you, I really appreciate the professionalism and ettiquete of the
> Borland Development newsgroups, as noted I did not have any attachments,
> but also, I did not post via Outlook Express, but posted via the web site
> with IE.

My apologies for leaving you with the impression that I was expecting you,
as a non-OE user, to take any action at all. As David pointed out it is
specifically a viewing problem, though those that are aware of the issue can
avoid confusion in the Outlook Express camp if they refrain from adding
comments (or anything else) to a line that starts "begin". Alternatively,
you can side-step the bug by putting one or more spaces before "begin", then
it doesn't matter what follows.


I am pleased to see from your later messages that you fixed the original
problem by your own efforts. Pleased partly because, as with Ryan, I
haven't quite understood the plot. :)


--
Regards,
Chris Luck


0 new messages