Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Block Popups from Web Browser Control
Message
De
29/08/2006 17:55:23
 
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01149451
Message ID:
01149573
Vues:
12
>Thanks for the tip, but no luck.
>I tried setting m.cancel=.T. in both NewWindow2 and NewWindow3 and those events do not seem to fire when the popups are happening. Am I missing something?
>
>>try working with NewWindow3. perhaps a cancel = True


This may not be what you are actually looking for, but helps me.

Before you naviagate to the site, call this routine. Then afterwards, release the object from memory, and all the window openned while IE navigated to the site are closed.
local loWindows
loWindows = PopupWin()
...
loIE.Navigate("<url>")
...
release loWindow
Save this code to PopupWin.prg
* Program:     POPUPWIN.PRG
* Description: Unloads Popup windows
* Created:     08/29/2006
* Developer:   Gregory L Reichert - UT #046387
* Copyright:   Copyright (c) 2006
*------------------------------------------------------------
*------------------------------------------------------------
* Description:
* Parameters:  <para>, <req/opt>, D=<def>, <desc>
* Return:
* Use:
*------------------------------------------------------------
* Id Date        By         Description
*  1 08/29/2006  Gregory L Reichert Initial Creation
*
*------------------------------------------------------------
RETURN CREATEOBJECT("PopUpWindows")

DEFINE CLASS PopUpWindows AS CONTAINER

	DIMENSION aWindows[1,2]

	*------------------------------------------------------------
	* Description: Remember all currently open windows.
	* Parameters:  <para>, <req/opt>, D=<def>, <desc>
	* Return:
	* Use:
	*------------------------------------------------------------
	* Id Date        By         Description
	*  1 08/29/2006  Gregory L Reichert Initial Creation
	*
	*------------------------------------------------------------

	PROCEDURE INIT
		*------------------------------------------------------------
		* Description: build list of window hwnd
		* Parameters:  <para>, <req/opt>, D=<def>, <desc>
		* Return:
		* Use:
		*------------------------------------------------------------
		* Id Date        By         Description
		*  1 09/04/2003  Gregory L Reichert Initial Creation
		*  2 02/04/2004  GLR		dont clear DLL, may be needed in actual application.
		*------------------------------------------------------------
		LOCAL HWND, x,N, stuffer

		* Get the HWND (handle) to the main FoxPro window
		#IF VERSION(5)>=700
			HWND = _VFP.HWND
		#ELSE
			IF FILE(HOME()+"FoxTools.fll")
				SET LIBRARY TO (HOME()+"FoxTools.fll") ADDITIVE
				HWND = EVALUATE("MainHWND()")
				RELEASE LIBRARY (HOME()+"FoxTools.fll")
			ELSE
				RETURN .F.
			ENDIF
		#ENDIF

		* Register the Windows API functions that will be called
		DECLARE INTEGER GetWindowText IN WIN32API;
			INTEGER HWND, ;
			STRING @ lpString, ;
			INTEGER nMaxCount

		DECLARE INTEGER GetWindow IN user32;
			INTEGER HWND,;
			INTEGER wFlag

		N = 0
		DO WHILE HWND <> 0

			stuffer = REPLICATE(CHR(0),512)
			x = GetWindowText(HWND,@stuffer,511)
			stuffer = LEFTC(stuffer,AT_C(CHR(0),stuffer)-1)

			IF LEN(TRIM(stuffer)) > 0
				N = N + 1
				DIMENSION THIS.aWindows[ n, 2]
				THIS.aWindows[ n,1 ] = HWND
				THIS.aWindows[ n,2 ] = stuffer
			ENDIF

			HWND = GetWindow(HWND,2)

		ENDDO
		RETURN


	ENDPROC

	*------------------------------------------------------------
	* Description: closes window not previously openned
	* Parameters:  <para>, <req/opt>, D=<def>, <desc>
	* Return:      
	* Use:         
	*------------------------------------------------------------
	* Id Date        By         Description
	*  1 08/29/2006  Gregory L Reichert Initial Creation
	* 
	*------------------------------------------------------------
	PROCEDURE DESTROY

		LOCAL HWND, x,N, stuffer, lFound


		* Get the HWND (handle) to the main FoxPro window
		#IF VERSION(5)>=700
			HWND = _VFP.HWND
		#ELSE
			IF FILE(HOME()+"FoxTools.fll")
				SET LIBRARY TO (HOME()+"FoxTools.fll") ADDITIVE
				HWND = EVALUATE("MainHWND()")
				RELEASE LIBRARY (HOME()+"FoxTools.fll")
			ELSE
				THIS.lclosepopup = .F.
				RETURN
			ENDIF
		#ENDIF

		* Register the Windows API functions that will be called
		DECLARE INTEGER GetWindowText IN WIN32API;
			INTEGER HWND, ;
			STRING @ lpString, ;
			INTEGER nMaxCount

		DECLARE INTEGER GetWindow IN user32;
			INTEGER HWND,;
			INTEGER wFlag

		DECLARE SHORT PostMessage IN user32;
			INTEGER   HWND,;
			INTEGER   Msg,;
			STRING  @ wParam,;
			INTEGER   LPARAM

		DO WHILE HWND <> 0

			stuffer = REPLICATE(CHR(0),512)
			x = GetWindowText(HWND,@stuffer,511)
			stuffer = LEFTC(stuffer,AT_C(CHR(0),stuffer)-1)

			IF LENC(TRIM(stuffer)) > 0

				lFound = .F.
				FOR N=1 TO ALEN(THIS.aWindows,1)
					lFound = lFound OR (HWND==THIS.aWindows[n,1] ;
						AND stuffer==THIS.aWindows[ n,2 ] ;
						AND NOT LEFTC(stuffer,22)="Visual FoxPro Debugger")
					IF lFound
						EXIT
					ENDIF
				NEXT
				IF NOT lFound
					*-- popup window, close it.
					ACTIVATE SCREEN
					PostMessage(HWND, 0x10, 0, 0)
				ENDIF
			ENDIF

			HWND = GetWindow(HWND,2)

		ENDDO

		RETURN .T.
	ENDPROC

ENDDEFINE
P.S. I sent a copy of you LOCALS.prg to Bhavbhuti to help him a problem he was having today. I added code to have it see existing Private, Dimension, and Public statements.
Greg Reichert
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform