【问题标题】:How can I remove the additional icon on the task bar when I use both VCL and FMX? [duplicate]当我同时使用 VCL 和 FMX 时,如何删除任务栏上的附加图标? [复制]
【发布时间】:2016-06-11 06:50:06
【问题描述】:

如果您默认创建 Delphi VCL 应用程序,您有一个 VCL 表单,如果您运行您的应用程序,则任务栏上只有一个图标。之后,如果向其中添加 FMX 表格,您可以同时拥有这两种表格并同时使用它们。但是在应用程序运行时的任务栏中有两个图标。无论如何要删除它的标题是项目名称的那个并保留另一个是你的主要形式?

我使用的是delphi XE8。

【问题讨论】:

    标签: delphi firemonkey vcl delphi-xe8


    【解决方案1】:

    我找到了答案。这很有趣。我搜索了大约 2 天,但没有成功,我在发布问题后找到了答案。我自己回答,也许对别人有用。

    我在此页面上找到了此代码 https://github.com/vintagedave/firemonkey-container/blob/master/Parnassus.FMXContainer.pas

    function EnumWindowCallback(hWnd: HWND; lParam: LPARAM): BOOL; stdcall;
    const
      FMXClassName = 'TFMAppClass';
    var
      ProcessID : DWORD;
      ClassName : string;
      ClassNameLength : NativeInt;
    begin
      // XE4 (possibly others) show a phantom TFMAppClass window on the taskbar.  Hide it.
      // Ensure the one we hide belongs to this thread / process - don't damage other FMX apps
      if (GetWindowThreadProcessId(hWnd, ProcessID) = GetCurrentThreadId) and (ProcessID = GetCurrentProcessId) then begin
        // Thanks to the ubiquitous David Heffernan... http://stackoverflow.com/questions/7096542/collect-all-active-window-class-names
        SetLength(ClassName, 256);
        ClassNameLength := GetClassName(hWnd, PChar(ClassName), Length(ClassName));
        if ClassNameLength = 0 then RaiseLastOSError;
        SetLength(ClassName, ClassNameLength);
        if ClassName = FMXClassName then begin
          // Found.  Hide it, and return false to stop enumerating
          ShowWindow(hWnd, SW_HIDE);
          Exit(False);
        end;
      end;
      Result := True; // Fallthrough, keep iterating
    end;
    

    如果使用下面的代码来使用,任务栏上的其他图标会被隐藏

      EnumWindows(@EnumWindowCallback, 0);
    

    【讨论】:

    • 由于您要在特定线程中查找窗口,因此您应该使用EnumThreadWindows() 而不是EnumWindows()。或者直接使用FindWindow()。
    猜你喜欢
    • 2021-11-15
    • 2016-11-28
    • 2021-11-08
    • 2012-02-14
    • 1970-01-01
    • 2012-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多