CodedK
asked on
Tray icons and Borderstyle set to bsnone.
Hi.
I have 2 buttons in a form.
- 1st button make the form show only important info and because i want to make it very small i need
to set BorderStyle=bsNone.
- 2nd button make the form normal again.
BUT my program tray icon disappears.
How can i prevent that ??
Thanks for your help.
I have 2 buttons in a form.
- 1st button make the form show only important info and because i want to make it very small i need
to set BorderStyle=bsNone.
- 2nd button make the form normal again.
BUT my program tray icon disappears.
How can i prevent that ??
Thanks for your help.
ASKER
Yes ... its not a component.
Here is the code :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellApi, ImgList, StdCtrls, XPMan;
const
WM_ICONTRAY=WM_USER+1;
type
TForm1 = class(TForm)
ImageList1: TImageList;
Button1: TButton;
Button2: TButton;
XPManifest1: TXPManifest;
Button3: TButton;
procedure WMNCHitTest(var Msg: TWMNCHitTest);
message WM_NCHITTEST;
procedure FormTray(var Msg:TMessage);
message WM_ICONTRAY;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
F1Tray:TNotifyIconData;
F1Icon:TIcon;
F2Tray:TNotifyIconData;
F2Icon:TIcon;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest);
begin
inherited;
if (Msg.Result = HTCLIENT)and(ControlAtPos( ScreenToCl ient(Small PointToPoi nt
(TWMNCHitTest(Msg).Pos)), False)= nil) then Msg.Result := HTCAPTION;
end;
procedure TForm1.FormTray(var Msg:TMessage);
begin
case Msg.lParam of WM_LBUTTONDOWN:
Form1.Show;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
With F1Tray do
begin
cbSize:=SizeOf(F1Tray);
Wnd:=Handle;
uID:=0;
uFlags:=NIF_MESSAGE+NIF_IC ON+NIF_TIP ;
uCallbackMessage:=WM_ICONT RAY;
F1Icon:=TIcon.Create;
ImageList1.GetIcon(0,F1Ico n);
hIcon:=F1Icon.Handle;
StrPCopy(szTip,'This is F1 ');
end;
Shell_NotifyIcon(NIM_ADD,@ F1Tray);
With F2Tray do
begin
cbSize:=SizeOf(F2Tray);
Wnd:=Handle;
uID:=1;
uFlags:=NIF_MESSAGE+NIF_IC ON+NIF_TIP ;
uCallbackMessage:=WM_ICONT RAY;
F2Icon:=TIcon.Create;
ImageList1.GetIcon(0,F2Ico n);
hIcon:=F2Icon.Handle;
StrPCopy(szTip,'This is F2');
end;
Shell_NotifyIcon(NIM_ADD,@ F2Tray);
end;
procedure TForm1.Button1Click(Sender : TObject);
begin
Form1.Height:=25;
Form1.BorderStyle:=bsNone; //---- PROBLEM
end;
procedure TForm1.Button2Click(Sender : TObject);
begin
Form1.Height:=160;
Form1.BorderStyle:=bsToolW indow;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELET E,@F1Tray) ;
Shell_NotifyIcon(NIM_DELET E,@F2Tray) ;
F1Icon.Free;
F2Icon.Free;
end;
procedure TForm1.FormCloseQuery(Send er: TObject; var CanClose: Boolean);
begin
CanClose:=False;
Form1.Hide;
end;
procedure TForm1.Button3Click(Sender : TObject);
begin
Application.Terminate;
end;
end.
Here is the code :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellApi, ImgList, StdCtrls, XPMan;
const
WM_ICONTRAY=WM_USER+1;
type
TForm1 = class(TForm)
ImageList1: TImageList;
Button1: TButton;
Button2: TButton;
XPManifest1: TXPManifest;
Button3: TButton;
procedure WMNCHitTest(var Msg: TWMNCHitTest);
message WM_NCHITTEST;
procedure FormTray(var Msg:TMessage);
message WM_ICONTRAY;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
F1Tray:TNotifyIconData;
F1Icon:TIcon;
F2Tray:TNotifyIconData;
F2Icon:TIcon;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest);
begin
inherited;
if (Msg.Result = HTCLIENT)and(ControlAtPos(
(TWMNCHitTest(Msg).Pos)), False)= nil) then Msg.Result := HTCAPTION;
end;
procedure TForm1.FormTray(var Msg:TMessage);
begin
case Msg.lParam of WM_LBUTTONDOWN:
Form1.Show;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
With F1Tray do
begin
cbSize:=SizeOf(F1Tray);
Wnd:=Handle;
uID:=0;
uFlags:=NIF_MESSAGE+NIF_IC
uCallbackMessage:=WM_ICONT
F1Icon:=TIcon.Create;
ImageList1.GetIcon(0,F1Ico
hIcon:=F1Icon.Handle;
StrPCopy(szTip,'This is F1 ');
end;
Shell_NotifyIcon(NIM_ADD,@
With F2Tray do
begin
cbSize:=SizeOf(F2Tray);
Wnd:=Handle;
uID:=1;
uFlags:=NIF_MESSAGE+NIF_IC
uCallbackMessage:=WM_ICONT
F2Icon:=TIcon.Create;
ImageList1.GetIcon(0,F2Ico
hIcon:=F2Icon.Handle;
StrPCopy(szTip,'This is F2');
end;
Shell_NotifyIcon(NIM_ADD,@
end;
procedure TForm1.Button1Click(Sender
begin
Form1.Height:=25;
Form1.BorderStyle:=bsNone;
end;
procedure TForm1.Button2Click(Sender
begin
Form1.Height:=160;
Form1.BorderStyle:=bsToolW
end;
procedure TForm1.FormDestroy(Sender:
begin
Shell_NotifyIcon(NIM_DELET
Shell_NotifyIcon(NIM_DELET
F1Icon.Free;
F2Icon.Free;
end;
procedure TForm1.FormCloseQuery(Send
begin
CanClose:=False;
Form1.Hide;
end;
procedure TForm1.Button3Click(Sender
begin
Application.Terminate;
end;
end.
I'm not sure why do they disappear when you change borders by using default BorderStyle property, but here's a WinAPI alternative that does border changing without that 'bug':
procedure TForm1.Button1Click(Sender : TObject);
begin
Form1.Height:=25;
//Form1.BorderStyle:=bsNon e;
SetWindowLong(handle, gwl_style, GetWindowLong(handle, gwl_style) and not (ws_caption or ws_sizebox)); // remove both 'blue border' and 'resizing border'
end;
procedure TForm1.Button2Click(Sender : TObject);
begin
Form1.Height:=160;
//Form1.BorderStyle:=bsToo lWindow;
SetWindowLong(handle, gwl_exstyle, GetWindowLong(handle, gwl_exstyle) or ws_ex_toolwindow); // set form-type to toolwindow
SetWindowLong(handle, gwl_style, GetWindowLong(handle, gwl_style) or ws_caption or ws_sizebox); // add 'blue border' and 'resizing border'
SetWindowPos(handle, 0, 0, 0, 0, 0, swp_nozorder or swp_nomove or swp_nosize or swp_drawframe); // redraw new border
end;
procedure TForm1.Button1Click(Sender
begin
Form1.Height:=25;
//Form1.BorderStyle:=bsNon
SetWindowLong(handle, gwl_style, GetWindowLong(handle, gwl_style) and not (ws_caption or ws_sizebox)); // remove both 'blue border' and 'resizing border'
end;
procedure TForm1.Button2Click(Sender
begin
Form1.Height:=160;
//Form1.BorderStyle:=bsToo
SetWindowLong(handle, gwl_exstyle, GetWindowLong(handle, gwl_exstyle) or ws_ex_toolwindow); // set form-type to toolwindow
SetWindowLong(handle, gwl_style, GetWindowLong(handle, gwl_style) or ws_caption or ws_sizebox); // add 'blue border' and 'resizing border'
SetWindowPos(handle, 0, 0, 0, 0, 0, swp_nozorder or swp_nomove or swp_nosize or swp_drawframe); // redraw new border
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much :)
But i dont want a form that can resize...
Can you please tell me the command ?
Thanks :)
But i dont want a form that can resize...
Can you please tell me the command ?
Thanks :)
take a look at:
SetWindowLong(handle, gwl_style, GetWindowLong(handle, gwl_style) or ws_caption or ws_sizebox); // add 'blue border' and 'resizing border'
ws_sizebox style - that's the resizable border. change it to:
SetWindowLong(handle, gwl_style, GetWindowLong(handle, gwl_style) or ws_caption);
SetWindowLong(handle, gwl_style, GetWindowLong(handle, gwl_style) or ws_caption or ws_sizebox); // add 'blue border' and 'resizing border'
ws_sizebox style - that's the resizable border. change it to:
SetWindowLong(handle, gwl_style, GetWindowLong(handle, gwl_style) or ws_caption);
ASKER
:) :) :) :) :) :)
Thanks :)
Thanks :)
Glad to help :)
whose trayicon component are you using?
Is it your own code? If it is, can you paste code here?