在Windows上的FMX中隐藏任务栏按钮

时间:2018-12-13 16:01:32

标签: firemonkey c++builder c++builder-10.2-tokyo

我希望能够从任务栏上删除Win32应用程序的按钮。我也希望以后可以重新添加。如何才能做到这一点?我找到了this approach,但是它是用Delphi编写的,而我使用的是C ++。

我尝试通过将以下代码中的一行Remy代码更改为modifying this code

SetWindowLong(hWnd, GWL_EXSTYLE, Style | WS_EX_APPWINDOW); 

SetWindowLong(hWnd, GWL_EXSTYLE, Style | WS_EX_TOOLWINDOW);

但这不起作用,该按钮仍在任务栏上。

更新:我正在使用的代码(当然源于雷米):

void __fastcall TForm1::CreateHandle()   // this is code from Remy i added to help me trap screen lock
{
 TForm::CreateHandle();

 HWND hWnd = Fmx::Platform::Win::FormToHWND(this);
 if (SetWindowSubclass(hWnd, &SubclassWndProc, 1, reinterpret_cast<DWORD_PTR>(this)))
 {
    MonitoringWTS = WTSRegisterSessionNotification(hWnd, NOTIFY_FOR_THIS_SESSION);
    if (!MonitoringWTS)
        RemoveWindowSubclass(hWnd, &SubclassWndProc, 1);
 }
 else {
    MonitoringWTS = false;
 }

 if (hWnd != NULL)   // this code added from https://stackoverflow.com/questions/28929163/how-to-show-a-secondary-form-on-taskbar-using-fmx-c
 {
 LONG Style = GetWindowLong(hWnd, GWL_EXSTYLE); // <-- don't forget this step!
 SetWindowLong(hWnd, GWL_EXSTYLE, Style | WS_EX_APPWINDOW);
 }
}

使用C ++ Builder 10.2版本25.0.31059.3231。

1 个答案:

答案 0 :(得分:1)

如果还保留默认的WS_EX_TOOLWINDOW样式,仅添加WS_EX_APPWINDOW样式是不够的。尝试改用此方法:

LONG_PTR ExStyle = GetWindowLongPtr(hWnd, GWL_EXSTYLE);
SetWindowLongPtr(hWnd, GWL_EXSTYLE, (Style & ~WS_EX_APPWINDOW) | WS_EX_TOOLWINDOW);

尽管,使TForm像工具窗口一样简单的方法是将其BorderStyle属性设置为bsToolWindowbsSizeToolWin

但是,请注意,在XE7 +中,您应该使用ApplicationHWND()来获取任务栏上的HWND,因为它与{{1 }}的窗口。甚至因为您用Delphi而不是C ++编写的问题,pointed out in an answer还是被您忽略了。相关的函数调用不会更改,只需代码语法即可。

尝试一下:

TForm