Desktop Icons

hallo zusammen
ich muss unbedingt wissen wo die koordinaten gespeichert sind auf denen die icons plaziert werden
in der registry hab ich schon reichlich gesucht aber nichts gefunden :frowning:
wenn ihrs nicht genau wisst wo vermutet ihr? wo könnte ich suchen?
danke im vorraus
mfg Luemmel

Hallo

Ich habe in meiner ziemlich ungeordneten Code-Sammlung ein Codemodul
(*.BAS) mit folgendem Inhalt gefunden:

':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


> > > > > > > > > >

' Locate Desktop Icons Source Code VB6
' Created 11 April 1999
' By Paul Pavlic
' abuse and advice to [email protected]
' Feel free to use anyway you can
' FreeWare
' Works on Win95
'
' Special thanks to Bruce McKinney
' Author of Hardcore Visual Basic
' A wonderful book with a great many insights
'
' Why?
' I looked all over the Internet, and never once saw any working
' code to do this, thought I would make a contribution
' Why call it Paulies Pet?
' Was the name of my Desktop Pet in VB3 rewriting it now to VB6
'
' This code resolves Explorer page faults when trying to send
' LVM\_GETITEMPOSITION to the Desktop Listview
'
'\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

'constants
Public Const GENERIC\_READ = &H80000000
Public Const GENERIC\_WRITE = &H40000000
Public Const OPEN\_ALWAYS = 4
Public Const FILE\_ATTRIBUTE\_NORMAL = &H80
Public Const SECTION\_MAP\_WRITE = &H2
Public Const FILE\_MAP\_WRITE = SECTION\_MAP\_WRITE

'NOT documented in Win32api.txt
Public Const PAGE\_READWRITE As Long = &H4

Const LVM\_GETTITEMCOUNT& = (&H1000 + 4)
Const LVM\_SETITEMPOSITION& = (&H1000 + 15)
Const LVM\_FIRST = &H1000
Const LVM\_GETITEMPOSITION = (LVM\_FIRST + 16)
Const LVM\_GETITEMTEXT = LVM\_FIRST + 45

'damn hell of a lot of declares
'copymemory \*3 avoid byval in code - bug? works this way
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" \_
(hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Sub CopyMemoryOne Lib "kernel32" Alias 
"RtlMoveMemory" \_
(ByVal hpvDest&, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Sub CopyMemoryTwo Lib "kernel32" Alias 
"RtlMoveMemory" \_
(hpvDest As Any, ByVal hpvSource&, ByVal cbCopy As Long)

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" 
\_
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam 
\_
As Any) As Long
Declare Function SendMessageByLong& Lib "user32" Alias "SendMessageA" 
\_
(ByVal hwnd&, ByVal wMsg&, ByVal wParam&, ByVal lParam&amp:wink:

Private Declare Function FindWindow& Lib "user32" Alias "FindWindowA" 
\_
(ByVal lpClassName As String, ByVal lpWindowName As String)
Private Declare Function FindWindowEx& Lib "user32" Alias \_
"FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter \_
As Long, ByVal lpClassName As String, ByVal lpWindowName As String)

'declares for printing to the desktop or other window for debug 
purposes
Public Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal \_
hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As \_
String, ByVal nCount As Long) As Long
Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As 
Long
Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, \_
ByVal hdc As Long) As Long
Public Declare Function InvalidateRect Lib "user32" (ByVal hwnd As 
Long, \_
lpRect As Any, ByVal bErase As Long) As Long

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As 
Long)

'declares for memory-mapped files
Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" 
\_
(ByVal lpFileName As String, ByVal dwDesiredAccess As Long, \_
ByVal dwShareMode As Long, lpSecurityAttributes As Any, \_
ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As \_
Long, ByVal hTemplateFile As Long) As Long
' changed lpFileMappigAttributes to Any, makes life much easier
Public Declare Function CreateFileMappingTwo Lib "kernel32" Alias \_
"CreateFileMappingA" (ByVal hFile As Long, lpFileMappigAttributes \_
As Any, ByVal flProtect As Long, ByVal dwMaximumSizeHigh As Long, \_
ByVal dwMaximumSizeLow As Long, ByVal lpName As String) As Long
Public Declare Function MapViewOfFile Lib "kernel32" (ByVal \_
hFileMappingObject As Long, ByVal dwDesiredAccess As Long, ByVal \_
dwFileOffsetHigh As Long, ByVal dwFileOffsetLow As Long, ByVal \_
dwNumberOfBytesToMap As Long) As Long
Public Declare Function UnmapViewOfFile Lib "kernel32" (lpBaseAddress 
\_
As Any) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject \_
As Long) As Long
Public Declare Function FlushViewOfFile Lib "kernel32" (ByVal 
lpBaseAddress \_
As Long, ByVal dwNumberOfBytesToFlush As Long) As Long

'type declarations
Public Type LV\_ITEM ' might need this if we ever figure out
 mask As Long ' how to retrieve the text
 iItem As Long
 iSubItem As Long
 State As Long
 stateMask As Long
 pszText As Long
 cchTextMax As Long
 iImage As Long
 lParam As Long ' I think we might need a second
 iIndent As Long ' memory mapped file
End Type

Public Type POINTAPI
 x As Long
 y As Long
End Type

Dim c As POINTAPI
Public IconPosition() As POINTAPI
Public IconPosition2() As POINTAPI
Public TempIconPosition2 As POINTAPI

'dimension some variables
Dim pNull As Long
Dim MyValue%, MyValue2%
Dim sFileName As String
Dim CurrentDirectory As String
Dim hdesk&, i%
Global icount&



Public Sub FindIcons()

'no error trapping done quick and dirty code
'this is Proof of Concept Code
'a problem for the reader 
pNull = 0
hdesk = FindWindow("progman", vbNullString)
hdesk = FindWindowEx(hdesk, 0, "shelldll\_defview", vbNullString)
hdesk = FindWindowEx(hdesk, 0, "syslistview32", vbNullString)
'hdesk is the handle of the Desktop's listview
icount = SendMessageByLong(hdesk, LVM\_GETTITEMCOUNT, 0, 0&amp:wink:
'bail if we get a zero count
If icount = 0 Then MsgBox "Error occurred: No icons found", \_
vbOKOnly, "PauliesPet": Unload Form1: End
'tell me how many icons we found
Form1.Text1.Text = Str(icount) + " icons detected "
'redimension arrays
ReDim IconPosition(icount) As POINTAPI
ReDim IconPosition2(icount) As POINTAPI

'///// create a memory-mapped file /////

CurrentDirectory = App.Path
If Right$(CurrentDirectory, 1) "\" Then \_
CurrentDirectory = CurrentDirectory + "\"

sFileName = CurrentDirectory + "TEMPPPPP.PPP"
' Open file
hFile = CreateFile(sFileName, GENERIC\_READ Or GENERIC\_WRITE, 0, \_
 ByVal pNull, OPEN\_ALWAYS, FILE\_ATTRIBUTE\_NORMAL, \_
 pNull)
' get handle
hFileMap = CreateFileMappingTwo(hFile, ByVal pNull, PAGE\_READWRITE, \_
0, 16, "MyMapping")
' Get pointer to memory representing file
pFileMap = MapViewOfFile(hFileMap, FILE\_MAP\_WRITE, 0, 0, 0)

For i = 0 To icount - 1
 'lparam is mem-map file Pointer
 Call SendMessageByLong(hdesk, LVM\_GETITEMPOSITION, i, pFileMap)
 'copy returned to our POINTAPI (c.x,c.y)
 CopyMemoryTwo c, pFileMap, 8
 'show me where the icons are
 Form1.List1.AddItem Str(i + 1) + " x-" + Str(c.x) + " y-" \_
 + Str(c.y)
 'put value in our arrays
 IconPosition(i) = c
 'back up array for swapping later
 IconPosition2(i) = c
Next i

'Release resources back to windows
FlushViewOfFile pFileMap, 8
UnmapViewOfFile pFileMap
CloseHandle hFileMap
CloseHandle hFile

End Sub

Sub RefreshDesktop()

' refresh the whole desktop , we'll just invalidate everything
xcc% = InvalidateRect(0, ByVal 0, 0)

End Sub

Sub RefreshIconPositions()

For i = 0 To icount - 1
'reset our icon switching array
IconPosition2(i) = IconPosition(i)
'Set icon postions back to what we found originally
Call SendMessageByLong(hdesk, LVM\_SETITEMPOSITION, i, \_
CLng(IconPosition(i).x + IconPosition(i).y \* &H10000))
Next i

End Sub

Um die Koordinaten herauszufinden, rufe die Prozedur „FindIcons“ auf.
Das obige Beispiel erfordert jedoch eine Form mit dem Namen „Form1“
sowie eine ListBox mit dem Namen „List1“. Darin werden dann die
Koordinaten ausgegeben.

Beim Beenden des Programms (QueryUnload) musst du die Prozeduren
„RefreshIconPositions“ und „RefreshDesktop“ aufrufen.

PS: Der Code stammt nicht von mir! Ich habe ihn weder ausprobiert
noch genau studiert. Also keine Garantie!

Mit freundlichen Grüssen

Samuel

Team: Name entfernt

hi
danke für die schnelle antwort :smile:
sieht doch recht vielversprechend aus der code
mfg Luemmel