| |
|
9481
|
Programación / .NET (C#, VB.NET, ASP) / Sobre los child handles
|
en: 9 Abril 2013, 19:54 pm
|
Necesito listar todos los handles hijos de un proceso, para eso utilizo esta Class: http://kellyschronicles.wordpress.com/2008/06/23/get-window-handles-associated-with-process-in-vb-net/Imports System.Collections.Generic Imports System.Runtime.InteropServices Imports System.Text Public Class ApiWindow Public MainWindowTitle As String = "" Public ClassName As String = "" Public hWnd As Int32 End Class ''' <summary> ''' Enumerate top-level and child windows ''' </summary> ''' <example> ''' Dim enumerator As New WindowsEnumerator() ''' For Each top As ApiWindow in enumerator.GetTopLevelWindows() ''' Console.WriteLine(top.MainWindowTitle) ''' For Each child As ApiWindow child in enumerator.GetChildWindows(top.hWnd) ''' Console.WriteLine(" " + child.MainWindowTitle) ''' Next child ''' Next top ''' </example> Public Class WindowsEnumerator Private Delegate Function EnumCallBackDelegate(ByVal hwnd As Integer, ByVal lParam As Integer) As Integer ' Top-level windows. Private Declare Function EnumWindows Lib "user32" _ (ByVal lpEnumFunc As EnumCallBackDelegate, ByVal lParam As Integer) As Integer ' Child windows. Private Declare Function EnumChildWindows Lib "user32" _ (ByVal hWndParent As Integer, ByVal lpEnumFunc As EnumCallBackDelegate, ByVal lParam As Integer) As Integer ' Get the window class. Private Declare Function GetClassName _ Lib "user32" Alias "GetClassNameA" _ (ByVal hwnd As Integer, ByVal lpClassName As StringBuilder, ByVal nMaxCount As Integer) As Integer ' Test if the window is visible--only get visible ones. Private Declare Function IsWindowVisible Lib "user32" _ (ByVal hwnd As Integer) As Integer ' Test if the window's parent--only get the one's without parents. Private Declare Function GetParent Lib "user32" _ (ByVal hwnd As Integer) As Integer ' Get window text length signature. Private Declare Function SendMessage _ Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32 ' Get window text signature. Private Declare Function SendMessage _ Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As StringBuilder) As Int32 Private _listChildren As New List(Of ApiWindow) Private _listTopLevel As New List(Of ApiWindow) Private _topLevelClass As String = "" Private _childClass As String = "" ''' <summary> ''' Get all top-level window information ''' </summary> ''' <returns>List of window information objects</returns> Public Overloads Function GetTopLevelWindows() As List(Of ApiWindow) EnumWindows(AddressOf EnumWindowProc, &H0) Return _listTopLevel End Function Public Overloads Function GetTopLevelWindows(ByVal className As String) As List(Of ApiWindow) _topLevelClass = className Return Me.GetTopLevelWindows() End Function ''' <summary> ''' Get all child windows for the specific windows handle (hwnd). ''' </summary> ''' <returns>List of child windows for parent window</returns> Public Overloads Function GetChildWindows(ByVal hwnd As Int32) As List(Of ApiWindow) ' Clear the window list. _listChildren = New List(Of ApiWindow) ' Start the enumeration process. EnumChildWindows(hwnd, AddressOf EnumChildWindowProc, &H0) ' Return the children list when the process is completed. Return _listChildren End Function Public Overloads Function GetChildWindows(ByVal hwnd As Int32, ByVal childClass As String) As List(Of ApiWindow) ' Set the search _childClass = childClass Return Me.GetChildWindows(hwnd) End Function ''' <summary> ''' Callback function that does the work of enumerating top-level windows. ''' </summary> ''' <param name="hwnd">Discovered Window handle</param> ''' <returns>1=keep going, 0=stop</returns> Private Function EnumWindowProc(ByVal hwnd As Int32, ByVal lParam As Int32) As Int32 ' Eliminate windows that are not top-level. If GetParent(hwnd) = 0 AndAlso CBool(IsWindowVisible(hwnd)) Then ' Get the window title / class name. Dim window As ApiWindow = GetWindowIdentification(hwnd) ' Match the class name if searching for a specific window class. If _topLevelClass.Length = 0 OrElse window.ClassName.ToLower() = _topLevelClass.ToLower() Then _listTopLevel.Add(window) End If End If ' To continue enumeration, return True (1), and to stop enumeration ' return False (0). ' When 1 is returned, enumeration continues until there are no ' more windows left. Return 1 End Function ''' <summary> ''' Callback function that does the work of enumerating child windows. ''' </summary> ''' <param name="hwnd">Discovered Window handle</param> ''' <returns>1=keep going, 0=stop</returns> Private Function EnumChildWindowProc(ByVal hwnd As Int32, ByVal lParam As Int32) As Int32 Dim window As ApiWindow = GetWindowIdentification(hwnd) ' Attempt to match the child class, if one was specified, otherwise ' enumerate all the child windows. If _childClass.Length = 0 OrElse window.ClassName.ToLower() = _childClass.ToLower() Then _listChildren.Add(window) End If Return 1 End Function ''' <summary> ''' Build the ApiWindow object to hold information about the Window object. ''' </summary> Private Function GetWindowIdentification(ByVal hwnd As Integer) As ApiWindow Const WM_GETTEXT As Int32 = &HD Const WM_GETTEXTLENGTH As Int32 = &HE Dim window As New ApiWindow() Dim title As New StringBuilder() ' Get the size of the string required to hold the window title. Dim size As Int32 = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0) ' If the return is 0, there is no title. If size > 0 Then title = New StringBuilder(size + 1) SendMessage(hwnd, WM_GETTEXT, title.Capacity, title) End If ' Get the class name for the window. Dim classBuilder As New StringBuilder(64) GetClassName(hwnd, classBuilder, 64) ' Set the properties for the ApiWindow object. window.ClassName = classBuilder.ToString() window.MainWindowTitle = title.ToString() window.hWnd = hwnd Return window End Function End Class
Y la uso de esta manera, pero solo obtengo el "main" handle: Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim enumerator As New WindowsEnumerator() For Each top As ApiWindow In enumerator.GetTopLevelWindows() If top.MainWindowTitle.ToLower.Contains("firefox") Then RichTextBox1.Text += vbNewLine & ("main handle: " & top.MainWindowTitle) For Each child As ApiWindow In enumerator.GetChildWindows(top.hWnd) RichTextBox1.Text += vbNewLine & ("child handle: " & " " + child.MainWindowTitle) Next End If Next top End Sub
Así que algo está mal. Lo que quiero es obtener todos los handles de un proceso, como por ejemplo el output que nos da la utilidad CommandLine "CMDOW" con este comando: C:\>cmdow | find /i "firefox" 0x2C0242 1 912 Res Ina Ena Hid firefox Code Sample <pre><code> Ctrl+K 0x1F0C10 1 912 Res Ina Ena Hid firefox pinvoke.net: EnumWindowsProc (Delegate 0x6E06A8 1 912 Res Ina Ena Hid firefox MozillaDropShadowWindowClass 0x310ADA 1 912 Res Ina Ena Hid firefox MozillaDropShadowWindowClass 0x610D3A 1 912 Res Ina Ena Hid firefox MozillaWindowClass 0x840A54 1 912 Res Ina Ena Hid firefox MozillaDropShadowWindowClass 0x9A08D6 1 912 Res Ina Ena Hid firefox Search using Google (English) 0x17E057C 1 912 Res Ina Ena Hid firefox MozillaDropShadowWindowClass 0x2E0A5A 1 912 Res Ina Ena Hid firefox MozillaWindowClass 0x4A04DC 1 912 Min Ina Ena Vis firefox Get all child handles of process - Sta 0xA40994 1 912 Min Ina Ena Hid firefox pinvoke.net: EnumWindowsProc (Delegate 0x110CF4 1 912 Min Ina Ena Hid firefox pinvoke.net: EnumChildWindows (user32) 0x560270 1 912 Min Ina Ena Hid firefox Get handles of process forms c# - Stac 0x7B0CCC 1 912 Min Ina Ena Hid firefox Get child window handles in C# - Stack 0x74040A 1 912 Min Ina Ena Hid firefox Get all child handles of process - Sta 0xC0028A 1 912 Min Ina Ena Hid firefox Get Window Handles Associated With Pro 0xAC067C 1 912 Min Ina Ena Hid firefox vbnet get child handles of process - B 0x6308B0 1 912 Min Ina Ena Hid firefox Process Class (System.Diagnostics) - M 0xB20B2E 1 912 Min Ina Ena Hid firefox How to wait the process until the proc 0xA7021C 1 912 Min Ina Ena Hid firefox vb.net - Waiting For Process To Comple 0xD30356 1 912 Min Ina Ena Hid firefox FreeVBCode code snippet: Execute a Pro 0x583207D0 1 912 Res Ina Ena Hid firefox nsAppShell:EventWindow 0x3C0550 1 912 Res Ina Ena Hid firefox DDEMLEvent 0x3E065C 1 912 Res Ina Ena Hid firefox DDEMLMom 0x590288 1 912 Res Ina Ena Hid firefox FirefoxMessageWindow 0x2D085A 1 912 Min Ina Ena Hid firefox vbnet wait for process end - Buscar co 0x5F0584 1 912 Res Ina Ena Hid firefox MCI command handling window 0x2307D2 1 912 Res Ina Ena Hid firefox MozillaHiddenWindowClass 0x1760466 1 912 Res Ina Dis Hid firefox MSCTFIME UI 0x200CB4 1 912 Res Ina Dis Hid firefox Default IME 0x510320 1 912 Res Ina Dis Hid firefox Default IME
|
|
|
|
|
9482
|
Programación / .NET (C#, VB.NET, ASP) / Sobre los Handles del SystemTray...
|
en: 9 Abril 2013, 19:48 pm
|
Este tema me lleva días matándome, he creado 5 posts sobre temas relacionados con los handles en StackOverFlow, porque no me aclaro nada con las funciones de la API (FindWindow, FindWindowEx, etc...). A ver, lo que necesito es, saber si una aplicación de terceros ha mostrado su icono en el systemtray, es decir, saber si "X" icono existe en el SysTray, ya séa buscando el icono por el handle del proceso, o por el nombre de la ventana, o como séa. Para esto, primero intento obtener el handle de la aplicación, y luego el handle de mi systray, pero hasta aquí, ya no sé como seguir ni que debo hacer. Imports System.Runtime.InteropServices Public Class Form1 Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public 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 Public Shared Function WindowHandle(sTitle As String) As Long Return FindWindow(vbNullString, sTitle) End Function Private Shared Function GetSystemTrayHandle() As IntPtr Dim hWndTray As IntPtr = FindWindow("Shell_TrayWnd", Nothing) If hWndTray <> IntPtr.Zero Then hWndTray = FindWindowEx(hWndTray, IntPtr.Zero, "TrayNotifyWnd", Nothing) If hWndTray <> IntPtr.Zero Then hWndTray = FindWindowEx(hWndTray, IntPtr.Zero, "SysPager", Nothing) If hWndTray <> IntPtr.Zero Then hWndTray = FindWindowEx(hWndTray, IntPtr.Zero, "ToolbarWindow32", Nothing) Return hWndTray End If End If End If Return IntPtr.Zero End Function Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click MsgBox(WindowHandle("Steam")) ' 6687230 MsgBox(GetSystemTrayHandle()) ' 65728 End Sub End Class
|
|
|
|
|
9483
|
Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets)
|
en: 9 Abril 2013, 16:50 pm
|
· Mostrar un MessageBox centrado al form #Region " Centered Messagebox " ' [ Centered Messagebox Function ] ' ' Instructions : ' 1. Add the Class ' 2. Use it ' ' Examples : ' Using New Centered_MessageBox(Me) ' MessageBox.Show("Test Text", "Test Title", MessageBoxButtons.OK) ' End Using ' Centered_MessageBox.vb #Region " Centered MessageBox Class" Imports System.Text Imports System.Drawing Imports System.Windows.Forms Imports System.Runtime.InteropServices Class Centered_MessageBox Implements IDisposable Private mTries As Integer = 0 Private mOwner As Form Public Sub New(owner As Form) mOwner = owner owner.BeginInvoke(New MethodInvoker(AddressOf findDialog)) End Sub Private Sub findDialog() ' Enumerate windows to find the message box If mTries < 0 Then Return End If Dim callback As New EnumThreadWndProc(AddressOf checkWindow) If EnumThreadWindows(GetCurrentThreadId(), callback, IntPtr.Zero) Then If System.Threading.Interlocked.Increment(mTries) < 10 Then mOwner.BeginInvoke(New MethodInvoker(AddressOf findDialog)) End If End If End Sub Private Function checkWindow(hWnd As IntPtr, lp As IntPtr) As Boolean ' Checks if <hWnd> is a dialog Dim sb As New StringBuilder(260) GetClassName(hWnd, sb, sb.Capacity) If sb.ToString() <> "#32770" Then Return True End If ' Got it Dim frmRect As New Rectangle(mOwner.Location, mOwner.Size) Dim dlgRect As RECT GetWindowRect(hWnd, dlgRect) MoveWindow(hWnd, frmRect.Left + (frmRect.Width - dlgRect.Right + dlgRect.Left) \ 2, frmRect.Top + (frmRect.Height - dlgRect.Bottom + dlgRect.Top) \ 2, dlgRect.Right - dlgRect.Left, dlgRect.Bottom - dlgRect.Top, True) Return False End Function Public Sub Dispose() Implements IDisposable.Dispose mTries = -1 End Sub ' P/Invoke declarations Private Delegate Function EnumThreadWndProc(hWnd As IntPtr, lp As IntPtr) As Boolean <DllImport("user32.dll")> _ Private Shared Function EnumThreadWindows(tid As Integer, callback As EnumThreadWndProc, lp As IntPtr) As Boolean End Function <DllImport("kernel32.dll")> _ Private Shared Function GetCurrentThreadId() As Integer End Function <DllImport("user32.dll")> _ Private Shared Function GetClassName(hWnd As IntPtr, buffer As StringBuilder, buflen As Integer) As Integer End Function <DllImport("user32.dll")> _ Private Shared Function GetWindowRect(hWnd As IntPtr, ByRef rc As RECT) As Boolean End Function <DllImport("user32.dll")> _ Private Shared Function MoveWindow(hWnd As IntPtr, x As Integer, y As Integer, w As Integer, h As Integer, repaint As Boolean) As Boolean End Function Private Structure RECT Public Left As Integer Public Top As Integer Public Right As Integer Public Bottom As Integer End Structure End Class #End Region #End Region
|
|
|
|
|
9484
|
Sistemas Operativos / Windows / Re: ¿Por que tanto odio hacia Windows 8?
|
en: 9 Abril 2013, 15:19 pm
|
Osea que te basas en los numeros y la probabilidad para decidir si va ser bueno o no? Lo siento, pienso que deberias ser tu mismo el que juzgue y decida eso y no basarte en nada ni en lo que diga nadie más. Puede ser custión de gustos. No, sería cuestión de números y probabilidad si el producto no se hubiese lanzado al mercado y no pudieramos testearlo. La imagen representa mi opinión y decepción personal (como la de muchos otros), pues una imagen vale más que mil palabras. No intentes sacar de contexto las frases que te está diciendo todo el mundo, respétalas y acepta las críticas, porque si bien habrás leido como sigue mi comentario: Nada más lejos que la pura realidad, yo he pasado por la época del Win95 hasta el Win8. Así que no se donde ves una simple cuestión de números y probabilidades, cuando te estoy diciendo que he tenido en mis manos todos a lo largo d elos años, he experimentado, sufrido, y obtenido mis própias conclusiones. Lo dicho, no saques las cosas fuera de contexto porfavor, porque esto más que un debate creo que se está convirtiendo en una ocasión personal tuya para negar todo lo que te digan o intentar darle la vuelta y llamarlos "listillos" (en fín lo que siempre suele pasar con estos posts). PD: No sigo el tema. Por cierto, como te gusta tanto Windows 8, quizás te interese mi post: Recopilación Windows 8 (Programas, tips y guías) (Actualizado el 05/11/2012)Un saludo!
|
|
|
|
|
9486
|
Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets)
|
en: 9 Abril 2013, 10:59 am
|
· Hexadecimal a Decimal: #Region " Hex To Dec Function " ' [ Hex To Dec Function ] ' ' // By Elektro H@cker ' ' Examples : ' MsgBox(Hex_To_Dec("0x020032")) ' Result: 131122 Private Function Hex_To_Dec(ByVal str As String) As Int32 Return Convert.ToInt32(str, 16) End Function #End Region
· Decimal a Hexadecimal: #Region " Dec To Hex Function " ' [ Dec To Hex Function ] ' ' // By Elektro H@cker ' ' Examples : ' MsgBox(Dec_To_Hex(131122)) ' Result: 0x020032 Private Function Dec_To_Hex(ByVal int As Int32) As String Return Convert.ToString(int, 16) End Function #End Region
· Comprueba si una fuente está instalada: EDITO: MEJORADO Y SIMPLIFICADO
#Region " Font Is Installed? Function "
' [ Font Is Installed? Function ] ' ' // By Elektro H@cker ' ' Examples : ' MsgBox(Font_Is_Installed("Lucida Console"))
Private Function Font_Is_Installed(ByVal FontName As String) As Boolean Dim AllFonts As New Drawing.Text.InstalledFontCollection If AllFonts.Families.ToList().Contains(New FontFamily(FontName)) Then Return True Else Return False End Function
#End RegionOtra versión que me han proporcionado, mucho más simplificada: #Region " Font Is Installed? Function " ' [ Font Is Installed? Function ] ' ' Examples : ' MsgBox(Font_Is_Installed("Lucida Console")) Public Shared Function Font_Is_Installed(ByVal FontName As String) As Boolean Using TestFont As Font = New Font(FontName, 8) Return CBool(String.Compare(FontName, TestFont.Name, StringComparison.InvariantCultureIgnoreCase) = 0) End Using End Function #End Region
|
|
|
|
|
9488
|
Sistemas Operativos / Windows / Re: ¿Por que tanto odio hacia Windows 8?
|
en: 9 Abril 2013, 09:26 am
|
¿Por que tanto odio hacia Windows 8? Porque sabemos lo que nos están vendiendo:  Nada más lejos que la pura realidad, yo he pasado por la época del Win95 hasta el Win8. Windows 8 es un buen sistema operativo, pero no es un buen Windows.Lo siento pero no me andaré con explicaciones, detalles, ni tecnicismos, me parece una pérdida de tiempo intentar convencer a la gente que tenga una opinión tán positiva, habrá a quien le guste y habrá a quien no, esto se ha debatido 1.000 veces. Un saludo!
|
|
|
|
|
|
| |
|