night_prince
Member
- Joined
- Dec 17, 2006
- Messages
- 24
- Programming Experience
- Beginner
Hi every body
i am trying to reach the desktop Icons using VB.net
i found an old code that use FindWIndow
And SendMessage whic sends the LVM_GETITEMPOSITION
and LVM_SETITEMPOSITION
but its using vb6
this what i converted to vb.net
but its not working and Explore.exe is throwing an exception
when it reaches to SendMessage
add that i dont know how to pass An PoinAPi Structure to the API
SendMessage (hwnd ,msg,lparam, wparam as POINTAPI)
Can Any one Help ME
i am trying to reach the desktop Icons using VB.net
i found an old code that use FindWIndow
And SendMessage whic sends the LVM_GETITEMPOSITION
and LVM_SETITEMPOSITION
but its using vb6
VB.NET:
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Runtime.InteropServices.Marshal[/SIZE]
[SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] form1[/SIZE]
[SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] icount [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ic [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE]
[SIZE=2]hdesk = FindWindow([/SIZE][SIZE=2][COLOR=#800000]"progman"[/COLOR][/SIZE][SIZE=2], vbNullString)[/SIZE]
[SIZE=2]hdesk = FindWindowEx(hdesk, 0, [/SIZE][SIZE=2][COLOR=#800000]"shelldll_defview"[/COLOR][/SIZE][SIZE=2], vbNullString)[/SIZE]
[SIZE=2]hdesk = FindWindowEx(hdesk, 0, [/SIZE][SIZE=2][COLOR=#800000]"syslistview32"[/COLOR][/SIZE][SIZE=2], vbNullString)[/SIZE]
[SIZE=2][COLOR=#008000]'hdesk is the handle of the Desktop's listview[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'find out how many icons reside on the desktop[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'icount = SendMessage(hdesk, LVM_GETITEMCOUNT, 0, 0&)[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'icount = SendMessage(hdesk, LVM_ARRANGE, 0, 0&)[/COLOR][/SIZE]
[SIZE=2]ic = 5[/SIZE]
[SIZE=2]icount = SendMessageP(hdesk, LVM_GETITEMPOSITION, ic, po)[/SIZE]
[SIZE=2]MsgBox(Err.LastDllError)[/SIZE]
[SIZE=2][COLOR=#008000]' CopyMemory(po, ps, 4)[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'MsgBox(SizeOf(ps).ToString)[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'MsgBox(Marshal.GetLastWin32Error.ToString)[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE]
VB.NET:
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Runtime.InteropServices[/SIZE]
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Runtime.InteropServices.Marshal[/SIZE]
[SIZE=2][COLOR=#0000ff]Module[/COLOR][/SIZE][SIZE=2] Module1[/SIZE]
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Declare [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] FindWindow [/SIZE][SIZE=2][COLOR=#0000ff]Lib [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"user32.dll" [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Alias [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"FindWindowA"[/COLOR][/SIZE][SIZE=2] ( _[/SIZE]
[SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] lpClassName [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2], _[/SIZE]
[SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] lpWindowName [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32[/SIZE]
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Declare [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] FindWindowEx [/SIZE][SIZE=2][COLOR=#0000ff]Lib [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"user32.dll" [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Alias [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"FindWindowExA"[/COLOR][/SIZE][SIZE=2] ( _[/SIZE]
[SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] hWnd1 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32, _[/SIZE]
[SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] hWnd2 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32, _[/SIZE]
[SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] lpsz1 [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2], _[/SIZE]
[SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] lpsz2 [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32[/SIZE]
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Declare [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] SendMessage [/SIZE][SIZE=2][COLOR=#0000ff]Lib [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"user32.dll" [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Alias [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"SendMessageA"[/COLOR][/SIZE][SIZE=2] ( _[/SIZE]
[SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] hwnd [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32, _[/SIZE]
[SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] wMsg [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32, _[/SIZE]
[SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] wParam [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32, _[/SIZE]
[SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] lParam [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32[/SIZE]
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Declare [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] SendMessageP [/SIZE][SIZE=2][COLOR=#0000ff]Lib [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"user32.dll" [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Alias [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"SendMessageA"[/COLOR][/SIZE][SIZE=2] ( _[/SIZE]
[SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] hwnd [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32, _[/SIZE]
[SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] wMsg [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32, _[/SIZE]
[SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] wParam [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32, _[/SIZE]
[SIZE=2][COLOR=#0000ff]ByRef[/COLOR][/SIZE][SIZE=2] lParam [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] POINTAPI) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32[/SIZE]
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][SIZE=2] LVM_GETITEMCOUNT [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32 = (LVM_FIRST + 4)[/SIZE]
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][SIZE=2] LVM_GETITEMPOSITION [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32 = (LVM_FIRST + 16)[/SIZE]
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][SIZE=2] LVM_GETITEMTEXTA [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32 = (LVM_FIRST + 45)[/SIZE]
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][SIZE=2] LVM_SETITEMPOSITION [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32 = (LVM_FIRST + 15)[/SIZE]
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][SIZE=2] LVM_FIRST [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32 = &H1000[/SIZE]
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] hdesk [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][SIZE=2] LVM_ARRANGE [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32 = (LVM_FIRST + 22)[/SIZE]
[SIZE=2]<StructLayout(LayoutKind.Sequential)> _[/SIZE]
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Structure[/COLOR][/SIZE][SIZE=2] POINTAPI[/SIZE]
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] x [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32[/SIZE]
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] y [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32[/SIZE]
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Structure[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Declare [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] CopyMemory [/SIZE][SIZE=2][COLOR=#0000ff]Lib [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"kernel32.dll" [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Alias [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"RtlMoveMemory"[/COLOR][/SIZE][SIZE=2] ( _[/SIZE]
[SIZE=2][COLOR=#0000ff]ByRef[/COLOR][/SIZE][SIZE=2] Destination [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] POINTAPI, _[/SIZE]
[SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] Source [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32, _[/SIZE]
[SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] Length [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32)[/SIZE]
[SIZE=2]<MarshalAs(UnmanagedType.Struct)> _[/SIZE]
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] po [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] POINTAPI[/SIZE]
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] ps [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Int32[/SIZE]
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Module[/COLOR][/SIZE]
this what i converted to vb.net
but its not working and Explore.exe is throwing an exception
when it reaches to SendMessage
add that i dont know how to pass An PoinAPi Structure to the API
SendMessage (hwnd ,msg,lparam, wparam as POINTAPI)
Can Any one Help ME