Enable Taskbar's auto hide feature from Delphi code
Hi. Recently I was looking for an easy solution on how to enable Taskbar's auto hide and always on top features. The only thing I have found was the solution on how to find out "Is Windows taskbar's auto hide feature enabled?". Here is the solution:
uses ShellAPI;
function IsTaskbarAutoHideOn : boolean;
var
ABData : TAppBarData;
begin
ABData.cbSize := sizeof(ABData) ;
Result :=
(SHAppBarMessage(ABM_GETSTATE, ABData)
and ABS_AUTOHIDE) > 0;
end;
But as you understand this is good but not what I was looking for.
Later I have found something similar to the solution, but once again it was not proper because it was just "cheating" :). Here is it:
procedure TForm1.Button1Click(Sender: TObject);
var
hTaskbar: THandle;
begin
hTaskbar := FindWindow('Shell_TrayWnd', Nil);
ShowWindow(hTaskbar, SW_HIDE);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
hTaskbar: THandle;
begin
hTaskbar := FindWindow('Shell_TrayWnd', Nil);
ShowWindow(hTaskbar, SW_SHOWNORMAL);
end;
That's why I had to dig deep into the MSDN and write my own solution. So, take a look how I have solved the problem.
procedure TForm1.Button1Click(Sender: TObject);
var
ABData: TAppBarData;
begin
ABData.cbSize := sizeof(tappbardata);
ABData.hWnd := FindWindow('SHELL_TRAYWND', nil);
ABData.lParam := LParam(ABS_ALWAYSONTOP or ABS_AUTOHIDE);
SHAppBarMessage($0000000a, ABData);
end;
As it turned out, the main problem was to find ABM_SETSTATE constant which equal to $0000000a and not declared in Delphi.
That's it!