Esto es un ejemplo de uso de SendMessage para enviar comandos a otras aplicaciones. Se necesita el Handle de la otra aplicación y un código que hace referencia a una acción o evento determinado. Los códigos se pueden encontrar usando la herramienta Spy++ incluida en VB y VB.Net
Este programita permite cambiar las vistas de los iconos del escritorio como si fuera un ListView y también cambia las vistas del Explorador de windows. Es como hacer "clic" en 'Vistas' del Explorador de Windows pero se hace remotamente desde el programa.
Intrucciones:
- Crea un array con dos controles OptionButton, 5 de cada uno: Option1 y Option2
En un formulario meter esto:
Código
Option Explicit Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long 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 Private Const WM_COMMAND = &H111 Private Sub Form_Load() Option1.Item(0).Caption = "Vista Miniatura" Option1.Item(1).Caption = "Mosaico" Option1.Item(2).Caption = "Iconos" Option1.Item(3).Caption = "Lista" Option1.Item(4).Caption = "Detalle" Option2.Item(0).Caption = "Vista Miniatura" Option2.Item(1).Caption = "Mosaico" Option2.Item(2).Caption = "Iconos" Option2.Item(3).Caption = "Lista" Option2.Item(4).Caption = "Detalle" End Sub Public Function VistasEscritorio(ByVal Code As Long) Dim hwProgMan As Long Dim hwDesktop As Long hwProgMan = FindWindow("Progman", "Program Manager") hwDesktop = FindWindowEx(hwProgMan, &H0, "SHELLDLL_DefView", vbNullString) SendMessage hwDesktop, WM_COMMAND, Code, &H0 End Function Public Function VistasExplorador(ByVal Code As Long) Dim hwExplorer As Long Dim ListView As Long 'Para XP hwExplorer = FindWindow("ExploreWClass", vbNullString) ListView = FindWindowEx(hwExplorer, &H0, "SHELLDLL_DefView", vbNullString) SendMessage ListView, WM_COMMAND, Code, &H0 'Para Vista/... hwExplorer = FindWindow("CabinetWClass", vbNullString) ListView = FindWindowEx(hwExplorer, &H0, "ShellTabWindowClass", vbNullString) SendMessage ListView, WM_COMMAND, Code, &H0 End Function Private Sub Option1_Click(Index As Integer) Dim Code As Long Select Case Index Case 0: Code = 28717 'Vista Miniatura Case 1: Code = 28718 'Mosaico Case 2: Code = 28713 'Iconos Case 3: Code = 28715 'Lista Case 4: Code = 28716 'Detalles End Select Call VistasEscritorio(Code) End Sub Private Sub Option2_Click(Index As Integer) Dim Code As Long Select Case Index Case 0: Code = 28717 'Vista Miniatura Case 1: Code = 28718 'Mosaico Case 2: Code = 28713 'Iconos Case 3: Code = 28715 'Lista Case 4: Code = 28716 'Detalles End Select Call VistasExplorador(Code) End Sub