Sign in to follow this  
p0is0n

[C#] Setting Desktop Icon Position

Recommended Posts

Hi, I am trying to make a small C# application that allows you to save and restore the desktop shortcuts. From reading : http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/d7df8a4d-fc0f-4b62-80c9-7768756456e6 I have managed (with only slight alterations) to get the desktop icons positions and names. When I try to set an icons position I use :
                uint bytesRead = 0;
                long[] lParam = new long[1];
                lParam[0] = MakeLParam(200, 200);
                WriteProcessMemory(process, address, Marshal.UnsafeAddrOfPinnedArrayElement(lParam, 0),
                    Marshal.SizeOf(typeof(long)), ref bytesRead);
                SendMessage(desktop, LVM_SETITEMPOSITION, 0, address.ToInt32());
MakeLParam is defined as :
        public long MakeLParam(int loWord, int hiWord)
        {
            return (long)((hiWord << 16) | (loWord & 0xffff));
        }
process and address are both valid as are used in previous calls to get the icon information. No matter what position I define for the desktop icon the position is set to : X = 14 Y = 688 No functions fail and bytesRead is always 4. I am pretty sure the MakeLParam function is correct. Can anyone see where I might be going wrong? Thanks! [edit] I have changed the int return from MakeLParam and the lParam variable to longs as I think that is what they should be. The problem is still the same though. [edit] After playing around it seems that the set icon position message can be sent without writing anything to the desktop list view process. Still not sure what is wrong with the above code :S I am not sure if this is the right way to do it, but as it works I think I'll just leave it as it is. [Edited by - p0is0n on March 8, 2010 8:25:54 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this