Función MoveWindow al abrir aplicación "firefox"

Iniciado por daniel.r.23, 26 Octubre 2014, 08:53 AM

0 Miembros y 1 Visitante están viendo este tema.

daniel.r.23

Buenas, en un tema anterior pedí ayuda a como ocultar una ventana de firefox a ese tema se le encontró solución pero no me sirvió para lo que yo necesitaba ya que cada ves que una aplicación externa utilizaba el navegador este se activaba y se mostraba de todas formas, por lo que el ShowWindow no me sirvió!.
Como solución utilicé el MoveWindow para mover el navegador a un puto el cual el usuario no pudiera hacer uso del mismo pero me encontré con un nuevo problema, cuando la aplicación que hace uso del navegador hace click en algún link, se abre una nueva ventana  en un punto que es visible para el usuario.
Hay alguna forma, algún método para que este si se abre, que aparezca en la posición de la primera pantalla del navegador???

Pensé en los procesos sincrónicos y siempre estar preguntando por los procesos de "firefox" para estar moviendo sus respectivas pantallas, pero no lo veo algo muy practico.  

daniel.r.23

les quería comentar que al final lo termine solucionando con un proceso asincrónico.
les dejo parte del código:


Private Sub HideToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles HideToolStripMenuItem.Click
        Dim Width As Integer = My.Computer.Screen.Bounds.Width
        Dim Height As Integer = My.Computer.Screen.Bounds.Height
        Dim hWnd As IntPtr = FindWindowExW(IntPtr.Zero, IntPtr.Zero, "MozillaWindowClass", Nothing)
        While Not hWnd.Equals(IntPtr.Zero)
            Dim title As New System.Text.StringBuilder(256)
            GetWindowTextW(hWnd, title, 256)
            'ListBox1.Items.Add(title.ToString)
            If title.ToString.Contains("NeoBux") Then
                MoveWindow(hWnd, Width, Height, Width, Height, True)
            End If
            hWnd = FindWindowExW(IntPtr.Zero, hWnd, "MozillaWindowClass", Nothing)
        End While
        Try
            BackgroundWorker1.RunWorkerAsync()
        Catch ex As Exception
            If BackgroundWorker1.WorkerSupportsCancellation Then
                BackgroundWorker1.CancelAsync()
            End If
        End Try
        For Each item As ToolStripItem In Me.ContextMenuStrip1.Items
            If item.Text = "Hide" Then
                item.Visible = False
                ctrh = item
            End If
            If item.Text = "Show" Then
                item.Visible = True
            End If
        Next
    End Sub
   Private Sub ShowToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ShowToolStripMenuItem.Click
       Dim hWnd As IntPtr = FindWindowExW(IntPtr.Zero, IntPtr.Zero, "MozillaWindowClass", Nothing)
       For Each item As ToolStripItem In Me.ContextMenuStrip1.Items
           If item.Text = "Show" Then
               item.Visible = False
               ctrh.Visible = True
               visible_ = True
               lx = 0
               ly = 0
           End If
       Next
       While Not hWnd.Equals(IntPtr.Zero)
           Dim title As New System.Text.StringBuilder(256)
           GetWindowTextW(hWnd, title, 256)
           If title.ToString.Contains("NeoBux") Then
               MoveWindow(hWnd, lx, ly, 512, 380, True)
               If lx = 0 Then
                   lx = 512
               ElseIf lx = 512 Then
                   lx = 0
                   ly += 380
               End If
           End If
           hWnd = FindWindowExW(IntPtr.Zero, hWnd, "MozillaWindowClass", Nothing)
       End While
       If BackgroundWorker1.IsBusy Then
           If BackgroundWorker1.WorkerSupportsCancellation Then
               BackgroundWorker1.CancelAsync()
           End If
       End If

   End Sub

   Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
       Dim Width As Integer = My.Computer.Screen.Bounds.Width
       Dim Height As Integer = My.Computer.Screen.Bounds.Height
       While Not visible_
           Dim hWnd As IntPtr = FindWindowExW(IntPtr.Zero, IntPtr.Zero, "MozillaWindowClass", Nothing)
           While Not hWnd.Equals(IntPtr.Zero)
               Dim title As New System.Text.StringBuilder(256)
               GetWindowTextW(hWnd, title, 256)
               'ListBox1.Items.Add(title.ToString)
               If title.ToString.Contains("NeoBux") Then
                   MoveWindow(hWnd, Width, Height, Width, Height, True)
               End If
               hWnd = FindWindowExW(IntPtr.Zero, hWnd, "MozillaWindowClass", Nothing)
           End While
       End While
       visible_ = False
   End Sub
End Class