请教吹版主关于API函数 openprocess
请教吹版主,我在https://www.看到这段VB代码,想借此实现在多个打开的EXCEL文档中找到需要关闭的文档,然后在转成VFP后在下面代码 ??处始终出错,请教是解决办法
Declare Long FindWindowEx IN user32 long hWnd1, long hWnd2, string lpsz1, string lpsz2
DECLARE Long PostMessage IN WIN32API as PostMessageA Long hWnd, Long Msg, Long wParam, Long lParam
Declare INTEGER GetWindowText IN User32 long hWnd, string lpString , long cch
Declare INTEGER GetWindowThreadProcessId in user32 long hwnd, long lpdwProcessId
Declare INTEGER OpenProcess in kernel32 long dwDesiredAccess, long bInheritHandle, long dwProcessId
Declare INTEGER TerminateProcess in kernel32 long hProcess, long uExitCode
*Declare INTEGER RtlAdjustPrivilege in ntdll AND Privilege&, ByVal NewValue&, ByVal NewThread&, OldValue&)
#define WM_CLOSE = &H10
#define PROCESS_TERMINATE = &H1
hWnd = FindWindow("XLMAIN", null)
procId=0
iid=GetWindowThreadProcessId(hWnd, @procId)
DO While hWnd <> 0
strText = Space(256)
GetWindowText(hWnd, @strText, Len(strText))
strText = Left(strText, at("-",strText ) - 1)
If at("Microsoft Excel",strText,1) > 0 Then
procId = 0
iid=GetWindowThreadProcessId(hWnd, procId)
hProcess = OpenProcess(PROCESS_ALL_ACCESS ,0,iid) && ??
iRet = TerminateProcess(hProcess, 0)
iRet = PostMessage(hWnd, WM_CLOSE, 0, 0)
EndIf
enddo