elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Curso de javascript por TickTack


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Cambiar de ventana
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Cambiar de ventana  (Leído 860 veces)
dPix

Desconectado Desconectado

Mensajes: 222


¬_¬ - ¬O.o


Ver Perfil
Cambiar de ventana
« en: 25 Enero 2007, 19:40 pm »

Muy buenas, bueno, la duda es un poco simple pero es que ahora no caigo. Quiero cambiar de ventana una por una, lo hago con Sendkeys mandando Alt + Tab pero si hago eso la primera vez cambia, pero la segunda vuelve al Form, luego otra vez a la de antes y otra vez al form y quiero moverme por todas, mi método era el más simple pero no funciona. Me podeis ayudar?

Un saludo a to2.

dPix ;D


En línea

CeLaYa


Desconectado Desconectado

Mensajes: 543



Ver Perfil
Re: Cambiar de ventana
« Respuesta #1 en: 26 Enero 2007, 23:01 pm »

me encontre un ejemplo de como listar las ventas:

el ejemplo ocupa un Listview, un PictureBox, un ImgeList y un commadButton.


en un módulo pones:
Código:
 Option Explicit

'Udt
'##############
 Type ProcData
    HwndWin As Long
    captionWin As String
    Estado As String
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type


Type POINTAPI
    x As Long
    y As Long
End Type

Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Type WINDOWPLACEMENT
    length As Long
    flags As Long
    showCmd As Long
    ptMinPosition As POINTAPI
    ptMaxPosition As POINTAPI
    rcNormalPosition As RECT
End Type
 
'Declaraciones Api
'#################
 
 Declare Function DrawCaption Lib "user32" (ByVal hwnd As Long, ByVal hDC As Long, _
                                        pcRect As RECT, ByVal un As Long) As Long
 Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 _
                                As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
 Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
 
 Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Any, ByVal _
                                                        lParam As Long) As Long
 Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As _
                                                            WINDOWPLACEMENT) As Long
 Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
                                    (ByVal hwnd As Long, ByVal lpString As String, _
                                                            ByVal cch As Long) As Long

'Variables
'##########

Public Valores() As ProcData
Public nProcesos As Integer



'Función que enumera las ventanas de windows

Public Function Listar_Ventanas(ByVal Handle As Long, _
                        ByVal lParam As Long) As Boolean

Dim infoWin As WINDOWPLACEMENT

Dim buffer As String * 256
Dim l As Long

    nProcesos = nProcesos + 1
    'redimensiona el vector
    ReDim Preserve Valores(1 To nProcesos)
   
    With Valores(nProcesos)
        .HwndWin = Handle

        ' Recupera el título de la ventana
        l = GetWindowText(Handle, buffer, Len(buffer))
        'Remplaza los Nulos
        .captionWin = Replace(buffer, Chr(0), vbNullString)
       
        infoWin.length = Len(infoWin)
       
        Call GetWindowPlacement(Handle, infoWin)
       
        'Guarda el estado de la ventana
        Select Case infoWin.showCmd
            Case 1
                .Estado = "Normal"
            Case 2
                .Estado = "Minimizado"
            Case 3
                .Estado = "Maximizado"
        End Select
       
       
                 'Guarda la posición de la ventana
                .Left = infoWin.rcNormalPosition.Left
                .Top = infoWin.rcNormalPosition.Top
                .Right = infoWin.rcNormalPosition.Right
                .Bottom = infoWin.rcNormalPosition.Bottom
    End With
   
    ' Continúa buscando las demás ventanas
    Listar_Ventanas = 1
End Function

y en un form:
Código:
Option Explicit

Const SWP_HIDEWINDOW = &H80
Const SWP_SHOWWINDOW = &H40
 
Private Sub Command1_Click()
   
    Erase Valores
    nProcesos = 0
    'Llama a Enumwindows para listar las ventanas y obtener la información
    EnumWindows AddressOf Listar_Ventanas, 0
   
    cargar
End Sub


Sub cargar()

Dim i As Integer
Dim LItem As ListItem 'variable para los subitems del listview


    ListView1.ListItems.Clear
   
    For i = 1 To nProcesos
        With Valores(i)
             
             If .captionWin <> "Program Manager" And .captionWin <> vbNullString _
                                        And .captionWin <> "Project1" Then
             ' Si la ventana es visible
             If IsWindowVisible(.HwndWin) Then
                'Obtiene el ícono de la ventana
                Call Obtener_Icono(.HwndWin)
               
                'Agrega el Item y subitems al ListView
                Set LItem = ListView1.ListItems.Add(, , .captionWin, , _
                                        ImageList1.ListImages.Count)
                   
                    LItem.SubItems(1) = .HwndWin
                    LItem.SubItems(2) = .Estado
                    LItem.SubItems(3) = .Left
                    LItem.SubItems(4) = .Right
                    LItem.SubItems(5) = .Top
                    LItem.SubItems(6) = .Bottom
             End If
             End If
           
        End With
    Next



End Sub

'Sub que obtiene el ícono de la ventana y luego lo coloca en el Listview
Private Sub Obtener_Icono(h As Long)
'Variable Rect para usar con el API setRect y Drawcaption
Dim rec As RECT

    With Picture1
        'Limpia el Picturebox
        .Cls
        .Picture = Nothing
       
        Call SetRect(rec, 5, 7, 10, 10)
       
        'Dibuja el icono en el picture pasandole al api el _
        hwnd de la ventana
        Call DrawCaption(h, .hDC, rec, 4)
       
        .Refresh
       
        Set .Picture = Picture1.Image

    End With
    ' Almacena la imagen en el ImageList
    ImageList1.ListImages.Add , , Picture:=Picture1
   
    ' Si el ImageList no está inicializado  se enlaza al ListView
    If ListView1.SmallIcons Is Nothing Then
        Set ListView1.SmallIcons = ImageList1
    End If
End Sub


Private Sub Form_Load()
With ListView1
     
     'vista de reporte
     .View = lvwReport
     'Columnas
     .ColumnHeaders.Add , , " Título de la ventana "
     .ColumnHeaders.Add , , " HWND "
     .ColumnHeaders.Add , , " Estado "
     .ColumnHeaders.Add , , " Left "
     .ColumnHeaders.Add , , " Right "
     .ColumnHeaders.Add , , " Top "
     .ColumnHeaders.Add , , " Bottom "
     .ColumnHeaders(1).Width = 4000
     .ColumnHeaders(2).Width = 1000
     .ColumnHeaders(3).Width = 1200
     .ColumnHeaders(4).Width = 700
     .ColumnHeaders(5).Width = 800
     .ColumnHeaders(6).Width = 800
     .ColumnHeaders(7).Width = 800
     
End With

'Propiedades para el Picture invisible en el cual se dibuja _
 el icono de la ventana mediante el Api DrawCaption
With Picture1
    .ScaleMode = vbPixels
    .Width = 260
    .Height = 260
    .AutoRedraw = True
    .BorderStyle = 0
    .BackColor = ListView1.BackColor
    .Visible = False
   
End With

Me.Caption = " Información de ventanas de windows "
Command1.Caption = " Listar ventanas "

End Sub

con esto vas a lograr hacer una lista de las ventanas que tienes abiertas, y puedes usar la API ShowWindow para traer alguna al frente:

ejemplo:
Código:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const SW_SHOWNORMAL = 1
Const WM_CLOSE = &H10
Const gcClassnameMSWord = "OpusApp"
Const gcClassnameMSExcel = "XLMAIN"
Const gcClassnameMSIExplorer = "IEFrame"
Const gcClassnameMSVBasic = "wndclass_desked_gsk"
Const gcClassnameNotePad = "Notepad"
Const gcClassnameMyVBApp = "ThunderForm"
Private Sub Form_Load()
    Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
    Ret = InputBox("Nombre de la ventana:" + vbcrlf + "Nota: el nombre debe ser exacto")
    'Búsca la ventana
    WinWnd = FindWindow(vbNullString, Ret)
    If WinWnd = 0 Then MsgBox "No sé pudo encontrar la ventana": Exit Sub
    'Muestra la ventana
    ShowWindow WinWnd, SW_SHOWNORMAL
End Sub
[code]

espero y te sirva de algo
[/code]


En línea

"La soledad es el elemento de los grandes talentos".
Cristina de Suecia (1626-1689) Reina de Suecia.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines