WinAPI - pozycja ikon na pulpicie [ciekawe kidy kto

0

dobra, więc mam kodzik, który z założenia powinien działać, ale nie działa! co jest z nim nie tak?

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, CommCtrl;

type
PInfo = ^TInfo;
TInfo = packed record
InfoPoint: TPoint;
InfoText: array[0..255] of Char;
InfoItem: TLVItem;
InfoFindInfo: TLVFindInfo;
end;

TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
Info: PInfo;
Desktop: THandle;
Count, I: Integer;

function GetDesktopListViewHandle: THandle;
var
S: String;
begin
Result := FindWindow('ProgMan', nil);
Result := GetWindow(Result, GW_CHILD);
Result := GetWindow(Result, GW_CHILD);
SetLength(S, 40);
GetClassName(Result, PChar(S), 39);
if PChar(S) 'SysListView32' then Result := 0;
end;

begin
Desktop:=GetDesktopListViewHandle;
If Desktop=0 then
Exit;
Count:=ListView_GetItemCount(Desktop);
GetMem(Info, SizeOf(TInfo));
try
ZeroMemory(Info, SizeOf(TInfo));
with Info^ do
begin
InfoItem.pszText:=InfoText;
InfoItem.cchTextMax := 255;
InfoItem.mask := LVIF_TEXT;
try
for I:=0 to Count-1 do
begin
InfoItem.iItem:=I;
try
ListView_GetItem(Desktop, InfoItem);
ListView_GetItemPosition(Desktop, I, InfoPoint);
except
Application.MessageBox('Something is wrong!', 'Exception!', MB_OK);
end;
end;
except
Application.MessageBox('Something is wrong!', 'Exception!', MB_OK);
end;
end;
finally
FreeMem(Info);
end;
end;

Gdy nacise na buttona od razu Explorer pada na nieprawidłwym wywołaniu funkcji z commctrl.dll a następnie (po zresetowaniu explorer.exe) wali sie o nieprawidłowe dojście do okna, co w tym jest źle?

0

Prosze o testowanie tego kodu, a jak ktoś z Was znajdzie odpowiedx to ma u mnie [browar] albo nawet całą skrzynke browara, byle tylko działało

0

takie coś też się wali, mimo użycia porządnego shared mem!:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, CommCtrl;

type
PInfo = ^TInfo;
TInfo = packed record
InfoPoint: TPoint;
InfoText: array[0..255] of Char;
InfoItem: TLVItem;
InfoFindInfo: TLVFindInfo;
end;

TSharedMem = class(TObject)
private
FHandle: THandle;
FName: string;
FSize: Integer;
FCreated: Boolean;
FFileView: Pointer;
public
constructor Create(const Name: string; Size: Integer);
destructor Destroy; override;

property Name: string read FName;
property Size: Integer read FSize;
property Buffer: Pointer read FFileView;
property Created: Boolean read FCreated;
property Handle: THandle read FHandle;
end;

TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

constructor TSharedMem.Create(const Name: string; Size: Integer);
begin
try
FName := Name;
FSize := Size;
{ CreateFileMapping, when called with $FFFFFFFF for the hanlde
value,
creates a region of shared memory }
FHandle := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0,
Size, PChar(Name));
if FHandle = 0 then abort;
FCreated := GetLastError = 0;
{ We still need to map a pointer to the handle of the shared memory
region }
FFileView := MapViewOfFile(FHandle, FILE_MAP_WRITE, 0, 0, Size);
if FFileView = nil then abort;
except
Application.MessageBox(PChar(Format('Error creating shared memory %s (%d)', [Name,
GetLastError])), 'Exception', MB_OK);
end;
end;

destructor TSharedMem.Destroy;
begin
if FFileView nil then
UnmapViewOfFile(FFileView);

if FHandle 0 then
CloseHandle(FHandle);

inherited;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
Info: PInfo;
Wnd: HWnd;
Count, I: Integer;
SharedMem: TSharedMem;
begin
Wnd := FindWindowEx(GetDesktopWindow, 0, 'Progman', 'Program Manager');
Wnd := FindWindowEx(Wnd, 0, 'SHELLDLL_DefView', nil);
Wnd := FindWindowEx(Wnd, 0, 'SysListView32', nil);
Count := ListView_GetItemCount(Wnd);
SharedMem := TSharedMem.Create('', SizeOf(TInfo));
Info := SharedMem.Buffer;
with Info^ do
try
infoItem.pszText := infoText;
infoItem.cchTextMax := 255;
infoItem.mask := LVIF_TEXT;
try
for I := 0 to Count - 1 do
begin
infoItem.iItem := I;
try
ListView_GetItem(Wnd, infoItem);
ListView_GetItemPosition(Wnd, I, infoPoint);
except
end;
end;
finally
end;
finally
SharedMem.Free;
end;
end;

end.

1 użytkowników online, w tym zalogowanych: 0, gości: 1