Re: Resize application window - more information



Ltexeira wrote:
Your link takes me to download Shell32.zip, which contains the following code
in the hWndShell function. ( Taken directly from the downloaded file )

I am so sorry about that! That truly is ancient. I thought I'd updated that eons
ago.

Perhaps you are referring to a newer version of yours that is not posted for
download.
<snip>
If you have a newer version that enumerates, please direct me to it.

Here ya go!

Private Type EnumWindowsData
ProcessID As Long
hWnd As Long
End Type

Public Function hWndShell(ByVal Job As String, Optional WindowStyle As
VbAppWinStyle = vbMinimizedNoFocus) As Long
Dim ProcessID As Long
' *************************************************************************
' Shells a new process and returns the hWnd of its main window.
' *************************************************************************

' Test WindowStyle for reasonableness
If (WindowStyle < vbHide) Or (WindowStyle > vbMinimizedNoFocus) Then
WindowStyle = vbMinimizedNoFocus
End If

' Launch process in requested mode.
On Error Resume Next
ProcessID = Shell(Job, WindowStyle)
On Error GoTo 0

' Determine main window handle for new process.
If ProcessID Then
hWndShell = hWndProcess(ProcessID)
End If
End Function

Public Function hWndProcess(ByVal ProcessID As Long) As Long
Dim ewd As EnumWindowsData
' *************************************************************************
' Fires off enumeration of all windows in system, seeking to return
' toplevel hWnd from requested process.
' *************************************************************************
ewd.ProcessID = ProcessID
Call EnumWindows(AddressOf EnumWindowsProc, VarPtr(ewd))
hWndProcess = ewd.hWnd
End Function

' ***********************************
' Private Methods
' ***********************************
Private Function EnumWindowsProc(ByVal hWnd As Long, lParam As EnumWindowsData)
As Long
Dim PID As Long

' Make sure this is a top-level window.
If GetParent(hWnd) = 0 Then
' Check what process it belongs to
Call GetWindowThreadProcessId(hWnd, PID)
If PID = lParam.ProcessID Then
lParam.hWnd = hWnd
End If
End If

' Return True to continue enumeration if we haven't
' found what we're looking for.
EnumWindowsProc = (lParam.hWnd = 0)
End Function

I'll try to get the update code out there shortly.

Thanks... Karl
--
..NET: It's About Trust!
http://vfred.mvps.org


.



Relevant Pages

  • Re: Restoring the Window of an App Launched from VB
    ... Dim res As Long ... > Here's the LaunchApp Function: ... > Dim processID As Long, ... > 'Test the value of windowStyle. ...
    (microsoft.public.vb.controls)
  • Re: Get hwnd from process returns 0
    ... I would like to start write.exe and get its hwnd. ... I don't know what I do wrong, but my var lProcHwnd always returns 0, ... Public Function hWndShell(ByVal Job As String, Optional WindowStyle As ... Dim ProcessID As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: GetWindowThreadProcessId
    ... > private static extern int GetWindowThreadProcessId(IntPtr hwnd, ... > Private Shared Function GetWindowThreadProcessId(ByVal hwnd As IntPtr, ... > processId As Integer) As Integer ...
    (microsoft.public.pocketpc.developer)
  • Re: GetWindowThreadProcessId
    ... private static extern int GetWindowThreadProcessId(IntPtr hwnd, ... Private Shared Function GetWindowThreadProcessId(ByVal hwnd As IntPtr, ... processId As Integer) As Integer ...
    (microsoft.public.pocketpc.developer)
  • Re: CreateProcess
    ... Is there another way to get from the processID to the hwnd of the apps ... main window without using EnumWindows? ... >> structure returned by CreateProcess. ...
    (microsoft.public.vc.language)