Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Desktop Icons

31 views
Skip to first unread message

Urs Klingsporn

unread,
May 28, 2001, 3:18:28 PM5/28/01
to
Is there a way to get the positions of the desktop icons?

Urs


Carlo Bertuccini

unread,
May 28, 2001, 3:58:23 PM5/28/01
to
Urs,

"Urs Klingsporn" <u...@websting.de> ha scritto nel messaggio:

> Is there a way to get the positions of the desktop icons?

Afaik you can do it using the ListView_GetItemPosition macro
(ListView_GetItemCount to know how many Icons are present).
However I've heard that there are different kind of problems while working
with these messages (these macros use internally different messages) and the
Desktop (the windows Desktop is a Listview!).
The only way I know to avoid these problems is to install an Hook into the
interested Thread (or directly into the process if you prefer) and to call
these functions directly from the Remote Address Space (the injected DLL).
If you want any code sample simply ask.

Bye! :)

--
- Carlo -
c.b...@libero.it

Charles Hacker

unread,
May 28, 2001, 10:58:34 PM5/28/01
to
Urs Klingsporn wrote:
> Is there a way to get the positions of the desktop icons?

I have written such an app, it was based on the following FAQ.

FAQ408D.txt Getting the Win95 Desktop ListView Handle
Category :Windows API
Platform :All
Product :All 32 bit

Question:
How do I get a handle to the Windows 95 Desktop to access the
Desktop icons?

Answer:
The Windows 95 Desktop is overlayed with a ListView component.
You simply need to get a handle to the ListView. Example:

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;

Once you have the handle, you can use the list view-related API
functions in the CommCtrl unit to manipulate the desktop. See
the LVM_xxxx messages in the Win32 online help.

For example the following line of code:

SendMessage(GetDesktopListViewHandle,LVM_ALIGN,LVA_ALIGNLEFT,0);

// This is an error in the TI, it should be
SendMessage(GetDesktopListViewHandle,LVM_ARRANGE,LVA_ALIGNLEFT,0);

will align the desktop icons to the left side of the Windows 95
desktop.

--
Charles Hacker
Lecturer in Electronics and Computing
School of Engineering
Griffith University - Gold Coast
Australia

Carlo Bertuccini

unread,
May 29, 2001, 4:28:32 PM5/29/01
to
Charles,

"Charles Hacker" <repl...@borland.newsgroups> ha scritto:

> function GetDesktopListViewHandle: THandle;

This function retrieve the Handle of the Desktop's ListView and it is
correct, however if you try to compile what follows:

var Info: TPoint
...
ListView_GetItemPosition(GetDesktopListViewHandle,1,Info);

you will obtain a dialog error, the same result if you use the SendMessage:

SendMessage(GetDesktopListViewHandle,LVM_GETITEMPOSITION,1,Integer(@info));

I suppose that the voices I've heard about these problems were true.
Probably the only solution is the hook ... a DLL like that should solve the
problem:

---
library DesktopManager;

uses
SysUtils,
Classes,
Messages,
Windows,
CommCtrl;

Var hookHandle: hHook;
firstHookCall: Boolean = true;

{$R *.RES}

Procedure DLLMainCode; stdcall;
var TheHandle: THandle;
Counter: Integer;
Coord: Array of TPoint;
CopyData: TCopyDataStruct;
Begin
TheHandle := FindWindow('ProgMan',nil);
TheHandle := GetWindow(TheHandle,GW_CHILD);
TheHandle := GetWindow(TheHandle,GW_CHILD);
SetLength(Coord,ListView_GetItemCount(TheHandle)-1);
for Counter := 0 to (ListView_GetItemCount(TheHandle)-1) do
ListView_GetItemPosition(TheHandle,Counter,Coord[Counter]);
with CopyData do
begin
dwData:=0;
cbData:=SizeOf(Coord);
lpData:=Coord;
end;
SendMessage(FindWindow('TManager','Manager'), WM_COPYDATA, hInstance,
Integer(@CopyData));
end;


function HookProc (Code: Integer; wParam: Integer; lParam: Integer)
:Integer; stdcall;
begin
if firstHookCall then begin
firstHookCall := False;
DLLMainCode;
end;
Result := CallNextHookEx(hookHandle, Code, wParam, lParam);
end;

Procedure Load (Tid: dWord); stdcall;
begin
hookHandle := SetWindowsHookEx(WH_GETMESSAGE, @HookProc, hInstance, Tid);
end;

procedure UnHook; stdcall;
begin
UnhookWindowsHookEx(hookHandle);
end;


Exports
Load,
UnHook;

end.
---

I have not tested it (just compiled) ....
The IPC technique I've used is the WM_COPYDATA message!

Regards,

Michael Winter

unread,
May 29, 2001, 4:34:59 PM5/29/01
to
Charles Hacker schrieb:

> if PChar(S) <> 'SysListView32' then Result := 0;
> end;
>
> Once you have the handle, you can use the list view-related API
> functions in the CommCtrl unit to manipulate the desktop. See
> the LVM_xxxx messages in the Win32 online help.
>
> For example the following line of code:
>
> SendMessage(GetDesktopListViewHandle,LVM_ALIGN,LVA_ALIGNLEFT,0);

Note that if you use LVM_messages with pointers to data structures or
strings, it is required that the pointer you provide is valid in the
process which hosts the Listview control. You'd need a hook or
Read/WriteProcessMemory in that case.

-Michael


JinTonic

unread,
May 31, 2001, 2:15:51 AM5/31/01
to
Hi

But what about NT4/2000?
Which functions to use to manipulate shortcuts(icons on desktop)?
Meaning get icons positions and set ones.

Best regards,
JinTonic

"Charles Hacker" <repl...@borland.newsgroups> ???????/???????? ? ????????
?????????: news:3B13105A...@borland.newsgroups...

Michael Winter

unread,
May 31, 2001, 4:26:20 PM5/31/01
to
JinTonic schrieb:

>
> Hi
>
> But what about NT4/2000?
> Which functions to use to manipulate shortcuts(icons on desktop)?
> Meaning get icons positions and set ones.

I posted an example to the attachments group, containing a class that
lets you insert and access space inside another processes memory
context.

-Michael

JinTonic

unread,
Jun 1, 2001, 4:28:56 AM6/1/01
to
So?

"Michael Winter" <delph...@gmx.net> ???????/???????? ? ???????? ?????????:
news:3b16a8a4_1@dnews...

0 new messages