Einzelnen Beitrag anzeigen

flashcoder

Registriert seit: 10. Nov 2013
83 Beiträge
 
#2

AW: SetThreadDesktop function: How show a Form in any active desktop?

  Alt 7. Dez 2018, 23:28
SOLUTION:

Change the code above this way:

Delphi-Quellcode:
if not IsSameDesktop(HOldDesk, HNewDesk) then
  begin

    if (not SetThreadDesktop(HNewDesk)) then
    begin
      WriteLn('SetThreadDesktop Failed.');
      Exit;
    end;
    Form1 := TForm1.Create(nil);
    Form1.ShowModal;
    Form1.Release;
  end;
will work fine only by the first time that SetThreadDesktop function is called before window creation, already when this piece of code:

Delphi-Quellcode:
while True do
  begin
    if InputDesktopSelected then
      //CopyScreen(FScrBmp, FIndex)
    else if SelectDesktop(nil) then
      //CopyScreen(FScrBmp, FIndex);
    Sleep(3000);
  end;
is executed by the 2nd time, SetThreadDesktop will fails because already exists a window created in same thread that call SetThreadDesktop. Then probably the solution to this could be create and execute a new thread with all the 2nd piece of code of this answer.
  Mit Zitat antworten Zitat