2011-04-28 97 views

回答

0

這是一個殺死特定程序的所有可見實例的函數。你需要知道它的ClassName。我已經能夠通過搜索找到常見的應用(如Office應用程序)的類名:

FUNCTION KillApp 
*============================================================================== 
* Program:    KillApp.PRG 
* Purpose:    Close any invisible instances of a specified program 
* Author:    Tamar E. Granor 
* Last revision:   04/16/02 
* Parameters:   tcClassName - the classname of the app to close 
* Returns:    Number of instances closed; -1, if parameter problems 
* Environment in:  
* Environment out:  Several API functions declared 
*============================================================================== 
#DEFINE GW_CHILD 5 
#DEFINE GW_HWNDNEXT 2 
#DEFINE WM_CLOSE 0x10 

LPARAMETERS tcClassName 

ASSERT VARTYPE(tcClassName) = "C" AND NOT EMPTY(tcClassName) ; 
    MESSAGE "KillApp: Must pass class name of application to kill" 

IF VARTYPE(tcClassName) <> "C" OR EMPTY(tcClassName) 
    ERROR 11 
    RETURN -1 
ENDIF 

DECLARE LONG GetDesktopWindow IN WIN32API 
DECLARE LONG GetWindow IN WIN32API LONG hWnd, LONG wCmd 
DECLARE LONG IsWindowVisible IN WIN32API LONG hWnd 
DECLARE LONG GetClassName IN WIN32API LONG hWnd, STRING lpClassName, LONG nMaxCount 
DECLARE LONG PostMessage IN WIN32API LONG hwnd, LONG wMsg, LONG wParam, LONG lParam 

LOCAL lnDesktopHWnd, lnHWnd, lnOldHWnd, lcClass, lnLen, nClosedCount 

lnDesktopHWnd = GetDesktopWindow() 
lnHWnd = GetWindow(lnDesktopHWnd, GW_CHILD) 
lnClosedCount = 0 

DO WHILE lnHWnd <> 0 
    lcClass = SPACE(256) 
    lnLen = GetClassName(lnHWnd, @lcClass, 256) 
    lnOldHWnd = lnHWnd 
    lnHWnd = GetWindow(lnOldHWnd, GW_HWNDNEXT) 
    IF UPPER(LEFT(lcClass, lnLen)) = UPPER(tcClassName) 
     lnVisible = IsWindowVisible(lnOldHWnd) 
     IF lnVisible = 0 
      PostMessage(lnOldHWnd, WM_CLOSE, 0, 0) 
      lnClosedCount = lnClosedCount + 1 
     ENDIF 
    ENDIF 
ENDDO 

RETURN lnClosedCount 

剛剛意識到的過程可能不一樣的應用程序。它看起來像查找過程的API函數是EnumProcesses。檢出http://www.news2news.com/vfp/?group=-1&function=246

添馬艦

+0

非常好的添馬艦。我能夠調整你的代碼,簡單地給我一個正在運行的進程的遊標(和一個集合)。我只是想看看機器上運行的是什麼,不一定會殺死任何東西。我改編的代碼在這裏http://codepaste.net/1enkjz – MattSlay 2016-10-17 16:47:54