Reply to J French (other returned)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dw85745

    Reply to J French (other returned)

    Thanks for responding J French

    ---------
    I assume you are finding the hWnd and using SetParent
    --------------

    Yes. Using Shell instead of ShellExecute. Saw another Shell implementation
    (as I recall using CreateProcess) so will try and fine and give it a go.

    However, I tried with another VB created exe (just a form compiled to exe)
    and ran into same issue.
    My guess is that VB runtime files are issue.

    If not above, what other info you need?

    Thanks
    David




  • J French

    #2
    Re: Reply to J French (other returned)

    On Wed, 31 Dec 2003 15:12:10 -0700, "dw85745" <dw85745@gbronl ine.com>
    wrote:
    [color=blue]
    >Thanks for responding J French
    >
    >---------
    >I assume you are finding the hWnd and using SetParent
    >--------------
    >
    >Yes. Using Shell instead of ShellExecute. Saw another Shell implementation
    >(as I recall using CreateProcess) so will try and fine and give it a go.
    >
    >However, I tried with another VB created exe (just a form compiled to exe)
    >and ran into same issue.
    >My guess is that VB runtime files are issue.
    >
    >If not above, what other info you need?[/color]

    My hunch (and right now it is just a hunch) is that you have not got
    hold of the right handle

    Run up a simple App and display the handle of the Form you want to
    re-parent - then manually re-parent it

    Right now I am sufferring from last night .. or I would delve in now
    - post again tomorrow

    Comment

    • dw85745

      #3
      Re: Reply to J French (other returned)

      Hi JFrench:

      I used Microsoft's Q242308 for my base example.

      Not sure what you mean by manually reparent????
      -- or would gladly try it

      Glad to hear you had a GOOD New Year!!!!!!!

      David

      "J French" <erewhon@nowher e.com> wrote in message
      news:3ff421f3.8 497432@news.btc lick.com...[color=blue]
      > On Wed, 31 Dec 2003 15:12:10 -0700, "dw85745" <dw85745@gbronl ine.com>
      > wrote:
      >[color=green]
      > >Thanks for responding J French
      > >
      > >---------
      > >I assume you are finding the hWnd and using SetParent
      > >--------------
      > >
      > >Yes. Using Shell instead of ShellExecute. Saw another Shell[/color][/color]
      implementation[color=blue][color=green]
      > >(as I recall using CreateProcess) so will try and fine and give it a go.
      > >
      > >However, I tried with another VB created exe (just a form compiled to[/color][/color]
      exe)[color=blue][color=green]
      > >and ran into same issue.
      > >My guess is that VB runtime files are issue.
      > >
      > >If not above, what other info you need?[/color]
      >
      > My hunch (and right now it is just a hunch) is that you have not got
      > hold of the right handle
      >
      > Run up a simple App and display the handle of the Form you want to
      > re-parent - then manually re-parent it
      >
      > Right now I am sufferring from last night .. or I would delve in now
      > - post again tomorrow[/color]


      Comment

      • J French

        #4
        Re: Reply to J French (other returned)

        On Fri, 2 Jan 2004 04:42:23 -0700, "dw85745" <dw85745@gbronl ine.com>
        wrote:
        [color=blue]
        >Hi JFrench:
        >
        >I used Microsoft's Q242308 for my base example.
        >
        >Not sure what you mean by manually reparent????
        >-- or would gladly try it[/color]

        Snoop on the App, grab its main form handle and use SetParent
        [color=blue]
        >Glad to hear you had a GOOD New Year!!!!!!![/color]

        I suffered ...


        Comment

        • J French

          #5
          Re: Reply to J French (other returned)

          On Fri, 2 Jan 2004 12:23:47 +0000 (UTC), erewhon@nowhere .com (J
          French) wrote:
          [color=blue]
          >On Fri, 2 Jan 2004 04:42:23 -0700, "dw85745" <dw85745@gbronl ine.com>
          >wrote:
          >[color=green]
          >>Hi JFrench:
          >>
          >>I used Microsoft's Q242308 for my base example.
          >>
          >>Not sure what you mean by manually reparent????
          >>-- or would gladly try it[/color]
          >
          >Snoop on the App, grab its main form handle and use SetParent[/color]

          I forgot to mention, the Application also has a Handle
          - App.hInstance


          Comment

          • dw85745

            #6
            Re: Reply to J French (other returned)

            J French sorry it took so long:

            Tested the handle and your right. Handle is different.

            SO, if Q242308 won't give me the right handle, how do I get it!!!!!!!!

            Thanks
            David

            "J French" <erewhon@nowher e.com> wrote in message
            news:3ff565a1.9 1372680@news.bt click.com...[color=blue]
            > On Fri, 2 Jan 2004 12:23:47 +0000 (UTC), erewhon@nowhere .com (J
            > French) wrote:
            >[color=green]
            > >On Fri, 2 Jan 2004 04:42:23 -0700, "dw85745" <dw85745@gbronl ine.com>
            > >wrote:
            > >[color=darkred]
            > >>Hi JFrench:
            > >>
            > >>I used Microsoft's Q242308 for my base example.
            > >>
            > >>Not sure what you mean by manually reparent????
            > >>-- or would gladly try it[/color]
            > >
            > >Snoop on the App, grab its main form handle and use SetParent[/color]
            >
            > I forgot to mention, the Application also has a Handle
            > - App.hInstance
            >
            >[/color]


            Comment

            • dw85745

              #7
              Re: Reply to J French (other returned)

              J French sorry it took so long:

              Your right the handle is different.
              So if Q242308 isn't converting the hInstance from Shell to hWnd then:
              1) what is it giving me??
              2) how do I get the correct handle other than Enum and using Caption???

              FYI even trying to reparent it manually didn't seem to work for the VB form.

              1) I put menus on the MDI for creating, terminating, freeing from MDI, min,
              and MAX.
              2) I also used a child form with command buttons to do the same thing as
              the MDI menus,
              PLUS a textbox to enter the parent handle. Lost focus triggered the
              reparent.

              Thanks
              David


              "J French" <erewhon@nowher e.com> wrote in message
              news:3ff565a1.9 1372680@news.bt click.com...[color=blue]
              > On Fri, 2 Jan 2004 12:23:47 +0000 (UTC), erewhon@nowhere .com (J
              > French) wrote:
              >[color=green]
              > >On Fri, 2 Jan 2004 04:42:23 -0700, "dw85745" <dw85745@gbronl ine.com>
              > >wrote:
              > >[color=darkred]
              > >>Hi JFrench:
              > >>
              > >>I used Microsoft's Q242308 for my base example.
              > >>
              > >>Not sure what you mean by manually reparent????
              > >>-- or would gladly try it[/color]
              > >
              > >Snoop on the App, grab its main form handle and use SetParent[/color]
              >
              > I forgot to mention, the Application also has a Handle
              > - App.hInstance
              >
              >[/color]


              Comment

              • J French

                #8
                Re: Reply to J French (other returned)

                On Fri, 2 Jan 2004 17:21:10 -0700, "dw85745" <dw85745@gbronl ine.com>
                wrote:
                [color=blue]
                >J French sorry it took so long:
                >
                >Your right the handle is different.
                >So if Q242308 isn't converting the hInstance from Shell to hWnd then:
                > 1) what is it giving me??
                > 2) how do I get the correct handle other than Enum and using Caption???
                >
                >FYI even trying to reparent it manually didn't seem to work for the VB form.[/color]

                <snip>

                Here is a demo I knocked up for reparenting Notepad

                The bit I think you need is InstanceToWnd

                I suggest you run this up as it is
                - test it
                - then make another version with MDI forms
                - check with Notepad
                - then try the 3rd party App instead of Notepad
                - it could be a number of problems
                for example I found WaitForSingleOb ject was essential
                (for slower loading Apps)

                Option Explicit

                ' J French - 27th Nov 2003
                ' Shell and Re-Parent
                ' hacked from MS and KPD

                Private Declare Function ShellExecute _
                Lib "shell32.dl l" _
                Alias "ShellExecu teA" _
                (ByVal hwnd As Long, _
                ByVal lpOperation As String, _
                ByVal lpFile As String, _
                ByVal lpParameters As String, _
                ByVal lpDirectory As String, _
                ByVal nShowCmd As Long) As Long
                Const SW_SHOWNORMAL = 1

                Private Declare Function MoveWindow _
                Lib "user32" _
                (ByVal hwnd As Long, _
                ByVal x As Long, _
                ByVal y As Long, _
                ByVal nWidth As Long, _
                ByVal nHeight As Long, _
                ByVal bRepaint As Long) As Long

                Private Declare Function FindWindow _
                Lib "user32" _
                Alias "FindWindow A" _
                (ByVal lpClassName As Long, _
                ByVal lpWindowName As Long) As Long
                Private Declare Function GetParent _
                Lib "user32" (ByVal hwnd As Long) As Long
                Private Declare Function SetParent _
                Lib "user32" _
                (ByVal hWndChild As Long, _
                ByVal hWndNewParent As Long) As Long
                Private Declare Function GetWindowThread ProcessId _
                Lib "user32" _
                (ByVal hwnd As Long, _
                lpdwProcessId As Long) As Long
                Private Declare Function GetWindow _
                Lib "user32" _
                (ByVal hwnd As Long, _
                ByVal wCmd As Long) As Long
                Private Declare Function LockWindowUpdat e _
                Lib "user32" _
                (ByVal hwndLock As Long) As Long
                Private Declare Function GetDesktopWindo w _
                Lib "user32" () As Long
                Private Declare Function DestroyWindow _
                Lib "user32" (ByVal hwnd As Long) As Long
                Private Declare Function TerminateProces s _
                Lib "kernel32" _
                (ByVal hProcess As Long, _
                ByVal uExitCode As Long) As Long
                Private Declare Function GetCurrentProce ss _
                Lib "kernel32" () As Long
                Private Declare Function Putfocus _
                Lib "user32" _
                Alias "SetFocus" _
                (ByVal hwnd As Long) As Long
                Const GW_HWNDNEXT = 2


                Private Type STARTUPINFO
                cb As Long
                lpReserved As String
                lpDesktop As String
                lpTitle As String
                dwX As Long
                dwY As Long
                dwXSize As Long
                dwYSize As Long
                dwXCountChars As Long
                dwYCountChars As Long
                dwFillAttribute As Long
                dwFlags As Long
                wShowWindow As Integer
                cbReserved2 As Integer
                lpReserved2 As Long
                hStdInput As Long
                hStdOutput As Long
                hStdError As Long
                End Type

                Private Type PROCESS_INFORMA TION
                hProcess As Long
                hThread As Long
                dwProcessID As Long
                dwThreadID As Long
                End Type


                Private Declare Function CreateProcessA _
                Lib "kernel32" _
                (ByVal lpApplicationNa me As String, _
                ByVal lpCommandLine As String, _
                ByVal lpProcessAttrib utes As Long, _
                ByVal lpThreadAttribu tes As Long, _
                ByVal bInheritHandles As Long, _
                ByVal dwCreationFlags As Long, _
                ByVal lpEnvironment As Long, _
                ByVal lpCurrentDirect ory As String, _
                lpStartupInfo As STARTUPINFO, _
                lpProcessInform ation As PROCESS_INFORMA TION) As Long

                Private Declare Function WaitForSingleOb ject _
                Lib "kernel32" _
                (ByVal hHandle As Long, _
                ByVal dwMilliseconds As Long) As Long

                Private Declare Function CloseHandle Lib "kernel32" _
                (ByVal hObject As Long) As Long

                Private Const NORMAL_PRIORITY _CLASS = &H20&


                Dim mWnd As Long

                Function InstanceToWnd(B yVal target_pid As Long) As Long
                Dim test_hwnd As Long, _
                test_pid As Long, _
                test_thread_id As Long
                'Find the first window
                test_hwnd = FindWindow(ByVa l 0&, ByVal 0&)
                Do While test_hwnd <> 0
                'Check if the window isn't a child
                If GetParent(test_ hwnd) = 0 Then
                'Get the window's thread
                test_thread_id = GetWindowThread ProcessId(test_ hwnd, _
                test_pid)
                If test_pid = target_pid Then
                InstanceToWnd = test_hwnd
                Exit Do
                End If
                End If
                'retrieve the next window
                test_hwnd = GetWindow(test_ hwnd, GW_HWNDNEXT)
                Loop
                End Function

                Public Function ExecCmd(cmdline $) As Long
                Dim proc As PROCESS_INFORMA TION
                Dim start As STARTUPINFO
                Dim Ret&

                ' Initialize the STARTUPINFO structure:
                start.cb = Len(start)

                ' Start the shelled application:
                Ret& = CreateProcessA( vbNullString, cmdline$, _
                0&, 0&, 1&, _
                NORMAL_PRIORITY _CLASS, _
                0&, vbNullString, _
                start, proc)
                ' --- let it start - this seems important
                Call WaitForSingleOb ject(proc.hProc ess, 500)
                If Ret Then
                ExecCmd = InstanceToWnd(p roc.dwProcessID )
                Me.Print Ret, ExecCmd
                Call CloseHandle(pro c.hThread)
                Call CloseHandle(pro c.hProcess)
                End If

                End Function


                Private Sub Command1_Click( )
                'KPD-Team 1999
                'URL: http://www.allapi.net/
                'E-Mail: KPDTeam@Allapi. net
                ' ---
                Me.AutoRedraw = True

                'Lock the window update
                LockWindowUpdat e GetDesktopWindo w

                'Execute notepad.Exe
                mWnd = ExecCmd("notepa d.exe")
                'If mWnd = 0 Then MsgBox "Error starting the app"

                Me.Print Str$(mWnd)
                ' Set the notepad's parent
                If mWnd Then
                SetParent mWnd, Me.hwnd
                ' -
                Me.ScaleMode = vbPixels
                Call MoveWindow(mWnd , 0, 0, _
                Me.ScaleWidth, _
                Me.ScaleHeight, 1)
                ' Put the focus on notepad
                Putfocus mWnd
                End If

                ' Unlock window update
                LockWindowUpdat e False
                End Sub
                Private Sub Form_Unload(Can cel As Integer)
                'Unload notepad
                'DestroyWindow mWnd
                'End this program
                End Sub


                Comment

                • dw85745

                  #9
                  Re: Reply to J French (other returned)

                  Will try your example.

                  - Per previous posts notepad works fine, no problem
                  - I'm not using WaitForSingleOb ject so will see if that makes a
                  difference.
                  - InstanceToWnd was copied from the Q (or vise-versa).
                  - Have allapi, but didn't try their example as the key code IMHO
                  (InstanceToWnd) looks like
                  a mirror of the Q.

                  David


                  "J French" <erewhon@nowher e.com> wrote in message
                  news:3ff6a30e.6 6960888@news.bt click.com...[color=blue]
                  > On Fri, 2 Jan 2004 17:21:10 -0700, "dw85745" <dw85745@gbronl ine.com>
                  > wrote:
                  >[color=green]
                  > >J French sorry it took so long:
                  > >
                  > >Your right the handle is different.
                  > >So if Q242308 isn't converting the hInstance from Shell to hWnd then:
                  > > 1) what is it giving me??
                  > > 2) how do I get the correct handle other than Enum and using[/color][/color]
                  Caption???[color=blue][color=green]
                  > >
                  > >FYI even trying to reparent it manually didn't seem to work for the VB[/color][/color]
                  form.[color=blue]
                  >
                  > <snip>
                  >
                  > Here is a demo I knocked up for reparenting Notepad
                  >
                  > The bit I think you need is InstanceToWnd
                  >
                  > I suggest you run this up as it is
                  > - test it
                  > - then make another version with MDI forms
                  > - check with Notepad
                  > - then try the 3rd party App instead of Notepad
                  > - it could be a number of problems
                  > for example I found WaitForSingleOb ject was essential
                  > (for slower loading Apps)
                  >
                  > Option Explicit
                  >
                  > ' J French - 27th Nov 2003
                  > ' Shell and Re-Parent
                  > ' hacked from MS and KPD
                  >
                  > Private Declare Function ShellExecute _
                  > Lib "shell32.dl l" _
                  > Alias "ShellExecu teA" _
                  > (ByVal hwnd As Long, _
                  > ByVal lpOperation As String, _
                  > ByVal lpFile As String, _
                  > ByVal lpParameters As String, _
                  > ByVal lpDirectory As String, _
                  > ByVal nShowCmd As Long) As Long
                  > Const SW_SHOWNORMAL = 1
                  >
                  > Private Declare Function MoveWindow _
                  > Lib "user32" _
                  > (ByVal hwnd As Long, _
                  > ByVal x As Long, _
                  > ByVal y As Long, _
                  > ByVal nWidth As Long, _
                  > ByVal nHeight As Long, _
                  > ByVal bRepaint As Long) As Long
                  >
                  > Private Declare Function FindWindow _
                  > Lib "user32" _
                  > Alias "FindWindow A" _
                  > (ByVal lpClassName As Long, _
                  > ByVal lpWindowName As Long) As Long
                  > Private Declare Function GetParent _
                  > Lib "user32" (ByVal hwnd As Long) As Long
                  > Private Declare Function SetParent _
                  > Lib "user32" _
                  > (ByVal hWndChild As Long, _
                  > ByVal hWndNewParent As Long) As Long
                  > Private Declare Function GetWindowThread ProcessId _
                  > Lib "user32" _
                  > (ByVal hwnd As Long, _
                  > lpdwProcessId As Long) As Long
                  > Private Declare Function GetWindow _
                  > Lib "user32" _
                  > (ByVal hwnd As Long, _
                  > ByVal wCmd As Long) As Long
                  > Private Declare Function LockWindowUpdat e _
                  > Lib "user32" _
                  > (ByVal hwndLock As Long) As Long
                  > Private Declare Function GetDesktopWindo w _
                  > Lib "user32" () As Long
                  > Private Declare Function DestroyWindow _
                  > Lib "user32" (ByVal hwnd As Long) As Long
                  > Private Declare Function TerminateProces s _
                  > Lib "kernel32" _
                  > (ByVal hProcess As Long, _
                  > ByVal uExitCode As Long) As Long
                  > Private Declare Function GetCurrentProce ss _
                  > Lib "kernel32" () As Long
                  > Private Declare Function Putfocus _
                  > Lib "user32" _
                  > Alias "SetFocus" _
                  > (ByVal hwnd As Long) As Long
                  > Const GW_HWNDNEXT = 2
                  >
                  >
                  > Private Type STARTUPINFO
                  > cb As Long
                  > lpReserved As String
                  > lpDesktop As String
                  > lpTitle As String
                  > dwX As Long
                  > dwY As Long
                  > dwXSize As Long
                  > dwYSize As Long
                  > dwXCountChars As Long
                  > dwYCountChars As Long
                  > dwFillAttribute As Long
                  > dwFlags As Long
                  > wShowWindow As Integer
                  > cbReserved2 As Integer
                  > lpReserved2 As Long
                  > hStdInput As Long
                  > hStdOutput As Long
                  > hStdError As Long
                  > End Type
                  >
                  > Private Type PROCESS_INFORMA TION
                  > hProcess As Long
                  > hThread As Long
                  > dwProcessID As Long
                  > dwThreadID As Long
                  > End Type
                  >
                  >
                  > Private Declare Function CreateProcessA _
                  > Lib "kernel32" _
                  > (ByVal lpApplicationNa me As String, _
                  > ByVal lpCommandLine As String, _
                  > ByVal lpProcessAttrib utes As Long, _
                  > ByVal lpThreadAttribu tes As Long, _
                  > ByVal bInheritHandles As Long, _
                  > ByVal dwCreationFlags As Long, _
                  > ByVal lpEnvironment As Long, _
                  > ByVal lpCurrentDirect ory As String, _
                  > lpStartupInfo As STARTUPINFO, _
                  > lpProcessInform ation As PROCESS_INFORMA TION) As Long
                  >
                  > Private Declare Function WaitForSingleOb ject _
                  > Lib "kernel32" _
                  > (ByVal hHandle As Long, _
                  > ByVal dwMilliseconds As Long) As Long
                  >
                  > Private Declare Function CloseHandle Lib "kernel32" _
                  > (ByVal hObject As Long) As Long
                  >
                  > Private Const NORMAL_PRIORITY _CLASS = &H20&
                  >
                  >
                  > Dim mWnd As Long
                  >
                  > Function InstanceToWnd(B yVal target_pid As Long) As Long
                  > Dim test_hwnd As Long, _
                  > test_pid As Long, _
                  > test_thread_id As Long
                  > 'Find the first window
                  > test_hwnd = FindWindow(ByVa l 0&, ByVal 0&)
                  > Do While test_hwnd <> 0
                  > 'Check if the window isn't a child
                  > If GetParent(test_ hwnd) = 0 Then
                  > 'Get the window's thread
                  > test_thread_id = GetWindowThread ProcessId(test_ hwnd, _
                  > test_pid)
                  > If test_pid = target_pid Then
                  > InstanceToWnd = test_hwnd
                  > Exit Do
                  > End If
                  > End If
                  > 'retrieve the next window
                  > test_hwnd = GetWindow(test_ hwnd, GW_HWNDNEXT)
                  > Loop
                  > End Function
                  >
                  > Public Function ExecCmd(cmdline $) As Long
                  > Dim proc As PROCESS_INFORMA TION
                  > Dim start As STARTUPINFO
                  > Dim Ret&
                  >
                  > ' Initialize the STARTUPINFO structure:
                  > start.cb = Len(start)
                  >
                  > ' Start the shelled application:
                  > Ret& = CreateProcessA( vbNullString, cmdline$, _
                  > 0&, 0&, 1&, _
                  > NORMAL_PRIORITY _CLASS, _
                  > 0&, vbNullString, _
                  > start, proc)
                  > ' --- let it start - this seems important
                  > Call WaitForSingleOb ject(proc.hProc ess, 500)
                  > If Ret Then
                  > ExecCmd = InstanceToWnd(p roc.dwProcessID )
                  > Me.Print Ret, ExecCmd
                  > Call CloseHandle(pro c.hThread)
                  > Call CloseHandle(pro c.hProcess)
                  > End If
                  >
                  > End Function
                  >
                  >
                  > Private Sub Command1_Click( )
                  > 'KPD-Team 1999
                  > 'URL: http://www.allapi.net/
                  > 'E-Mail: KPDTeam@Allapi. net
                  > ' ---
                  > Me.AutoRedraw = True
                  >
                  > 'Lock the window update
                  > LockWindowUpdat e GetDesktopWindo w
                  >
                  > 'Execute notepad.Exe
                  > mWnd = ExecCmd("notepa d.exe")
                  > 'If mWnd = 0 Then MsgBox "Error starting the app"
                  >
                  > Me.Print Str$(mWnd)
                  > ' Set the notepad's parent
                  > If mWnd Then
                  > SetParent mWnd, Me.hwnd
                  > ' -
                  > Me.ScaleMode = vbPixels
                  > Call MoveWindow(mWnd , 0, 0, _
                  > Me.ScaleWidth, _
                  > Me.ScaleHeight, 1)
                  > ' Put the focus on notepad
                  > Putfocus mWnd
                  > End If
                  >
                  > ' Unlock window update
                  > LockWindowUpdat e False
                  > End Sub
                  > Private Sub Form_Unload(Can cel As Integer)
                  > 'Unload notepad
                  > 'DestroyWindow mWnd
                  > 'End this program
                  > End Sub
                  >
                  >[/color]


                  Comment

                  Working...