Jump to content

Recognizing icons on desktop


rliiack
 Share

Recommended Posts

Hi,

#include <GuiListView.au3>
#include <Misc.au3>

Global $hListView, $aOrigPos

$hListView = ControlGetHandle("[CLASS:Progman]", "", "[CLASS:SysListView32;INSTANCE:1]")

$aOrigPos = _GUICtrlListView_GetItemPosition($hListView, 0)

WinMinimizeAll()

_GUICtrlListView_SetItemPosition($hListView, 0, $aOrigPos[0] + 500, $aOrigPos[1])

Do
    Sleep(100)
Until _IsPressed("1B") ;Esc to restore the icon original position.

_GUICtrlListView_SetItemPosition($hListView, 0, $aOrigPos[0], $aOrigPos[1])

WinMinimizeAllUndo()

Cheers

Link to comment
Share on other sites

Thanks, I know how it works now. However icons did not move at all... I checked and all the icons have the same title and controlID. How do I find the position for the specific icon, because I think the program didn't know which icon we are talking failing it to work. Thanks for your time!

Edited by rliiack

My Projects:Smart Icons

Link to comment
Share on other sites

Thanks, I know how it works now. However icons did not move at all... I checked and all the icons have the same title and controlID. How do I find the position for the specific icon, because I think the program didn't know which icon we are talking failing it to work. Thanks for your time!

You don't have to use the handle or control ID of the icon..

You get the handle to the desktop eg: SysListView32 ..

Then use the listview udf supplied with autoit to get or set the icon index, position or text.

Once you have icons position you can then use MouseGetPos() and you can use _GUICtrListView_HitTest() to see if your mouse is over an icon or not.

Cheers

Link to comment
Share on other sites

Hi again,

Here's a snippet of code to show you how to get all the desktop icons text and X and Y positions..

#include <GuiListView.au3>
#include <Array.au3>

Opt("MustDeclareVars", 1)

Global $hListView, $iIconCount, $aIconPos

; Get a handle to the desktop listview (where your desktop icons are located)
$hListView = ControlGetHandle("[CLASS:Progman]", "", "[CLASS:SysListView32;INSTANCE:1]")
If @error Then
    MsgBox(64, "Error..", "Unable to get desktop handle.", 3)
    Exit
Else
    ; Use the handle to get a count of how many icons are on the desktop.
    $iIconCount = _GUICtrlListView_GetItemCount($hListView)

    ; If the count of icons is greater then 0 then we found desktop icons..
    If $iIconCount > 0 Then
        ; Now store all the Icon text, x & y position in an array so we can easily do things with the icons..
        Dim $aIconPos[$iIconCount][3]
        For $i = 0 To UBound($aIconPos, 1) - 1
            $aIconPos[$i][0] = _GUICtrlListView_GetItemText($hListView, $i)
            $aIconPos[$i][1] = _GUICtrlListView_GetItemPositionX($hListView, $i)
            $aIconPos[$i][2] = _GUICtrlListView_GetItemPositionY($hListView, $i)
        Next
    Else
        ; If we didn't find any icons then there's no icons on the desktop.
        MsgBox(64, "No desktop icons", "No desktop icons found.", 3)
        Exit
    EndIf
EndIf

_ArrayDisplay($aIconPos, "Icon Text - Icon X Position - Icon Y Position")

Cheers

Edited by smashly
Link to comment
Share on other sites

Hi, yep that's correct, you'll just need to do some maths and loops to work out the mouse in relation to an icon.

For the x and y value in _GUICtrListView_HitTest() you could use _WinAPI_GetMousePosX() and _WinAPI_GetMousePosY().

you'll need to compare the mouse values against the values you have in your array.

Cheers

Link to comment
Share on other sites

  • 3 months later...

Hi again,

Here's a snippet of code to show you how to get all the desktop icons text and X and Y positions..

#include <GuiListView.au3>
#include <Array.au3>

Opt("MustDeclareVars", 1)

Global $hListView, $iIconCount, $aIconPos

; Get a handle to the desktop listview (where your desktop icons are located)
$hListView = ControlGetHandle("[CLASS:Progman]", "", "[CLASS:SysListView32;INSTANCE:1]")
If @error Then
    MsgBox(64, "Error..", "Unable to get desktop handle.", 3)
    Exit
Else
    ; Use the handle to get a count of how many icons are on the desktop.
    $iIconCount = _GUICtrlListView_GetItemCount($hListView)

    ; If the count of icons is greater then 0 then we found desktop icons..
    If $iIconCount > 0 Then
        ; Now store all the Icon text, x & y position in an array so we can easily do things with the icons..
        Dim $aIconPos[$iIconCount][3]
        For $i = 0 To UBound($aIconPos, 1) - 1
            $aIconPos[$i][0] = _GUICtrlListView_GetItemText($hListView, $i)
            $aIconPos[$i][1] = _GUICtrlListView_GetItemPositionX($hListView, $i)
            $aIconPos[$i][2] = _GUICtrlListView_GetItemPositionY($hListView, $i)
        Next
    Else
        ; If we didn't find any icons then there's no icons on the desktop.
        MsgBox(64, "No desktop icons", "No desktop icons found.", 3)
        Exit
    EndIf
EndIf

_ArrayDisplay($aIconPos, "Icon Text - Icon X Position - Icon Y Position")

Cheers

Hi,

This is great code, and is exactly what I'm looking for - using it, I've written a couple of routines for getting & setting the desktop icon locations. Everything works fine on XP 32-bit, but unfortunately it fails to get the icon names on Windows 7 x64 (the culprit is the _GUICtrlListView_GetItemText() call, which returns a null string on that platform). I suspect it's Windows 7 that is the problem rather than the 64-bit architecture. It can still "see" all the icons and their positions - just not their names.

Can you suggest how to get the icon name on W7 x64?

Thanks (and happy New Year to all)!

Link to comment
Share on other sites

Everything works fine on XP 32-bit, but unfortunately it fails to get the icon names on Windows 7 x64 (the culprit is the _GUICtrlListView_GetItemText() call, which returns a null string on that platform). I suspect it's Windows 7 that is the problem rather than the 64-bit architecture. It can still "see" all the icons and their positions - just not their names.

Weird this works just fine on Windows 7 32-bit. I see all of my icon names. Perhaps it is the 64-bit?
Link to comment
Share on other sites

Weird this works just fine on Windows 7 32-bit. I see all of my icon names. Perhaps it is the 64-bit?

I stand corrected - I only have W7 x64 and XP x86, I took a guess as to which was more likely to be the cause - and got it wrong. Great start to the year ;)

Thanks for the really quick response!

Link to comment
Share on other sites

I stand corrected - I only have W7 x64 and XP x86, I took a guess as to which was more likely to be the cause - and got it wrong. Great start to the year ;)

Thanks for the really quick response!

Maybe my reply was ambiguous.. the problem still has me tearing out what's left of my hair, and help would be much appreciated if anyone can shed light on this.. On XP 32-bit the _GUICtrlListView_GetItemText($hListView, $i) call returns the icon label; on Win7 x64, it returns blank. So does _GUICtrlListView_GetItemTextArray(). Checking the desktop icons with _GUICtrlListView_MapIndexToID() shows that the ID of every icon is "-1".

I am... puzzled.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...