Reputation: 6707
I want to hide my App from ALT+TAB but not from the Taskbar; The taskbar has a icon now OK that can be used to manage the tool GUI.
However, there is no need to have the app in ALT-TAB browsable window list as the main window of app is actually hidden.
The App Window is hidden by setting its ALPHA to 0.
Upvotes: 0
Views: 1676
Reputation: 6099
Form.BorderStyle
to either bsSizeToolWin
or bsToolWindow
, so its window is not listed in the Alt+Tab dialog.Application.Handle
window:
procedure TForm1.FormCreate( Sender: TObject );
var
iStyle: Integer;
begin
iStyle:= GetWindowLong( Application.Handle, GWL_EXSTYLE );
SetWindowLong( Application.Handle, GWL_EXSTYLE, iStyle or WS_EX_TOOLWINDOW );
end;
Steps #1 and #2 work for me as expected: nothing in the window list, not one button on the taskbar.uses
ComObj;
// From https://github.com/project-jedi/jvcl/blob/master/jvcl/run/JvProgressBar.pas
const
CLSID_TaskbarList: TGUID= '{56FDF344-FD6D-11d0-958A-006097C9A090}';
type
ITaskbarList= interface(IUnknown)
['{56FDF342-FD6D-11D0-958A-006097C9A090}']
function HrInit: HRESULT; stdcall;
function AddTab( hwnd: HWND ): HRESULT; stdcall;
function DeleteTab( hwnd: HWND ): HRESULT; stdcall;
function ActivateTab( hwnd: HWND ): HRESULT; stdcall;
function SetActiveAlt( hwnd: HWND ): HRESULT; stdcall;
end;
var
oBar: ITaskbarList= nil;
procedure TForm1.Button1Click( Sender: TObject );
begin
if oBar= nil then begin // Never used? Try to init.
oBar:= CreateComObject( CLSID_TaskbarList ) as ITaskbarList;
if oBar.HrInit<> S_OK then oBar:= nil; // Failed? Can't use it.
end;
if oBar<> nil then begin
if oBar.AddTab( self.Handle )= S_OK then self.Caption:= 'Success!';
end;
end;
However: this 3rd step didn't work for me on Win7 - no button was added to the taskbar, although no error occurred. It may be because
I discourage this entire approach: what appears in Alt+Tab should also have a taskbar button and vice versa. At work there's this annoying NCP software which auto hides its window upon successful connect, insists on using a tasktray icon and auto-slides in a window as soon as I come near the taskicon, although I surely wanted to hit a different one. Horrible, because it's always in the way and can't be relied on to persist either.
That's not what you intend, but you also want to force inconsistency. Simply don't. Just release an application that can be used and where expected behavior also happens. If all that doesn't move you then think of how prone your application will be in the future to fail in emulations - don't do unusual stuff and Wine will have no problems running it for all Unix users, too.
Upvotes: 2