Author: Tomas Rutkauskas
Does anyone know where the X- and Y-coordinates of the icons on the Windows Desktop
are stored/ saved and how I can read and write those values?
Answer:
Since the desktop is a simple ListView (embedded in a few other windows), you'll be
able to find it with this (from a little utility of mine). It uses IPCThrd.pas from
the IPCXXX demos in the demos directory, for the SharedMem class. You'll have to
use that, since otherwise you won't be able to read the information from desktop's
memory into your memory.
1 type
2 PInfo = ^TInfo;
3 TInfo = packed record
4 infoPoint: TPoint;
5 infoText: array[0..255] of Char;
6 infoItem: TLVItem;
7 infoFindInfo: TLVFindInfo;
8 end;
9
10 {...}
11
12 var
13 Info: PInfo;
14 IniFile: TRegIniFile;
15 Wnd: HWnd;
16 Count, I: Integer;
17 SharedMem: TSharedMem;
18 begin
19 {Find list view window}
20 Wnd := FindWindowEx(GetDesktopWindow, 0, 'Progman', 'Program Manager');
21 Wnd := FindWindowEx(Wnd, 0, 'SHELLDLL_DefView', nil);
22 Wnd := FindWindowEx(Wnd, 0, 'SysListView32', nil);
23 Count := ListView_GetItemCount(Wnd);
24 SharedMem := TSharedMem.Create('', SizeOf(TInfo));
25 Info := SharedMem.Buffer;
26 with Info^ do
27 try
28 infoItem.pszText := infoText;
29 infoItem.cchTextMax := 255;
30 infoItem.mask := LVIF_TEXT;
31 IniFile := TRegIniFile.Create('Software\YaddaYadda');
32 try
33 with IniFile do
34 begin
35 EraseSection('Desktop\' + CurRes);
36 for I := 0 to Count - 1 do
37 begin
38 infoItem.iItem := I;
39 try
40 ListView_GetItem(Wnd, infoItem);
41 ListView_GetItemPosition(Wnd, I, infoPoint);
42 WriteString('Desktop\' + CurRes, infoText, Format('%.4d, %.4d',
43 [Point.X,
44 Point.Y]));
45 except
46 end;
47 end;
48 end;
49 finally
50 IniFile.Free;
51 end;
52 finally
53 SharedMem.Free;
54 end;
55 end;
|