Alaska Software Inc. - wildcard find and close window
Username: Password:
AuthorTopic: wildcard find and close window
Rudolf Reinthalerwildcard find and close window
on Wed, 16 Mar 2011 15:39:20 +0100
Hello,
I need to find a open window from another program to close it. I know 
only a part of the name of the window title. With the attached function 
I always get 0 in hWnd. Is there another function then FindWindowA ?
regards
Rudolf


function KillProcessFromWindow( cText )
******************************************************************
local result :=  .F.
local pid := 0
local hProc
local hWnd := DllCall("user32.dll", DLL_STDCALL, "FindWindowA",0,cText)
if hWnd > 0
      @user32:GetWindowThreadProcessId(hWnd,@pid)
      hProc := @kernel32:OpenProcess(0x411,.F.,pid)
      if( !Empty(hProc) )
           result := ( @kernel32:TerminateProcess(hProc) != 0 )
           @kernel32:CloseHandle(hProc)
      end
endif
return result
Edgar Borger Re: wildcard find and close window
on Wed, 16 Mar 2011 12:33:55 -0300
Hello Rudolf,

I don't know if this helps, but I got this function from somewhere a 
long time ago, I can't ever remember from where.....

It is suppose to end and Adobe Reader window....

********************************************************************************
*  Function AllWindows(lShow) -> aTitles  { nHandle, cTitle }
*           Gets the handles & titles of all top level windows.
********************************************************************************
*  If lShow == .T. Display Titles in a Message Box and return the array 
aTitles.
*  If lShow == .F. Just return the array aTitles.
********************************************************************************
DLLFUNCTION EnumWindows( cProc, nPara ) USING STDCALL FROM USER32.DLL
DLLFUNCTION EnumChildWindows( hWndParent, lpEnumFunc, lParam ) USING 
STDCALL FROM USER32.DLL
DLLFUNCTION GetWindowTextA( nHandle, @cBuf, nSize ) USING STDCALL FROM 
USER32.DLL
*PostMessage   DllCall("User32.DLL", DLL_STDCALL,"PostMessageA", 
nhwnd,nwMsg,nwParam,nlParam)

FUNCTION KillAcro( lAll )
    LOCAL i, ok := .t.
    PRIVATE aTitles := {}, cTitles := ""
	if lAll = NIL
		lAll := .f.
	endif

	do while ok
		aTitles := {}
		cTitles := ""
		ok := .f.
	   EnumWindows(BaCallBack("EnumWindow",BA_CB_GENERIC2),0)
    	IF !empty(aTitles)
       	 FOR i := 1 TO len(aTitles)
          	  cTitles := cTitles+;
             	       padl(str(aTitles[i,2],10,0),10)+;
                	    chr(9)+;
                   	 iif(aTitles[i,2]<100000,chr(9),"")+;
	                   aTitles[i,1]
    	        IF i<len(aTitles)
       	         cTitles := cTitles+chr(13)
          	  ENDIF
	       NEXT i
    	ENDIF

		for i = 1 to len(aTitles)
			if Upper(Substr(aTitles[i,1],1,12)) = 'ADOBE READER'
				nhwnd := aTitles[i,2]
				nwMsg := 16
				nwParam := 0
				nlParam := 0
				PostMessageA( nhwnd, nwMsg, nwParam, nlParam)
				ok := lAll
				nwMsg := 18
				PostMessageA( nhwnd, nwMsg, nwParam, nlParam)
				ok := lAll
				sleep(10)
			endif
		next
	enddo

RETURN(.t.)

******************************************************


Em 16/03/2011 11:39, Rudolf Reinthaler escreveu:
> Hello,
> I need to find a open window from another program to close it. I know
> only a part of the name of the window title. With the attached function
> I always get 0 in hWnd. Is there another function then FindWindowA ?
> regards
> Rudolf
>
>
> function KillProcessFromWindow( cText )
> ******************************************************************
> local result := .F.
> local pid := 0
> local hProc
> local hWnd := DllCall("user32.dll", DLL_STDCALL, "FindWindowA",0,cText)
> if hWnd > 0
> @user32:GetWindowThreadProcessId(hWnd,@pid)
> hProc := @kernel32:OpenProcess(0x411,.F.,pid)
> if( !Empty(hProc) )
> result := ( @kernel32:TerminateProcess(hProc) != 0 )
> @kernel32:CloseHandle(hProc)
> end
> endif
> return result
>
>
>
>
>
>
Rudolf ReinthalerRe: wildcard find and close window
on Wed, 16 Mar 2011 17:36:17 +0100
Hello Edgar,
looks interesting,could you please send me the PostmessageA function ? I 
would also like to send keystrokes to the other window (page up and down 
in a Acrobat window)
regards
Rudolf

Am 16.03.2011 16:33, schrieb Edgar Borger:
> Hello Rudolf,
>
> I don't know if this helps, but I got this function from somewhere a
> long time ago, I can't ever remember from where.....
>
> It is suppose to end and Adobe Reader window....
>
> ********************************************************************************
>
> * Function AllWindows(lShow) -> aTitles { nHandle, cTitle }
> * Gets the handles & titles of all top level windows.
> ********************************************************************************
>
> * If lShow == .T. Display Titles in a Message Box and return the array
> aTitles.
> * If lShow == .F. Just return the array aTitles.
> ********************************************************************************
>
> DLLFUNCTION EnumWindows( cProc, nPara ) USING STDCALL FROM USER32.DLL
> DLLFUNCTION EnumChildWindows( hWndParent, lpEnumFunc, lParam ) USING
> STDCALL FROM USER32.DLL
> DLLFUNCTION GetWindowTextA( nHandle, @cBuf, nSize ) USING STDCALL FROM
> USER32.DLL
> *PostMessage DllCall("User32.DLL", DLL_STDCALL,"PostMessageA",
> nhwnd,nwMsg,nwParam,nlParam)
>
> FUNCTION KillAcro( lAll )
> LOCAL i, ok := .t.
> PRIVATE aTitles := {}, cTitles := ""
> if lAll = NIL
> lAll := .f.
> endif
>
> do while ok
> aTitles := {}
> cTitles := ""
> ok := .f.
> EnumWindows(BaCallBack("EnumWindow",BA_CB_GENERIC2),0)
> IF !empty(aTitles)
> FOR i := 1 TO len(aTitles)
> cTitles := cTitles+;
> padl(str(aTitles[i,2],10,0),10)+;
> chr(9)+;
> iif(aTitles[i,2]<100000,chr(9),"")+;
> aTitles[i,1]
> IF i<len(aTitles)
> cTitles := cTitles+chr(13)
> ENDIF
> NEXT i
> ENDIF
>
> for i = 1 to len(aTitles)
> if Upper(Substr(aTitles[i,1],1,12)) = 'ADOBE READER'
> nhwnd := aTitles[i,2]
> nwMsg := 16
> nwParam := 0
> nlParam := 0
> PostMessageA( nhwnd, nwMsg, nwParam, nlParam)
> ok := lAll
> nwMsg := 18
> PostMessageA( nhwnd, nwMsg, nwParam, nlParam)
> ok := lAll
> sleep(10)
> endif
> next
> enddo
>
> RETURN(.t.)
>
> ******************************************************
>
>
> Em 16/03/2011 11:39, Rudolf Reinthaler escreveu:
>> Hello,
>> I need to find a open window from another program to close it. I know
>> only a part of the name of the window title. With the attached function
>> I always get 0 in hWnd. Is there another function then FindWindowA ?
>> regards
>> Rudolf
>>
>>
>> function KillProcessFromWindow( cText )
>> ******************************************************************
>> local result := .F.
>> local pid := 0
>> local hProc
>> local hWnd := DllCall("user32.dll", DLL_STDCALL, "FindWindowA",0,cText)
>> if hWnd > 0
>> @user32:GetWindowThreadProcessId(hWnd,@pid)
>> hProc := @kernel32:OpenProcess(0x411,.F.,pid)
>> if( !Empty(hProc) )
>> result := ( @kernel32:TerminateProcess(hProc) != 0 )
>> @kernel32:CloseHandle(hProc)
>> end
>> endif
>> return result
>>
>>
>>
>>
>>
>>
>
Edgar Borger Re: wildcard find and close window
on Wed, 16 Mar 2011 13:46:43 -0300
Rudolf,
it is there, just remove the asterisk. "*" .....

DLLFUNCTION PostMessageA(nhwnd, nwMsg, nwParam, nlParam) USING STDCALL 
FROM USER32.DLL




Em 16/03/2011 13:36, Rudolf Reinthaler escreveu:
> Hello Edgar,
> looks interesting,could you please send me the PostmessageA function ? I
> would also like to send keystrokes to the other window (page up and down
> in a Acrobat window)
> regards
> Rudolf
>
> Am 16.03.2011 16:33, schrieb Edgar Borger:
>> Hello Rudolf,
>>
>> I don't know if this helps, but I got this function from somewhere a
>> long time ago, I can't ever remember from where.....
>>
>> It is suppose to end and Adobe Reader window....
>>
>> ********************************************************************************
>>
>>
>> * Function AllWindows(lShow) -> aTitles { nHandle, cTitle }
>> * Gets the handles & titles of all top level windows.
>> ********************************************************************************
>>
>>
>> * If lShow == .T. Display Titles in a Message Box and return the array
>> aTitles.
>> * If lShow == .F. Just return the array aTitles.
>> ********************************************************************************
>>
>>
>> DLLFUNCTION EnumWindows( cProc, nPara ) USING STDCALL FROM USER32.DLL
>> DLLFUNCTION EnumChildWindows( hWndParent, lpEnumFunc, lParam ) USING
>> STDCALL FROM USER32.DLL
>> DLLFUNCTION GetWindowTextA( nHandle, @cBuf, nSize ) USING STDCALL FROM
>> USER32.DLL
>> *PostMessage DllCall("User32.DLL", DLL_STDCALL,"PostMessageA",
>> nhwnd,nwMsg,nwParam,nlParam)
>>
>> FUNCTION KillAcro( lAll )
>> LOCAL i, ok := .t.
>> PRIVATE aTitles := {}, cTitles := ""
>> if lAll = NIL
>> lAll := .f.
>> endif
>>
>> do while ok
>> aTitles := {}
>> cTitles := ""
>> ok := .f.
>> EnumWindows(BaCallBack("EnumWindow",BA_CB_GENERIC2),0)
>> IF !empty(aTitles)
>> FOR i := 1 TO len(aTitles)
>> cTitles := cTitles+;
>> padl(str(aTitles[i,2],10,0),10)+;
>> chr(9)+;
>> iif(aTitles[i,2]<100000,chr(9),"")+;
>> aTitles[i,1]
>> IF i<len(aTitles)
>> cTitles := cTitles+chr(13)
>> ENDIF
>> NEXT i
>> ENDIF
>>
>> for i = 1 to len(aTitles)
>> if Upper(Substr(aTitles[i,1],1,12)) = 'ADOBE READER'
>> nhwnd := aTitles[i,2]
>> nwMsg := 16
>> nwParam := 0
>> nlParam := 0
>> PostMessageA( nhwnd, nwMsg, nwParam, nlParam)
>> ok := lAll
>> nwMsg := 18
>> PostMessageA( nhwnd, nwMsg, nwParam, nlParam)
>> ok := lAll
>> sleep(10)
>> endif
>> next
>> enddo
>>
>> RETURN(.t.)
>>
>> ******************************************************
>>
>>
>> Em 16/03/2011 11:39, Rudolf Reinthaler escreveu:
>>> Hello,
>>> I need to find a open window from another program to close it. I know
>>> only a part of the name of the window title. With the attached function
>>> I always get 0 in hWnd. Is there another function then FindWindowA ?
>>> regards
>>> Rudolf
>>>
>>>
>>> function KillProcessFromWindow( cText )
>>> ******************************************************************
>>> local result := .F.
>>> local pid := 0
>>> local hProc
>>> local hWnd := DllCall("user32.dll", DLL_STDCALL, "FindWindowA",0,cText)
>>> if hWnd > 0
>>> @user32:GetWindowThreadProcessId(hWnd,@pid)
>>> hProc := @kernel32:OpenProcess(0x411,.F.,pid)
>>> if( !Empty(hProc) )
>>> result := ( @kernel32:TerminateProcess(hProc) != 0 )
>>> @kernel32:CloseHandle(hProc)
>>> end
>>> endif
>>> return result
>>>
>>>
>>>
>>>
>>>
>>>
>>
>
Rudolf ReinthalerRe: wildcard find and close window
on Wed, 16 Mar 2011 17:57:24 +0100
Hello Edgar,
I have made the function this way:
function PostMessageA(nhwnd,nwMsg,nwParam,nlParam)
return DllCall("User32.DLL", DLL_STDCALL,"PostMessageA", 
nhwnd,nwMsg,nwParam,nlParam)


but the code cannot work, what happens with aTitles and cTitles ?
regards
Rudolf



Am 16.03.2011 17:46, schrieb Edgar Borger:
> Rudolf,
> it is there, just remove the asterisk. "*" .....
>
> DLLFUNCTION PostMessageA(nhwnd, nwMsg, nwParam, nlParam) USING STDCALL
> FROM USER32.DLL
>
>
>
>
> Em 16/03/2011 13:36, Rudolf Reinthaler escreveu:
>> Hello Edgar,
>> looks interesting,could you please send me the PostmessageA function ? I
>> would also like to send keystrokes to the other window (page up and down
>> in a Acrobat window)
>> regards
>> Rudolf
>>
>> Am 16.03.2011 16:33, schrieb Edgar Borger:
>>> Hello Rudolf,
>>>
>>> I don't know if this helps, but I got this function from somewhere a
>>> long time ago, I can't ever remember from where.....
>>>
>>> It is suppose to end and Adobe Reader window....
>>>
>>> ********************************************************************************
>>>
>>>
>>>
>>> * Function AllWindows(lShow) -> aTitles { nHandle, cTitle }
>>> * Gets the handles & titles of all top level windows.
>>> ********************************************************************************
>>>
>>>
>>>
>>> * If lShow == .T. Display Titles in a Message Box and return the array
>>> aTitles.
>>> * If lShow == .F. Just return the array aTitles.
>>> ********************************************************************************
>>>
>>>
>>>
>>> DLLFUNCTION EnumWindows( cProc, nPara ) USING STDCALL FROM USER32.DLL
>>> DLLFUNCTION EnumChildWindows( hWndParent, lpEnumFunc, lParam ) USING
>>> STDCALL FROM USER32.DLL
>>> DLLFUNCTION GetWindowTextA( nHandle, @cBuf, nSize ) USING STDCALL FROM
>>> USER32.DLL
>>> *PostMessage DllCall("User32.DLL", DLL_STDCALL,"PostMessageA",
>>> nhwnd,nwMsg,nwParam,nlParam)
>>>
>>> FUNCTION KillAcro( lAll )
>>> LOCAL i, ok := .t.
>>> PRIVATE aTitles := {}, cTitles := ""
>>> if lAll = NIL
>>> lAll := .f.
>>> endif
>>>
>>> do while ok
>>> aTitles := {}
>>> cTitles := ""
>>> ok := .f.
>>> EnumWindows(BaCallBack("EnumWindow",BA_CB_GENERIC2),0)
>>> IF !empty(aTitles)
>>> FOR i := 1 TO len(aTitles)
>>> cTitles := cTitles+;
>>> padl(str(aTitles[i,2],10,0),10)+;
>>> chr(9)+;
>>> iif(aTitles[i,2]<100000,chr(9),"")+;
>>> aTitles[i,1]
>>> IF i<len(aTitles)
>>> cTitles := cTitles+chr(13)
>>> ENDIF
>>> NEXT i
>>> ENDIF
>>>
>>> for i = 1 to len(aTitles)
>>> if Upper(Substr(aTitles[i,1],1,12)) = 'ADOBE READER'
>>> nhwnd := aTitles[i,2]
>>> nwMsg := 16
>>> nwParam := 0
>>> nlParam := 0
>>> PostMessageA( nhwnd, nwMsg, nwParam, nlParam)
>>> ok := lAll
>>> nwMsg := 18
>>> PostMessageA( nhwnd, nwMsg, nwParam, nlParam)
>>> ok := lAll
>>> sleep(10)
>>> endif
>>> next
>>> enddo
>>>
>>> RETURN(.t.)
>>>
>>> ******************************************************
>>>
>>>
>>> Em 16/03/2011 11:39, Rudolf Reinthaler escreveu:
>>>> Hello,
>>>> I need to find a open window from another program to close it. I know
>>>> only a part of the name of the window title. With the attached function
>>>> I always get 0 in hWnd. Is there another function then FindWindowA ?
>>>> regards
>>>> Rudolf
>>>>
>>>>
>>>> function KillProcessFromWindow( cText )
>>>> ******************************************************************
>>>> local result := .F.
>>>> local pid := 0
>>>> local hProc
>>>> local hWnd := DllCall("user32.dll", DLL_STDCALL, "FindWindowA",0,cText)
>>>> if hWnd > 0
>>>> @user32:GetWindowThreadProcessId(hWnd,@pid)
>>>> hProc := @kernel32:OpenProcess(0x411,.F.,pid)
>>>> if( !Empty(hProc) )
>>>> result := ( @kernel32:TerminateProcess(hProc) != 0 )
>>>> @kernel32:CloseHandle(hProc)
>>>> end
>>>> endif
>>>> return result
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>
>
Edgar Borger Re: wildcard find and close window
on Wed, 16 Mar 2011 15:32:00 -0300
Hi Rudolf,

attached is the whole program, it is alaska sample of acrobat activex, 
with the change on the end (quit) routine, to properly kill the acrobat 
window....

It works for me, compiled with 1.90.355

aTitles should have an array of open windows returned from EnumWindow 
routine ....

Em 16/03/2011 13:57, Rudolf Reinthaler escreveu:
> Hello Edgar,
> I have made the function this way:
> function PostMessageA(nhwnd,nwMsg,nwParam,nlParam)
> return DllCall("User32.DLL", DLL_STDCALL,"PostMessageA",
> nhwnd,nwMsg,nwParam,nlParam)
>
>
> but the code cannot work, what happens with aTitles and cTitles ?
> regards
> Rudolf
>
>
>
> Am 16.03.2011 17:46, schrieb Edgar Borger:
>> Rudolf,
>> it is there, just remove the asterisk. "*" .....
>>
>> DLLFUNCTION PostMessageA(nhwnd, nwMsg, nwParam, nlParam) USING STDCALL
>> FROM USER32.DLL
>>
>>
>>
>>
>> Em 16/03/2011 13:36, Rudolf Reinthaler escreveu:
>>> Hello Edgar,
>>> looks interesting,could you please send me the PostmessageA function ? I
>>> would also like to send keystrokes to the other window (page up and down
>>> in a Acrobat window)
>>> regards
>>> Rudolf
>>>
>>> Am 16.03.2011 16:33, schrieb Edgar Borger:
>>>> Hello Rudolf,
>>>>
>>>> I don't know if this helps, but I got this function from somewhere a
>>>> long time ago, I can't ever remember from where.....
>>>>
>>>> It is suppose to end and Adobe Reader window....
>>>>
>>>> ********************************************************************************
>>>>
>>>>
>>>>
>>>>
>>>> * Function AllWindows(lShow) -> aTitles { nHandle, cTitle }
>>>> * Gets the handles & titles of all top level windows.
>>>> ********************************************************************************
>>>>
>>>>
>>>>
>>>>
>>>> * If lShow == .T. Display Titles in a Message Box and return the array
>>>> aTitles.
>>>> * If lShow == .F. Just return the array aTitles.
>>>> ********************************************************************************
>>>>
>>>>
>>>>
>>>>
>>>> DLLFUNCTION EnumWindows( cProc, nPara ) USING STDCALL FROM USER32.DLL
>>>> DLLFUNCTION EnumChildWindows( hWndParent, lpEnumFunc, lParam ) USING
>>>> STDCALL FROM USER32.DLL
>>>> DLLFUNCTION GetWindowTextA( nHandle, @cBuf, nSize ) USING STDCALL FROM
>>>> USER32.DLL
>>>> *PostMessage DllCall("User32.DLL", DLL_STDCALL,"PostMessageA",
>>>> nhwnd,nwMsg,nwParam,nlParam)
>>>>
>>>> FUNCTION KillAcro( lAll )
>>>> LOCAL i, ok := .t.
>>>> PRIVATE aTitles := {}, cTitles := ""
>>>> if lAll = NIL
>>>> lAll := .f.
>>>> endif
>>>>
>>>> do while ok
>>>> aTitles := {}
>>>> cTitles := ""
>>>> ok := .f.
>>>> EnumWindows(BaCallBack("EnumWindow",BA_CB_GENERIC2),0)
>>>> IF !empty(aTitles)
>>>> FOR i := 1 TO len(aTitles)
>>>> cTitles := cTitles+;
>>>> padl(str(aTitles[i,2],10,0),10)+;
>>>> chr(9)+;
>>>> iif(aTitles[i,2]<100000,chr(9),"")+;
>>>> aTitles[i,1]
>>>> IF i<len(aTitles)
>>>> cTitles := cTitles+chr(13)
>>>> ENDIF
>>>> NEXT i
>>>> ENDIF
>>>>
>>>> for i = 1 to len(aTitles)
>>>> if Upper(Substr(aTitles[i,1],1,12)) = 'ADOBE READER'
>>>> nhwnd := aTitles[i,2]
>>>> nwMsg := 16
>>>> nwParam := 0
>>>> nlParam := 0
>>>> PostMessageA( nhwnd, nwMsg, nwParam, nlParam)
>>>> ok := lAll
>>>> nwMsg := 18
>>>> PostMessageA( nhwnd, nwMsg, nwParam, nlParam)
>>>> ok := lAll
>>>> sleep(10)
>>>> endif
>>>> next
>>>> enddo
>>>>
>>>> RETURN(.t.)
>>>>
>>>> ******************************************************
>>>>
>>>>
>>>> Em 16/03/2011 11:39, Rudolf Reinthaler escreveu:
>>>>> Hello,
>>>>> I need to find a open window from another program to close it. I know
>>>>> only a part of the name of the window title. With the attached
>>>>> function
>>>>> I always get 0 in hWnd. Is there another function then FindWindowA ?
>>>>> regards
>>>>> Rudolf
>>>>>
>>>>>
>>>>> function KillProcessFromWindow( cText )
>>>>> ******************************************************************
>>>>> local result := .F.
>>>>> local pid := 0
>>>>> local hProc
>>>>> local hWnd := DllCall("user32.dll", DLL_STDCALL,
>>>>> "FindWindowA",0,cText)
>>>>> if hWnd > 0
>>>>> @user32:GetWindowThreadProcessId(hWnd,@pid)
>>>>> hProc := @kernel32:OpenProcess(0x411,.F.,pid)
>>>>> if( !Empty(hProc) )
>>>>> result := ( @kernel32:TerminateProcess(hProc) != 0 )
>>>>> @kernel32:CloseHandle(hProc)
>>>>> end
>>>>> endif
>>>>> return result
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>


MAIN.PRG
Rudolf ReinthalerRe: wildcard find and close window
on Thu, 17 Mar 2011 06:35:37 +0100
Hello Edgar,
thank you !
regards
Rudolf

Am 16.03.2011 19:32, schrieb Edgar Borger:
> Hi Rudolf,
>
> attached is the whole program, it is alaska sample of acrobat activex,
> with the change on the end (quit) routine, to properly kill the acrobat
> window....
>
> It works for me, compiled with 1.90.355
>
> aTitles should have an array of open windows returned from EnumWindow
> routine ....
>
> Em 16/03/2011 13:57, Rudolf Reinthaler escreveu:
>> Hello Edgar,
>> I have made the function this way:
>> function PostMessageA(nhwnd,nwMsg,nwParam,nlParam)
>> return DllCall("User32.DLL", DLL_STDCALL,"PostMessageA",
>> nhwnd,nwMsg,nwParam,nlParam)
>>
>>
>> but the code cannot work, what happens with aTitles and cTitles ?
>> regards
>> Rudolf
>>
>>
>>
>> Am 16.03.2011 17:46, schrieb Edgar Borger:
>>> Rudolf,
>>> it is there, just remove the asterisk. "*" .....
>>>
>>> DLLFUNCTION PostMessageA(nhwnd, nwMsg, nwParam, nlParam) USING STDCALL
>>> FROM USER32.DLL
>>>
>>>
>>>
>>>
>>> Em 16/03/2011 13:36, Rudolf Reinthaler escreveu:
>>>> Hello Edgar,
>>>> looks interesting,could you please send me the PostmessageA function
>>>> ? I
>>>> would also like to send keystrokes to the other window (page up and
>>>> down
>>>> in a Acrobat window)
>>>> regards
>>>> Rudolf
>>>>
>>>> Am 16.03.2011 16:33, schrieb Edgar Borger:
>>>>> Hello Rudolf,
>>>>>
>>>>> I don't know if this helps, but I got this function from somewhere a
>>>>> long time ago, I can't ever remember from where.....
>>>>>
>>>>> It is suppose to end and Adobe Reader window....
>>>>>
>>>>> ********************************************************************************
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> * Function AllWindows(lShow) -> aTitles { nHandle, cTitle }
>>>>> * Gets the handles & titles of all top level windows.
>>>>> ********************************************************************************
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> * If lShow == .T. Display Titles in a Message Box and return the array
>>>>> aTitles.
>>>>> * If lShow == .F. Just return the array aTitles.
>>>>> ********************************************************************************
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> DLLFUNCTION EnumWindows( cProc, nPara ) USING STDCALL FROM USER32.DLL
>>>>> DLLFUNCTION EnumChildWindows( hWndParent, lpEnumFunc, lParam ) USING
>>>>> STDCALL FROM USER32.DLL
>>>>> DLLFUNCTION GetWindowTextA( nHandle, @cBuf, nSize ) USING STDCALL FROM
>>>>> USER32.DLL
>>>>> *PostMessage DllCall("User32.DLL", DLL_STDCALL,"PostMessageA",
>>>>> nhwnd,nwMsg,nwParam,nlParam)
>>>>>
>>>>> FUNCTION KillAcro( lAll )
>>>>> LOCAL i, ok := .t.
>>>>> PRIVATE aTitles := {}, cTitles := ""
>>>>> if lAll = NIL
>>>>> lAll := .f.
>>>>> endif
>>>>>
>>>>> do while ok
>>>>> aTitles := {}
>>>>> cTitles := ""
>>>>> ok := .f.
>>>>> EnumWindows(BaCallBack("EnumWindow",BA_CB_GENERIC2),0)
>>>>> IF !empty(aTitles)
>>>>> FOR i := 1 TO len(aTitles)
>>>>> cTitles := cTitles+;
>>>>> padl(str(aTitles[i,2],10,0),10)+;
>>>>> chr(9)+;
>>>>> iif(aTitles[i,2]<100000,chr(9),"")+;
>>>>> aTitles[i,1]
>>>>> IF i<len(aTitles)
>>>>> cTitles := cTitles+chr(13)
>>>>> ENDIF
>>>>> NEXT i
>>>>> ENDIF
>>>>>
>>>>> for i = 1 to len(aTitles)
>>>>> if Upper(Substr(aTitles[i,1],1,12)) = 'ADOBE READER'
>>>>> nhwnd := aTitles[i,2]
>>>>> nwMsg := 16
>>>>> nwParam := 0
>>>>> nlParam := 0
>>>>> PostMessageA( nhwnd, nwMsg, nwParam, nlParam)
>>>>> ok := lAll
>>>>> nwMsg := 18
>>>>> PostMessageA( nhwnd, nwMsg, nwParam, nlParam)
>>>>> ok := lAll
>>>>> sleep(10)
>>>>> endif
>>>>> next
>>>>> enddo
>>>>>
>>>>> RETURN(.t.)
>>>>>
>>>>> ******************************************************
>>>>>
>>>>>
>>>>> Em 16/03/2011 11:39, Rudolf Reinthaler escreveu:
>>>>>> Hello,
>>>>>> I need to find a open window from another program to close it. I know
>>>>>> only a part of the name of the window title. With the attached
>>>>>> function
>>>>>> I always get 0 in hWnd. Is there another function then FindWindowA ?
>>>>>> regards
>>>>>> Rudolf
>>>>>>
>>>>>>
>>>>>> function KillProcessFromWindow( cText )
>>>>>> ******************************************************************
>>>>>> local result := .F.
>>>>>> local pid := 0
>>>>>> local hProc
>>>>>> local hWnd := DllCall("user32.dll", DLL_STDCALL,
>>>>>> "FindWindowA",0,cText)
>>>>>> if hWnd > 0
>>>>>> @user32:GetWindowThreadProcessId(hWnd,@pid)
>>>>>> hProc := @kernel32:OpenProcess(0x411,.F.,pid)
>>>>>> if( !Empty(hProc) )
>>>>>> result := ( @kernel32:TerminateProcess(hProc) != 0 )
>>>>>> @kernel32:CloseHandle(hProc)
>>>>>> end
>>>>>> endif
>>>>>> return result
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
AUGE_OHRRe: wildcard find and close window
on Thu, 17 Mar 2011 08:59:53 +0100
Pablo BotellaRe: wildcard find and close window
on Wed, 16 Mar 2011 17:11:04 +0100
Hi,

Sometime ago I was publish a WiliFindWindow() sample
http://news.xbwin.com/newsgroups.php?art_group=ot4xb.examples&article_id=5

I think it do just that you need. 
Regards,
Pablo Botella
Rudolf ReinthalerRe: wildcard find and close window
on Wed, 16 Mar 2011 17:37:02 +0100
Hello Pablo,
thank you, will take a look on it
regards
Rudolf

Am 16.03.2011 17:11, schrieb Pablo Botella:
> Hi,
>
> Sometime ago I was publish a WiliFindWindow() sample
> http://news.xbwin.com/newsgroups.php?art_group=ot4xb.examples&article_id=5
>
> I think it do just that you need.
> Regards,
> Pablo Botella
AUGE_OHRRe: wildcard find and close window
on Thu, 17 Mar 2011 08:50:13 +0100
hi,

> local hWnd := DllCall("user32.dll", DLL_STDCALL, "FindWindowA",0,cText)

"FindWindowA" need "excat" Title Name, so you have to use $ for Wildcat.

this Method does "scan" Tasklist with $ as Wildcat

greetings by OHR
Jimmy

*** Code ***
Look4Window(cTitle,dDate,cTime)
LOCAL nHwnd, cWind
LOCAL oThread
LOCAL nEvent, mp1, mp2
LOCAL oDlg
LOCAL aTasklist
LOCAL aSize     := { 0, 0 }
LOCAL aPos      := { 0, 0 }
LOCAL lRunnin   := .F.
LOCAL i         := 0

IF PCOUNT() > 0

   oDlg := XbpDialog() :new( AppDesktop(),, aPos, aSize,, .F. )
   oDlg:clipSiblings := .T.
   oDlg:drawingArea:ClipChildren := .T.
   oDlg:create()
   SETAPPFOCUS( oDlg )

   DO WHILE .T.
      lRunnin   := .F.
      aTasklist := GetTaskList( oDlg:gethWnd( ) )

      FOR i = 1 TO LEN( aTasklist )
         cWind  := TRIM( UPPER( SUBSTR( aTasklist[ i ], 9 ) ) )
         cWind  := SUBSTR( cWind, 1, LEN( cWind ) - 1 )
         nHwnd  := VAL( LEFT( aTasklist[ i ], 8 ) )
         
          search as Wildcat
         
         IF UPPER(cTitle) $ cWind
             run new Action in a Thread
            oThread := Thread():new()
            oThread:start( {|| ::Chk4Ref(nHwnd,cTitle,dDate,cTime) } )
            lRunnin := .T.
            EXIT
         ENDIF
      NEXT

      IF lRunnin = .T.
         EXIT
      ENDIF
      SLEEP(100)
   ENDDO

ENDIF

RETURN lRunnin
*** eof ***