Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP.exe to different VFP.exe
Message
From
16/02/2021 18:12:02
 
 
To
16/02/2021 17:23:24
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01678195
Message ID:
01678299
Views:
59
>>I was able to reduce the number of items to check by adding the legacy name to the query.
>>SELECT * FROM Win32_Process WHERE Name = 'legacyapp.exe'
>>
>>I altered the loop to see which ExecutablePath each instance of the legacy app has.
>>IF upper(m.Process.Name) == "LEGACYAPP.EXE" and 'somefolder'$m.Process.ExecutablePath
>>
>>Very good!
>>
>>Now to make that application come to the foreground. Any suggestions? Is m.Process.Handle the hWnd? Why is it the same as m.Process.ProcessID?
>>
>
>Mike, once you have the process ID, I think you can get the hWnd of its _Screen that you can move to foreground. I haven't tried this, but hopefully it's workable.
>
>You'll need VFP2C32.fll to get the required information from the system. The library is available from https://github.com/ChristianEhlscheid/vfp2c32.
>
>After the library is loaded, create an array of top level windows:
>
>
>#include "vfp2c.h"
>
>DIMENSION hWnds[1, 2]
>AWindowsEx('hWnds', 'WO', AWINDOWS_TOPLEVEL)
>
>
>Now, you'll have an array of top level windows for the processes running in your system. The first column holds a hWnd, the second the process id (I think...).
>
>Go trough the array and locate the process you got from the WMI_Query. Fetch the corresponding hWnd, and send the window to the foreground.
>
>Let us know if it works...

Sorry did not see what you where after
I had this one saved - using just win32 :
*
* 
* Original source: 
* "List child windows for the Windows desktop" from https://github.com/VFPX/Win32API/blob/master/samples/sample_027.md
*
* Modified by: Marco Plaza,  github.com/nftools :
* added GetWindowThreadProcessId() to get the PID from hWnd 
* saves to cursor all running applications with their hwnd & corresponding PID's.
*

#Define GW_HWNDLAST 1
#Define GW_HWNDNEXT 2
#Define GW_CHILD 5
Do Declare

Create Cursor csResult (HWnd N(12), pid i,isvisible N(1),;
	leftpos i, toppos i, rightpos i, botpos i, wincap C(64), classname C(64))

Local hDesktop, hFirstChild, hLastChild, rc, cWinCap, cWinClass,;
	nVisible, nLeft, nTop, nRight, nBottom

hDesktop = GetDesktopWindow()
hFirstChild = GetWindow(m.hDesktop, GW_CHILD)
hLastChild = GetWindow(m.hFirstChild, GW_HWNDLAST)

hCurrent = m.hFirstChild

Do While .T.

	cWinCap = GetWinText(m.hCurrent)
	cWinClass= GetClsName(m.hCurrent)
	nVisible = IsWindowVisible(m.hCurrent)

	rc = Repli(Chr(0),16)
	= GetWindowRect(m.hCurrent, @rc)
	nLeft = buf2dword(Substr(m.rc, 1,4))
	nTop = buf2dword(Substr(m.rc, 5,4))
	nRight = buf2dword(Substr(m.rc, 9,4))
	nBottom = buf2dword(Substr(m.rc, 13,4))

	pidx = 0
	GetWindowThreadProcessId(m.hCurrent,@pidx)

	Insert Into csResult Values (m.hCurrent, m.pidx, m.nVisible,m.nLeft, m.nTop, m.nRight, m.nBottom, m.cWinCap, m.cWinClass)

	If m.hCurrent = m.hLastChild
		Exit
	Endif
	hCurrent = GetWindow(m.hCurrent, GW_HWNDNEXT)

Enddo

Go Top
Browse Normal Nowait

*------------------------------------------
Function GetClsName(hWindow)
*------------------------------------------
Local nBufsize, cBuffer
cBuffer = Repli(Chr(0), 250)
nBufsize = GetClassName(hWindow, @cBuffer, Len(cBuffer))
Return Substr(cBuffer, 1, nBufsize)

*----------------------------------------
Function GetWinText(hWindow)
*----------------------------------------
Local cBuffer, nResult
cBuffer = Space(250)
nResult = GetWindowText(hWindow, @cBuffer, Len(cBuffer))
Return Substr(cBuffer, 1, nResult)


*----------------------------------------------------
Function buf2dword(lcBuffer)
*----------------------------------------------------
Return Asc(Substr(lcBuffer, 1,1)) + ;
	BitLShift(Asc(Substr(lcBuffer, 2,1)),  8) +;
	BitLShift(Asc(Substr(lcBuffer, 3,1)), 16) +;
	BitLShift(Asc(Substr(lcBuffer, 4,1)), 24)

*----------------------------------------------------
Procedure Declare
*----------------------------------------------------

Declare Integer GetDesktopWindow In user32
Declare Integer GetWindow In user32 Integer HWnd, Integer wFlag
Declare Integer GetWindowRect In user32 Integer HWnd, String @lpRect
Declare Integer IsWindowVisible In user32 Integer HWnd
Declare Integer GetWindowText In user32;
	INTEGER HWnd, String @lpString, Integer cch

Declare Integer GetClassName In user32;
	INTEGER HWnd, String lpClassName, Integer nMaxCount

Declare Integer GetWindowThreadProcessId In user32    Integer HWnd,    Integer @pid
@nfoxdev
github.com/nfoxdev
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform