Page 1 of 1

Run Process -> Return Handle

Posted: Fri May 20, 2022 12:12 am
by AUGE_OHR
hi,

i want to run many Instance of App but i need "Control" them.
as they all have "same Name" i can´t use "FindWindow" to get Handle

so how can i "run" a Instance and get it´s Handle under harbour :idea:
attached Xbase++ Sample using OT4XB Syntax
TRunProcess.zip
(3.95 KiB) Downloaded 61 times

Re: Run Process -> Return Handle

Posted: Fri May 20, 2022 2:04 am
by AUGE_OHR
hi

it seems that ShellExecute() return

Code: Select all

  HMG_retnl ((LONG_PTR) hInstance );
https://docs.microsoft.com/en-us/window ... llexecutea
If the function succeeds, it returns a value greater than 32. If the function fails, it returns an error value that indicates the cause of the failure. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Windows applications. It is not a true HINSTANCE, however. It can be cast only to an INT_PTR and compared to either 32 or the following error codes below.

Re: Run Process -> Return Handle

Posted: Fri May 20, 2022 5:52 am
by AUGE_OHR
hi

i try it this Way

Code: Select all

   hwnd := ShellExecute(0, "open", "Playvlc.exe", cPara,cHome ,1)
   AADD(aWin, hwnd)
it does start "Playvlc.exe" as i want but i have always 42 as hwnd ... :(
what do i miss ... :idea:

Re: Run Process -> Return Handle

Posted: Wed May 25, 2022 8:31 pm
by AUGE_OHR
hi,

found out that i can find "Title" even when use NOCAPTION
so i can "search" for Windows and it´s Handle after call ShellExecute()

Code: Select all

PROCEDURE GetVLChandle()
LOCAL cTitle, hwnd, ii, iMax, cMemo

   iMax := nRow * nCol
   FOR ii := 1 TO iMax
      cTitle := "PLAYVLC" + STRZERO( ii, 2 )
      hwnd := FindWindowEx(,,, cTitle )
      IF !EMPTY( hwnd )
         WritePlay( cTitle + ".PLAY", STR( hwnd ) )
         AADD( aWin, hwnd )
      ENDIF
   NEXT
! Note : i write a "Number" ... not a String ?!

Code: Select all

STATIC PROCEDURE CheckCloseScreen()
   ...
   IF lCheckScreen = .T.
      aDir := DIRECTORY( "PLAYVLC*.PLAY" )
      iMax := LEN( aDir )
      FOR ii := 1 TO iMax
         IF ".PLAY" $ aDir[ ii ] [ F_NAME ]
            nCount ++
            cMemo := ReadPlay( aDir[ ii ] [ F_NAME ] )
            AADD( aCheck, cMemo )
         ENDIF
      NEXT
      IF nCount <> nOpenVLC
         lCheckScreen = .F.
   
         iMax := LEN( aWin )
         FOR ii := 1 TO iMax
            hProcess := aWin[ ii ]
            SendMessage( hProcess, WM_CLOSE, 0, 0 )
            hb_idleSleep( .1 )
         NEXT
         Domethod( "IPTVMAIN", "PLAYTV", "SHOW" )
         SnapToCtrl("IPTVMAIN","PLAYTV")

      ENDIF
   ENDIF