Thanks for you reply.
I don't think this is Windows feature. I made this in Delphi 2010, but still I'm not sure it will work in Lazarus. I'll try it later.
Look at attached example.
The most important part is:
Override the CreateParams procedure in borderless form:
procedure TBorderlessForm.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
Params.WndParent := GetDesktopWindow; //without this line assigned icon will not work
end;
I must assign WndParent to GetDesktopWindow result.
I haven't find this function in Lazarus, but it's from user32.dll:
function GetDesktopWindow; external user32 name 'GetDesktopWindow';
The second part is hiding main form with this:
procedure TMainForm.btnHideClick(Sender: TObject);
begin
self.hide;
Application.ShowMainForm := False;
ShowWindow(Application.Handle, SW_HIDE); //mainform button is hidden
// ShowWindow(Application.MainForm.Handle, SW_HIDE); //mainform button is not hidden
end;
And the worst is that in Lazarus there is no Application.Handle! I don't know what is this, but in Delphi assignment to FHandle looks like this:
[UIPermission(SecurityAction.LinkDemand, Window=UIPermissionWindow.AllWindows)]
procedure TApplication.CreateHandle;
var
LHandle: HWND;
SysMenu: HMenu;
{$IF DEFINED(CLR)}
TempClass: TWndClassInfo;
WindowClass: TWndClass;
{$ELSE}
TempClass: TWndClass;
{$IFEND}
begin
{$IF DEFINED(CLR)}
if not FHandleCreated and not IsConsole then
begin
if not Assigned(FResources) then
FResources := TApplicationResources.Create;
FResources.FObjectInstance := MakeObjectInstance(WndProc);
WindowClass.lpszMenuName := '';
WindowClass.lpszClassName := 'TApplication';
{$ELSE}
{$IFDEF MSWINDOWS}
if not FHandleCreated and not IsConsole then
{$ENDIF}
{$IFDEF LINUX}
if not FHandleCreated then
{$ENDIF}
begin
FObjectInstance := MakeObjectInstance(WndProc);
{$IFEND}
WindowClass.lpfnWndProc := @DefWindowProc;
if not GetClassInfo(HInstance, WindowClass.lpszClassName, TempClass) then
begin
WindowClass.hInstance := HInstance;
if Windows.RegisterClass(WindowClass) = 0 then
raise EOutOfResources.Create(SWindowClass);
end;
LHandle := CreateWindowEx(WS_EX_TOOLWINDOW, WindowClass.lpszClassName, {$IFNDEF CLR}PChar{$ENDIF}(FTitle),
WS_POPUP or WS_CAPTION or WS_CLIPSIBLINGS or WS_SYSMENU
or WS_MINIMIZEBOX,
GetSystemMetrics(SM_CXSCREEN) div 2,
GetSystemMetrics(SM_CYSCREEN) div 2,
0, 0, 0, 0, HInstance, nil);
{$IF DEFINED(CLR)}
FResources.FHandle := LHandle;
{$ELSE}
FHandle := LHandle; //<----------- HERE
{$IFEND}
FHandleCreated := True;
{$IF DEFINED(CLR)}
SetWindowLong(Handle, GWL_WNDPROC, @FResources.FObjectInstance);
{$ELSE}
SetWindowLong(FHandle, GWL_WNDPROC, LPARAM(FObjectInstance));
{$IFEND}
if NewStyleControls then
begin
SendMessage(Handle, WM_SETICON, ICON_BIG, LPARAM(GetIconHandle));
SetClassLong(Handle, GCL_HICON, LPARAM(GetIconHandle));
end;
SysMenu := GetSystemMenu(Handle, False);
DeleteMenu(SysMenu, SC_MAXIMIZE, MF_BYCOMMAND);
DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND);
if NewStyleControls then DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND);
end;
end;
When I use Application.Mainform.Handle, it works weird, because if another than mainform window is visible, the mainform button will not disappear from taskbar. When there is no other forms visible, mainform button will hide. So this is not what I want.
Using this wih Application.Handle works fine in Delphi.