-1

If you create Delphi VCL application by default you have one VCL form and if you run your application there is only one icon on your task bar. After that if add a FMX form to it, you can have both forms and use them both. but in the task bar when the application is running there is two icon. Is there anyway to remove the one that its title is the project name and keep the other that is your main form?

I am using delphi XE8.

Loghman
  • 1,500
  • 1
  • 14
  • 30

1 Answers1

1

I found the answer. It is funny. about 2 days that I am searching and no success I found the answer after I posted my question. I answer it myself maybe it is useful to another person.

I found this code on this page 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;

if use the following code to use it, the other icon on the task bar will be hidden

  EnumWindows(@EnumWindowCallback, 0);
Loghman
  • 1,500
  • 1
  • 14
  • 30
  • Since you are looking for windows in a specific thread, you should use [`EnumThreadWindows()`](https://msdn.microsoft.com/en-us/library/windows/desktop/ms633495.aspx) instead of `EnumWindows()`. Or just use `FindWindow()` instead. – Remy Lebeau Jun 11 '16 at 15:57