ActiveX pop-up dialogue window hides IE from tasklist - delphi

This seems to only happen in IE6
I have an activex form written in Delphi 7. A dialogue window opened from within the activex control in IE6 gets displayed on the taskbar - the users (for some reason) do not want the dialogue to show in the taskbar.
So I set the dialogue's borderStyle to bsToolwindow. This hides the dialogue from the taskbar but also has the (side-) effect of hiding IE from the task list in windows, which means that you cannot <alt>Tab back to IE if you tabbed away.
Question: How to hide the activex pop-up dialogue from the taskbar but still have IE6 listed in the tasklist?

Set the owner window of your form to be the activex form (or perhaps the ie window). You can achieve this f.i. by passing the activex form as the owner component while you're creating your form and overriding CreateParams of the instantiated form:
// in the activex form's unit
procedure TActiveFormX.Button1Click(Sender: TObject);
var
f: TForm;
begin
f := TForm1.Create(Self);
f.BorderStyle := bsToolWindow;
f.Show;
end;
// in the dialog unit
type
TForm1 = class(TForm)
private
protected
procedure CreateParams(var Params: TCreateParams); override;
[...]
[...]
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.WndParent := TCustomForm(Owner).Handle;
end;

Related

Delphi Vcl Metro application issue when minimizing then maximizing application

I've written a Vcl Metro application with several forms that I have to open sequentially.
I'm using Rad Studio 10.1 Berlin
I've added a button on every form to miminize application if user need it.
The issue happens when:
1) Open main form
2) Open second form
3) Open third form
4) Minimize application
5) Restore application.
At point 5 (when click on desktop bar to maximize application) the application will show Form2 instead of form3
The code
//On Main form (Form1)
procedure TForm1.Button2Click(Sender: TObject);
begin
if not Assigned(form2) then
form2:=tform2.Create(self);
form2.show;
form2.BringToFront;
end;
//On Second form (Form2)
procedure TForm2.Button2Click(Sender: TObject);
begin
if not Assigned(form3) then
form3:=tform3.Create(self);
form3.show;
form3.BringToFront;
end;
//On third Form
procedure TForm3.Button1Click(Sender: TObject);
begin
APPLICATION.Minimize;
end;

How to hide an application from taskbar in Windows 7?

I would like to hide an application from the Windows 7 taskbar.
I want to make something like a toolbar on the edge of the screen which does certain things when the user clicks on it, but I don't want it to show in the taskbar, since its a thing that i want to stay in the background.
I tried the instructions in the following post, but it did not work on my application:
How to hide a taskbar entry but keep the window form
Then i tried it on a new empty VCL Forms Application and it still did not work. I searched for other solutions, but they all do very much the same like in the linked post.
Has something changed, that makes that impossible in windows 7? Or is there anything you
could think of, that could prevent it from working?
You can override the main form's CreateParam to remove the flag that forces the taskbar button (WS_EX_APPWINDOW) and additionally make the form owned by the application window. That's doing the opposite of the requirement for the shell to place a taskbar button for a window. From "Managing Taskbar Buttons":
[..] To ensure that the window button is placed on the taskbar, create an
unowned window with the WS_EX_APPWINDOW extended style. [..]
Sample:
type
TForm1 = class(TForm)
protected
procedure CreateParams(var Params: TCreateParams); override;
end;
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.ExStyle := Params.ExStyle and not WS_EX_APPWINDOW;
Params.WndParent := Application.Handle;
end;
Don't change the state of MainFormOnTaskbar property of the 'Application' from its default 'True' if you use this method.
You can also remove the second line (..WndParent := ..) and instead set PopupMode of the form to pmExplicit in the object inspector to same effect.
BTW, here's the documentation quote from the same topic for the solution TLama posted:
To prevent the window button from being placed on the taskbar, [...]
As an alternative, you can create a hidden window and make this hidden
window the owner of your visible window.
When you set MainFormOnTaskbar to false, the main form is owned by the application window by VCL design. And if you hide the application window, the requirement is fulfilled.
Try to use a tricky way described in this article:
Set the MainFormOnTaskBar to False in your project file. Then try to hide the application window from the main form's OnShow and OnActivate event handlers. So your project might look like follows:
Project1.dpr:
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := False;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
Unit1.pas:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormShow(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
ShowWindow(Application.Handle, SW_HIDE);
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
ShowWindow(Application.Handle, SW_HIDE);
end;
end.
your application main form is normally created in the dpr so open the dpr and look for the line that creates the main form.
// add this line first
// blank app title will prevent app from showing in the applications list in task manager
Application.Title := '';
// this line is already in the dpr and creates the main form, the class will differ
Application.CreateForm(TMainForm, Result);
// make the main form invisible to windows taskbar/task switcher
i := GetWindowLong(Application.Handle, GWL_EXSTYLE);
SetWindowLong(Application.Handle, GWL_EXSTYLE, i OR WS_EX_TOOLWINDOW AND NOT WS_EX_APPWINDOW);
i know this works on XP and 7. i'm guessing it's good for 8 as well. this adds the tool window flag and removes the appwindow flag so i guess if you're not interested in the toolwindow flag you can leave out the following part
i OR WS_EX_TOOLWINDOW

double-clicking TStaticText in Delphi XE2 app copies caption to clipboard

Double-clicking a TStaticText on a form copies the caption of that TStaticText to the clipboard. No double-click event is needed.
Steps to reproduce:
Using Win 64 and Delphi XE2 update 4.
Create a VCL Forms app.
Place a TEdit on the form.
Place a TStaticText on the form. Change caption to "TStaticText1Caption"
Place a second TStaticText on the form. Change caption to "TStaticText2Caption"
Run program(F9)
Type some text into the TEdit. Select it all and copy it via CTRL+C.
Delete the text in the TEdit. Paste it in to verify the text is what you copied.
Delete the text in the TEdit.
Double-click either TStaticText.
Paste text into TEdit. Notice it is not the original copied text but the caption of the TStaticText.
I have already submitted a bug report to Embarcadero.
I tried assigning a double-click event to the TStaticTexts. It still copies the caption to the clipboard even though it executes the double-click event.
procedure TForm1.StaticText1DblClick(Sender: TObject);
begin
Edit1.Text := 'Hello';
end;
procedure TForm1.StaticText2DblClick(Sender: TObject);
begin
Edit1.Text := 'World';
end;
This does not happen with TLabel or any other VCL control I have tried.
We have lots of TStaticTexts on our forms for visual design purposes and changing to TLabels is not an option.
Anybody have any ideas on how to prevent this from happening?
This is not a delphi bug, this behaviour is caused by the Windows Static Control which is created by the TStaticText VCL component.
Starting in Windows Vista, the Static text controls automatically copy their contents to the clipboard when you double-click them if you set the SS_NOTIFY style (the SS_NOTIFY style is set by the CreateParams method of the TCustomStaticText component)
Recomended lecture How do I make it so that users can copy static text on a dialog box to the clipboard easily?
As workaround you can remove the SS_NOTIFY style overriding the CreateParams method like so
type
TStaticText = class(Vcl.StdCtrls.TStaticText)
protected
procedure CreateParams(var Params: TCreateParams); override;
end;
TForm1 = class(TForm)
StaticText1: TStaticText;
private
public
end;
var
Form1: TForm42;
implementation
{$R *.dfm}
{ TStaticText }
procedure TStaticText.CreateParams(var Params: TCreateParams);
begin
inherited;
with Params do
Style := Style and not SS_NOTIFY;
end;
Note : you must be aware if you remove this style from the control you will no receive the STN_CLICKED, STN_DBLCLK, STN_DISABLE, and STN_ENABLE notification codes when the user clicks or double-clicks the control.

Correct way to ensure mainform has maximized and fully redrawn before showing a modal form on application load

What is the recommended way to ensure that the mainform is fully maximized and all controls are redrawn before showing a modal form on application first load?
I need to show a modal dialog when the application starts (not a login screen) but if I set the form to wsMaximized whilst the screen maximizes, the controls do not have chance to redraw and you are left with an ugly mess.
I show the modal screen at present using the following:
procedure TForm1.FormActivate(Sender: TObject);
var
frmOrderLookup:TfrmOrderLookup;
begin
onactivate := nil;
frmOrderLookup:=TfrmOrderLookup.Create(nil);
try
frmOrderLookup.showmodal;
finally
frmOrderLookup.Free;
end;
end;
What I normally do is post a custom message back to my form. That way it won't get processed until other messages for the form have already been handled. By the time this message gets processed, your form should have already finished redrawing.
type
TMyForm = class(TForm)
procedure FormCreate(Sender: TObject);
private
procedure HandleLookupMessage(var Message: TMessage); message WM_USER + 1;
end;
procedure TMyForm.HandleLookupMessage(var Message: TMessage);
var
frmOrderLookup: TfrmOrderLookup;
begin
frmOrderLookup := TfrmOrderLookup.Create(Application);
try
frmOrderLookup.ShowModal;
finally
frmOrderLookup.Release;
end;
end;
procedure TMyForm.FormCreate(Sender: TObject);
begin
// Maximise form here if needed
PostMessage(Handle, WM_USER + 1, 0, 0);
end;
If you're worried about the message getting to your application again somehow, you can always add a private boolean variable to indicate that it's been handled once.

Delphi - Set form to not focus on any component when it shows

Is there a way in Delphi to disallow the form to focus on any of its components but not disabling those components? I tried Self.SetFocus on FormActivate event of the form but the program says that it cannot focus on a disabled component.
Use the following OnActivate event handler:
procedure TForm1.FormActivate(Sender: TObject);
begin
ActiveControl:= nil;
end;

Resources