473,406 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Retrieving Desktop Icon Positions

Hi,

I'd like to be able to read the positions of all the Icons on my WinXP
desktop. I've had a look around to see how to do it and I've come up
with the code below...but it doesn't work. :o(

The x and y properties of my POINT structure are always zero. It seems
the structure isn't getting updated at all from the SendMessage
function and so the code just displays the default values.

Any suggestions?

Thanks in advance, AF.
-----------------

using System;
using System.Runtime.InteropServices;

namespace DesktopIcons
{
class GetInfo
{
const uint LVM_FIRST = 0x1000;
const uint LVM_GETITEMCOUNT = (LVM_FIRST + 4);
const uint LVM_GETITEMPOSITION = (LVM_FIRST + 16);

[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string
lpWindowName);

[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr
childAfter, string className, string windowTitle);

[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, uint Msg, int
wParam, IntPtr lParam);

[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, uint Msg, int
wParam, ref IntPtr lParam);

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct POINT
{
public long x;
public long y;
}

[STAThread]
static void Main(string[] args)
{

IntPtr handle = FindWindow("progman", null);
handle = FindWindowEx(handle, IntPtr.Zero, "shelldll_defview",
null);
handle = FindWindowEx(handle, IntPtr.Zero, "syslistview32", null);

// Get the Number of Icons
int iconCount = SendMessage(handle, LVM_GETITEMCOUNT, 0,
IntPtr.Zero);

Console.WriteLine("Number of Icons on Desktop: " +
iconCount.ToString());

IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(POINT)) );

POINT p;
p.x = 0;
p.y = 0;

Marshal.StructureToPtr(p, ptr, true);

// Get First Icon Position
SendMessage(handle, LVM_GETITEMPOSITION, 0, ref ptr);

p = (POINT)Marshal.PtrToStructure(ptr, typeof(POINT));

Console.WriteLine("First Icon Position: (x = " + p.x.ToString() + ",
y = " + p.y.ToString() + ")");

Marshal.FreeHGlobal(ptr);
}

}
}

Feb 26 '06 #1
0 4192

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Eskimo Joe | last post by:
I am trying to create a desktop icon using VB6. is this possible? -p
2
by: Dickyb | last post by:
Extracting an Icon and Placing It On The Desktop (C# Language) I constructed a suite of programs in C++ several years ago that handle my financial portfolio, and now I have converted them to...
3
by: Michael D. Murphy | last post by:
Hi, I am searching for a way to creat desktop shortcuts when running the setup files that were created within a VB solution using the setup wizard. Thanks, Michael
1
by: Mike L | last post by:
How do I set the publish wizard to add a shortcut to the client's desktop?
1
by: Henrik | last post by:
I'm sorry to trouble you once again but somebody must know how to get a list of the desktop icons and their respective positions. I know that I have to look into shell but I have no idea how to...
0
by: avec.fromage | last post by:
Hi, I'd like to be able to read the positions of all the Icons on my WinXP desktop. I've had a look around to see how to do it and I've come up with the code below...but it doesn't work. :o( ...
0
by: Steve | last post by:
After installing my application (which I developed using Visual Studio 2005) on a target desktop, the desktop icon shows the icon that is assigned to the application exe - which is what I want. ...
0
by: pvishweshwar | last post by:
Hi All, am developing one application in which i have to retrieve the msolap dimension members properties data.In this till now am able to get the member values properly.But the problem is am...
1
by: laredotornado | last post by:
Hi, When I save out an HTML file to my desktop (I'm using Windows XP), it saves with the Firefox icon, presumably because I have Firefox as the default application to open my HTML files. Is it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.