473,785 Members | 2,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_GETITEMCOUN T = (LVM_FIRST + 4);
const uint LVM_GETITEMPOSI TION = (LVM_FIRST + 16);

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

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

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

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

[StructLayout(La youtKind.Sequen tial, CharSet=CharSet .Ansi)]
public struct POINT
{
public long x;
public long y;
}

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

IntPtr handle = FindWindow("pro gman", null);
handle = FindWindowEx(ha ndle, IntPtr.Zero, "shelldll_defvi ew",
null);
handle = FindWindowEx(ha ndle, IntPtr.Zero, "syslistview32" , null);

// Get the Number of Icons
int iconCount = SendMessage(han dle, LVM_GETITEMCOUN T, 0,
IntPtr.Zero);

Console.WriteLi ne("Number of Icons on Desktop: " +
iconCount.ToStr ing());

IntPtr ptr = Marshal.AllocHG lobal(Marshal.S izeOf(typeof(PO INT)));

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

Marshal.Structu reToPtr(p, ptr, true);

// Get First Icon Position
SendMessage(han dle, LVM_GETITEMPOSI TION, 0, ref ptr);

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

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

Marshal.FreeHGl obal(ptr);
}

}
}

Feb 26 '06 #1
0 4227

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

Similar topics

5
27029
by: Eskimo Joe | last post by:
I am trying to create a desktop icon using VB6. is this possible? -p
2
2817
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 C#. The only significant problem that I have encountered in the conversion is this one - extracting an icon from the 'KTEntryPoint' program into the software suite and placing that icon on the PC Desktop.
3
4194
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
7271
by: Mike L | last post by:
How do I set the publish wizard to add a shortcut to the client's desktop?
1
4496
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 do it...! Regards I've found this bit of vb code but I don't know how to translate it
0
4383
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( 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
0
1290
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. When I click on the desktop icon to run the application, the icon will flip between the desired icon and a Windows default icon(file/folder?) before the application is loaded. Does anyone know why this happens?
0
1189
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 not able to retrieve the properties values.Can any one help on this. am sending that part of code how am retrieving the member data. For intDimCount = 0 To cst.Axes(0).DimensionCount - 1
1
8242
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 possible to have the desktop icon be the favicon.ico file of the web site from which I'm saving the page? Thanks, - Dave
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10324
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8971
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.