VFP9+win10环境下如何获取操作系统后台已运行软件名称
需要获取操作系统后台已运行软件的列表,从中判断某个软件是否被运行,如果没有被运行则由VFP调用对应程序运行。
2023-03-23 16:40
2023-03-23 16:49
2023-03-23 16:50
2023-03-23 16:51
2023-03-23 17:39
程序代码:Set Nulldisplay To
Create Cursor ttt (name V(50), value V(250))
oWMI = GetObject('winmgmts://')
*!* cQuery = 'Select * From Win32_Process'
*!* 取这俩属性差不多够用了
cQuery = 'Select Caption,ExecutablePath From Win32_Process'
oRes = oWMI.ExecQuery(cQuery)
Clear
For ii = 0 to oRes.Count - 1
For each o1 in oRes.ItemIndex(ii).Properties_
cVal = ''
If o1.IsArray and !IsNull(o1.Value)
For each o2 in o1.Value
cVal = cVal + Transform(o2) + ','
EndFor
Else
cVal = Transform(o1.Value)
EndIf
Insert into ttt (name, value) Values (o1.name, cVal)
EndFor
Insert into ttt (name) Values ('====================')
EndFor
Locate
Browse nowait[此贴子已经被作者于2023-3-23 17:57编辑过]
2023-03-23 17:53
2023-03-23 18:34
2023-03-23 19:00
程序代码:
*-- VFP Code
#Define GW_NEXT 2
#define GW_CHILD 5
Declare Integer GetActiveWindow In user32
Declare Integer GetWindow In win32api Integer HWnd, Integer wFlag
Declare Integer GetWindowTextA In win32api Integer hwnd, String @ctitle, Integer ntitle
Declare Integer SetForegroundWindow In Win32api Integer
DECLARE inte IsChild IN WIN32API integer Hwndparent,integer Hwnd
Declare inte FindWindowEx IN win32api inte hWnd1,inte hWnd2, string lpsz1, string lpsz2
Declare Integer GetWindowText In win32api Integer hand, String @ctitle, Integer ntitle
clea
*hcurrent=findwindowex(_vfp.hwnd,0,null,null)
hcurrent=findwindowex(0,0,null,null)
*?hcurrent
*hCurrent=GetActiveWindow() &&从当前活动窗口开始
*lnhCurrent=hCurrent
*SetForegroundWindow(_vfp.HWnd)
*SetForegroundWindow(_Screen.HWnd) &&或Thisform.HWnd
*SetForegroundWindow(hCurrent) && vfp8 以下没有 HWnd
*lcWinLists=""
Create Cursor t1 (WindowHWnd I,WindowTitle C(254))
Do While hCurrent!=0
lcWinTitle=Space(255)
lnlength=GetWindowTextA(hCurrent,@lcWinTitle,Len(lcWinTitle))
lcwintitle=SUBSTR(lcwintitle,1,lnlength)
*lcWinTitle=Iif(lnlength>0,Strtran(Trim(lcWinTitle),Chr(0),""),"")
Insert Into t1 Values (hCurrent,lcWinTitle)
*hCurrent=findwindowex(_vfp.hwnd,hcurrent,null,null) &&得到下一个窗口句柄
hCurrent=findwindowex(0,hcurrent,null,null) &&得到下一个窗口句柄
*?ischild(_vfp.hWnd,hcurrent)
*?hcurrent
Enddo
*SetForegroundWindow(lnhCurrent)
Select t1
*Locate
Browse
*Clear Dlls
2023-03-23 20:03
2023-03-24 05:41