Recent

Author Topic: Draw Behind Desktop Icons - porting  (Read 445 times)

atroesch

  • New Member
  • *
  • Posts: 15
Draw Behind Desktop Icons - porting
« on: November 16, 2025, 05:04:52 pm »
somebody can help with this?
i like to do what is explained here:
https://www.codeproject.com/articles/Draw-Behind-Desktop-Icons-in-Windows-plus#comments-section

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, windows;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     procedure Button1Click(Sender: TObject);
  17.   private
  18.  
  19.   public
  20.    png1 : TportableNetworkGraphic;
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. type
  31.   TMyData = record
  32.     Handle: HWND;
  33.     Pid: DWORD;
  34.     Caption: String;
  35.     ClassName: String;
  36.   end;
  37.   PMyData = ^TMyData;
  38.  
  39. function GetWindowClass(const Handle: HWND): String;
  40. begin
  41.   SetLength(Result, MAX_PATH);
  42.   SetLength(Result, GetClassName(Handle, PChar(Result), Length(Result)));
  43. end;
  44.  
  45. function GetWindowCaption(const Handle: HWND): String;
  46.  begin
  47.   SetLength(Result, MAX_PATH);
  48.   SetLength(Result, GetWindowText(Handle, PChar(Result), Length(Result)));
  49. end;
  50.  
  51. function EnumChildWindowsProc(Handle: THandle; MyData: LParam): BOOL; stdcall;
  52. var
  53.   ClassName: String;
  54.   Caption: String;
  55.   Pid: DWORD;
  56. begin
  57.   ClassName := GetWindowClass(Handle);
  58.   Caption := GetWindowCaption(Handle);
  59.  
  60.   Result := (ClassName = 'SysListView32') and (Caption = 'FolderView');
  61.   if Result then
  62.   begin
  63.     PmyData(MyData)^.Handle := Handle;
  64.     GetWindowThreadProcessId(Handle, PmyData(MyData)^.Pid);
  65.     PmyData(MyData)^.Caption := Caption;
  66.     PmyData(MyData)^.ClassName := ClassName;
  67.   end;
  68.  
  69.   // To continue enumeration, the callback function must return TRUE;
  70.   // to stop enumeration, it must return FALSE
  71.   Result := not Result;
  72. end;
  73.  
  74. procedure TForm1.Button1Click(Sender: TObject);
  75. var
  76.   MyData  : TMyData;
  77.   P       : IntPtr;
  78.   DC      : HDC;
  79. begin
  80.   ZeroMemory(@MyData, SizeOf(MyData));
  81.   EnumChildWindows(GetDesktopWindow, @EnumChildWindowsProc, NativeInt(@MyData));
  82.   if MyData.Handle > 0 then
  83.   begin
  84.     ShowMessageFmt('Found Window in Pid %d '+MyData.caption, [MyData.Pid]);
  85.     png1:=TportableNetworkGraphic.Create;
  86.     DC:=getDC(MyData.handle);
  87.     if(DC = 0 ) then
  88.      showmessage('no');
  89.     png1.LoadFromDevice(DC);
  90.     releaseDC(MyData.handle,DC);
  91.     png1.SaveToFile(getuserdir+'Pictures\test.png');
  92.     png1.Free;
  93.   end
  94.   else begin
  95.     ShowMessage('Window not found!');
  96.   end;
  97. end;
  98.  
  99. end.
  100.  

i need the translation to pascal for:
Code: [Select]
W32.SendMessageTimeout(progman,
                       0x052C,
                       new IntPtr(0),
                       IntPtr.Zero,
                       W32.SendMessageTimeoutFlags.SMTO_NORMAL,
                       1000,
                       out result);

and to get the HDC handle of the workerW window created by the sendmessage above

jamie

  • Hero Member
  • *****
  • Posts: 7379
Re: Draw Behind Desktop Icons - porting
« Reply #1 on: November 16, 2025, 06:42:45 pm »
Really? 8)

Jamie
The only true wisdom is knowing you know nothing

atroesch

  • New Member
  • *
  • Posts: 15
Re: Draw Behind Desktop Icons - porting
« Reply #2 on: November 16, 2025, 07:46:33 pm »
Yes, really, because i know that i know nothing, thats why i ask here.

jamie

  • Hero Member
  • *****
  • Posts: 7379
Re: Draw Behind Desktop Icons - porting
« Reply #3 on: November 16, 2025, 11:35:31 pm »
Code: Pascal  [Select][+][-]
  1. Var
  2.  AReturnValue:DWORD;
  3. Begin
  4.   SendmessageTimeOut(TheHandle, $052C,0,0,0,1000,AReturnValue);
  5.  

Then WIndows File shows 2 variants, if that one don't work then change the last parameter to this
Code: Pascal  [Select][+][-]
  1.  (.....@AReturnvalue);
  2.  

Jamie
The only true wisdom is knowing you know nothing

atroesch

  • New Member
  • *
  • Posts: 15
Re: Draw Behind Desktop Icons - porting
« Reply #4 on: November 17, 2025, 07:38:05 am »
thank you :-)

 

TinyPortal © 2005-2018