Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Handling multiple mainWindowHandles of one Process

Handling multiple mainWindowHandles of one Process

Scheduled Pinned Locked Moved Visual Basic
question
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wieczo yo
    wrote on last edited by
    #1

    Hello! I am developing an application to display different documents(txt, doc, xls, ppt, pdf files), arrange them on the desktop and scroll through the pages. I use System.Diagnostics.Process.Start to open the relevant file with the right application. I use then Process.mainWindowHandle to resize, to move and scroll those apps with WinAPI methods. It works good for documents for which every Process.Start call results in an independent process, e.g. I can open two txt-files in Windows' Notepad and I get two processes displayed in the task manager. I can get the mainWindowHandle of both easily and rearrange them. But it crashes on mutex apps(right word?). The Microsoft Word Viewer is such a candidate. I open one document foo.doc, the Word Viewer starts a process. Then I start another "instance" of it with a different file bar.doc and it opens the file, but I don't get the right Process object returned, because the first instance(with foo.doc) adds bar.doc to its managed windows. My code:

    Public Overridable Function Start(ByVal x As Double, ByVal y As Double, _
    ByVal width As Double, ByVal height As Double) As Boolean

    Dim retValue As Boolean = False
    Dim fred As ProcessThread
    Dim waited As Boolean
    
    \_x = x
    \_y = y
    \_width = width
    \_height = height
    
    'Starts the application with the file, ...
    \_process = Process.Start(\_app\_path, """" & \_file.Path & """")
    If Not IsNothing(\_process) Then
        '...but it crashes as soon as I try to access a member of \_process
        waited = \_process.WaitForInputIdle()
    
        If Not IsNothing(\_process.Threads) Then
            fred = \_process.Threads.Item(0)
            retValue = EnumThreadWindows(New IntPtr(fred.Id), \_
                AddressOf MoveCallback, IntPtr.Zero)
        End If
    End If
    
    Return retValue
    

    End Function

    EnumThreadWindows is a WinAPI call and MoveCallback is a callback for it:

    Private Function MoveWindow(ByVal hWnd As IntPtr, ByVal x As Integer, _
    ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, _
    ByVal bRepaint As Boolean) As Boolean
    End Function
    _
    Private Function EnumThreadWindows(ByVal dwThreadId As IntPtr, _
    ByVal lpfn As EnumThreadDelegate, ByVal lParam As IntPtr) As Boolean
    End Function

    Private Function MoveCallback(ByVal hWnd As IntPtr, _
    ByVal lParam As IntPtr) As Boolean
    Dim sc

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups