Turns out I was sending the wrong values in my sendmessage.
Code to count number of icons and then move one icon to a certain x,y position(This will move the first icon in the list to the top left corner position, in my case I have nothing in the spot.
require 'ffi'
module Win32
extend FFI::Library
ffi_lib 'user32'
ffi_convention :stdcall
enum :lvm, [:LVM_GETITEMCOUNT, 4100,
:LVM_DELETEALLITEMS, 4105,
:LVM_GETNEXTITEM, 4108,
:LVM_SETITEMPOSITION, 4111,
:LVM_GETITEMPOSITION, 4112,
:LVM_ARRANGE, 4118,
:LVM_UPDATE, 4138,
:LVM_GETITEMTEXTA, 4141,
:LVM_SETITEMTEXTA, 4142 ]
enum :parameter, [:GW_CHILD, 5,
:LVS_ALIGNLEFT, 2048 ]
# Uses C Function to find the window handle(HWND) of a window with the specified text, in this case 'ProgMan'
attach_function :findWindow,
:FindWindowA,[ :string, :parameter ], :int
# Gets passed in window handle's child window
attach_function :getChildWindow,
:GetWindow, [ :ulong, :parameter], :int
# Sends a message to the passed in window
attach_function :sendMessage,
:SendMessageA, [ :ulong, :lvm, :parameter, :long], :int
end # end of Win32
def makeLPARAM(w1, w2)
return (w2<<16) | w1
end
# Finds Windows handle for FolderView, SysListView32 which is the icon list
DesktopHandle = Win32.findWindow('ProgMan', 0)
DesktopHandle = Win32.getChildWindow(DesktopHandle, :GW_CHILD)
DesktopHandle = Win32.getChildWindow(DesktopHandle, :GW_CHILD)
# Gets count of icons on desktop
Win32.sendMessage(DesktopHandle, :LVM_GETITEMCOUNT, 0, 0)
# Moves the first icon in the list to the top leftmost position on the screen
Win32.sendMessage(DesktopHandle, :LVM_SETITEMPOSITION, 0, makeLPARAM(10, 1))
This was a lot more difficult then I imagined! Although a lot was not having the right values, can anyone point out a place that I should have looked for the values in the first place?