这是VB的一段例子,它都可以正常调用:<br><br>Option Explicit<br>Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long<br>Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wmsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long<br>Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long<br>Private Const LVM_GETTITEMCOUNT& = (&H1000 + 4)<br>Private Const LVM_SETITEMPOSITION& = (&H1000 + 15)<br>Private Const LVM_FIRST = &H1000<br>Private Const LVM_GETITEMPOSITION = (LVM_FIRST + 16)<br>Private Const LVM_GETITEMTEXT = LVM_FIRST + 45<br>Private Const LVM_GETIMAGELIST = (LVM_FIRST + 2)<br>Private Const LVSIL_NORMAL = 0<br>Private Const LVM_GETITEM = (LVM_FIRST + 5)<br>Private Const LVM_ARRANGE = (LVM_FIRST + 22)<br>Private Type POINTAPI<br>X As Long<br>y As Long<br>End Type<br>Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long<br>Private Const SPI_GETWORKAREA = 48<br><br>Public Sub GetDeskIconPosition(ByVal SX As String)<br>'Dim hdesk As Long<br>Dim WorkArea As RECT<br>Dim DeskWidth As Long<br>Dim DeskHeight As Long<br>Dim Pointx() As POINTAPI<br>Dim Hdesk As Long<br>Hdesk = GetrDeskIconHandle()<br>SystemParametersInfo SPI_GETWORKAREA, 0, WorkArea, 0<br>DeskWidth = WorkArea.Right<br>DeskHeight = WorkArea.Bottom<br>Dim IconCount As Long<br>IconCount = SendMessage(Hdesk, LVM_GETTITEMCOUNT, 0, 0)<br>Dim TR As Long, J As Long, Ji As Long<br>Dim RF As Long, Frt As Boolean, Rf1 As Long, FR As Boolean, LT As Boolean<br>Dim Rf2 As Long<br>LT = False<br>FR = False<br>Frt = False<br>TR = 0<br>J = 0<br>ReDim Pointx(IconCount)<br>For TR = 0 To IconCount - 1<br>Ji = Ji + 1<br><br>DoEvents<br>Ds: Select Case SX<br>Case "桌面图标左顶对齐"<br>Pointx(TR).y = 77 * (J + 1) - 77<br>Pointx(TR).X = 77 * Ji - 50<br>If Pointx(TR).X > DeskWidth - 10 Then<br>Ji = 1<br>J = J + 1<br>GoTo Ds<br>End If<br>Case "桌面图标右顶对齐" '右顶对齐<br><br>Pointx(TR).y = 77 * (J + 1) - 77<br>Pointx(TR).X = DeskWidth - 77 * Ji + 10<br>If Pointx(TR).X < 10 Then<br>Ji = 1<br>J = J + 1<br>GoTo Ds<br>End If<br>Case "桌面图标左对齐" '左对齐<br>Pointx(TR).y = 77 * Ji - 77<br>Pointx(TR).X = 77 * J + 10<br><br>If Pointx(TR).y > DeskHeight - 40 Then<br>Ji = 1<br>J = J + 1<br>GoTo Ds<br>End If<br><br>Case "桌面图标右对齐" '右对齐<br><br>Pointx(TR).y = 77 * Ji - 77<br>Pointx(TR).X = DeskWidth - 77 * J - 77<br>If Pointx(TR).y > DeskHeight - 40 Then<br>Ji = 1<br>J = J + 1<br>GoTo Ds<br>End If<br>Case "桌面图标左右环绕" '环绕<br>'左顶对齐<br>If ((DeskWidth - 77) > (77 * Ji - 50)) And Frt = False Then<br>Pointx(TR).y = 0 '77 * (J + 1) - 77<br>Pointx(TR).X = 77 * Ji - 50<br>RF = Pointx(TR).X<br>Else<br>'右对齐<br>If Frt = False Then<br>Ji = 2<br>Frt = True<br>End If<br>If FR = False And ((DeskHeight - 40) > (77 * Ji - 77)) Then<br>Pointx(TR).X = RF<br>Pointx(TR).y = 77 * Ji - 77<br>Rf1 = Pointx(TR).y<br>Else<br>'右底对齐<br>If FR = False Then<br>FR = True<br>Ji = 2<br>End If<br>If LT = False And DeskWidth - 77 * Ji > 10 Then<br>Pointx(TR).y = Rf1<br>Pointx(TR).X = DeskWidth - 77 * Ji<br>Rf2 = Pointx(TR).X<br>Else<br>'左对齐<br>If LT = False Then<br>LT = True<br>Ji = 2<br>End If<br>Pointx(TR).X = Rf2<br>Pointx(TR).y = DeskHeight - 77 * Ji<br>End If<br>End If<br>End If<br>Case "桌面图标右底对齐" '右底对齐<br>Pointx(TR).X = DeskWidth - 77 * Ji<br>Pointx(TR).y = DeskHeight - 77 * (J + 1)<br>If Pointx(TR).X < 10 Then<br>Ji = 1<br>J = J + 1<br>GoTo Ds<br>End If<br>End Select<br>SendMessageLong Hdesk, LVM_SETITEMPOSITION, TR, CLng(Pointx(TR).X + Pointx(TR).y * &H10000)<br>Next TR<br>Erase Pointx()<br>End Sub<br><br>Public Function GetrDeskIconHandle() As Long<br>Dim Wnd As Long<br>Wnd = FindWindow("progman", vbNullString)<br>Wnd = FindWindowEx(Wnd, 0, "shelldll_defview", vbNullString)<br>Wnd = FindWindowEx(Wnd, 0, "syslistview32", vbNullString)<br>GetrDeskIconHandle = Wnd<br>End Function