发信人: he_jm() 
整理人: wenbobo(2002-12-27 16:00:21), 站内信件
 | 
 
 
【 在 jsbyl (hnbadboy) 的大作中提到: 】
 : 在c++build中有没有办法自动判断ie浏览器的弹出窗口,并把它关闭,
 : 最好提供一点源程序,
 : 谢谢各位大侠了!!!
 这儿有一段VC关闭IE广告窗口的源代码,不知对你有没有帮助
 / close ieDlg.cpp : implementation file
 //
 
 #include "stdafx.h"
 #include "close ie.h"
 #include "close ieDlg.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
 #undef THIS_FILE
 static char THIS_FILE[] = __FILE__;
 #endif
 
 ////////////////////////////////////////////////////////////////////// ///////
 // CCloseieDlg dialog
 
 CCloseieDlg::CCloseieDlg(CWnd* pParent /*=NULL*/)
 	: CDialog(CCloseieDlg::IDD, pParent)
 {
 	//{{AFX_DATA_INIT(CCloseieDlg)
 		// NOTE: the ClassWizard will add member initialization here
 	//}}AFX_DATA_INIT
 	// Note that LoadIcon does not require a subsequent DestroyIcon in Wi n32
 	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
 }
 
 void CCloseieDlg::DoDataExchange(CDataExchange* pDX)
 {
 	CDialog::DoDataExchange(pDX);
 	//{{AFX_DATA_MAP(CCloseieDlg)
 		// NOTE: the ClassWizard will add DDX and DDV calls here
 	//}}AFX_DATA_MAP
 }
 
 BEGIN_MESSAGE_MAP(CCloseieDlg, CDialog)
 	//{{AFX_MSG_MAP(CCloseieDlg)
 	ON_WM_PAINT()
 	ON_WM_QUERYDRAGICON()
 	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
 	ON_WM_TIMER()
 	//}}AFX_MSG_MAP
 END_MESSAGE_MAP()
 
 ////////////////////////////////////////////////////////////////////// ///////
 // CCloseieDlg message handlers
 
 BOOL CCloseieDlg::OnInitDialog()
 {
 	CDialog::OnInitDialog();
 
 	// Set the icon for this dialog.  The framework does this automatical ly
 	//  when the application's main window is not a dialog
 	SetIcon(m_hIcon, TRUE);			// Set big icon
 	SetIcon(m_hIcon, FALSE);		// Set small icon
 	
 	// TODO: Add extra initialization here
 	
 	return TRUE;  // return TRUE  unless you set the focus to a control
 }
 
 // If you add a minimize button to your dialog, you will need the code  below
 //  to draw the icon.  For MFC applications using the document/view mo del,
 //  this is automatically done for you by the framework.
 
 void CCloseieDlg::OnPaint() 
 {
 	if (IsIconic())
 	{
 		CPaintDC dc(this); // device context for painting
 
 		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
 
 		// Center icon in client rectangle
 		int cxIcon = GetSystemMetrics(SM_CXICON);
 		int cyIcon = GetSystemMetrics(SM_CYICON);
 		CRect rect;
 		GetClientRect(&rect);
 		int x = (rect.Width() - cxIcon + 1) / 2;
 		int y = (rect.Height() - cyIcon + 1) / 2;
 
 		// Draw the icon
 		dc.DrawIcon(x, y, m_hIcon);
 	}
 	else
 	{
 		CDialog::OnPaint();
 	}
 }
 
 // The system calls this to obtain the cursor to display while the use r drags
 //  the minimized window.
 HCURSOR CCloseieDlg::OnQueryDragIcon()
 {
 	return (HCURSOR) m_hIcon;
 }
 
 void CCloseieDlg::OnButton1() 
 {
 	SetTimer(1,400,NULL);
 	
 }
 
 void CCloseieDlg::OnTimer(UINT nIDEvent) 
 {
 	if(nIDEvent==1)
 	{
 		CWnd* pMainWnd = AfxGetMainWnd()->GetWindow(GW_HWNDFIRST);
 		while (pMainWnd)
 		{
 			CString strClassName;
 			GetClassName(pMainWnd->m_hWnd,strClassName.GetBufferSetLength(100), 100);
 			if(strClassName=="IEFrame")
 			{
 				CWnd* pChildWnd=CWnd::FromHandle(FindWindowEx(pMainWnd->m_hWnd,NUL L,
 					"Worker",NULL));
 				if(!pChildWnd)
 					pChildWnd=CWnd::FromHandle(FindWindowEx(pMainWnd->m_hWnd,NULL,
 					"WorkerA",NULL));
 				if(pChildWnd)
 				{
 					CWnd* pChildNextWnd=CWnd::FromHandle(FindWindowEx(pMainWnd->m_hWn d,pChildWnd->m_hWnd,
 						"Worker",NULL));
 					if(!pChildNextWnd)
 						pChildNextWnd=CWnd::FromHandle(FindWindowEx(pMainWnd->m_hWnd,pCh ildWnd->m_hWnd,
 							"WorkerA",NULL));
 					if(pChildNextWnd)
 					{
 						if(!(GetWindowLong(pChildWnd->m_hWnd,GWL_STYLE)&WS_VISIBLE))
 						{
 							pTempWnd=NULL;
 							pTempWnd=pMainWnd;
 							KillTimer(1);
 							SetTimer(2,800,NULL);
 							return;
 						}
 					}
 				}
 			}
 			pMainWnd = pMainWnd->GetWindow(GW_HWNDNEXT);
 		}
 	}
 	else
 	{
 		pTempWnd->PostMessage(WM_CLOSE,0,0);
 		KillTimer(2);
 		SetTimer(1,400,NULL);
 	}	
 	CDialog::OnTimer(nIDEvent);
 }
 
 
  -- ※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 61.130.224.84]
  | 
 
 
 |