其实只用一个API函数就能实现:ShowWindow(Application.Handle,SW_HIDE),今天看到另一种方法,利用ITaskbarList接口隐藏任务栏图标,缺点是ALT+TAB或最小化后又显示出来了,但这个方法可以引伸出其它应用。
- //uses ActiveX
- type
- ITaskbarList = interface(IUnknown)
- ['{56FDF344-FD6D-11d0-958A-006097C9A090}']
- procedure HrInit; safecall;
- procedure AddTab(hWindow: HWND); safecall;
- procedure DeleteTab(hWindow: HWND); safecall;
- procedure ActivateTab(hWindow: HWND); safecall;
- procedure SetActiveAlt(hWindow: HWND); safecall;
- end;
- procedure TForm1.btn1Click(Sender: TObject);
- var
- TaskbarList:ITaskbarList;
- const
- CLSID_TaskbarList:TGUID='{56FDF344-FD6D-11d0-958A-006097C9A090}';
- IID_ITaskbarList:TGUID='{602D4995-B13A-429b-A66E-1935E44F4317}';
- begin
- CoCreateInstance(CLSID_TaskbarList,Nil,CLSCTX_INPROC_SERVER,IID_ITaskbarList,TaskbarList);
- TaskbarList.HrInit();
- TaskbarList.DeleteTab(Application.Handle);
- end;
还有一种方法:
ExtendedStyle := GetWindowLong (Application.Handle, GWL_EXSTYLE);
SetWindowLong(Application.Handle, GWL_EXSTYLE, ExtendedStyle OR WS_EX_TOOLWINDOW AND NOT WS_EX_APPWINDOW);