Click here to Skip to main content
11,484,640 members (57,247 online)
Click here to Skip to main content
Add your own
alternative version

LintProject - Improving the Usability of PC-Lint with Visual C++ Solutions and Projects

, , 29 Jan 2009 CPOL 179.6K 1.5K 52
Utility to run PC-Lint on Visual C++ solutions and projects, generating XML and HTML reports of the results.
/************************************************************************
 *
 *  Description : Browser related utility functions.
 *
 *     (c) Copyright 2004-2008 by Anna-Jayne Metcalfe (anna@riverblade.co.uk)
 *     and Beth Mackenzie (beth@riverblade.co.uk) / Riverblade Limited
 *
 *  Licence Terms:
 *
 *     This code may be freely reused, subject to the licence terms below.
 *     Please do let us know of any bugs you find or improvements you make,
 *     so that we can pass them on to the rest of the development community.
 *
 *     This code is free software; you can redistribute it and/or
 *     modify it under the terms of the Code Project Open License (CPOL)
 *     version 1.0 (http://www.codeproject.com/info/cpol10.aspx).
 *
 *     This code is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     Code Project Open Licence for further details.
 *
 ************************************************************************
 *    $Archive: /Projects/Applications/LintProject/Development/Shared/BrowserUtils.cpp $
 *   $Revision: 6 $
 *       $Date: 22/02/08 13:02 $
 *     $Author: Anna $
 * 
 * $Nokeywords: $
 ************************************************************************/

 /// \file	
 /// \brief Browser related utility functions implementation.

#include "StdAfx.h"

#ifndef __ATLSYNC_H__
	#pragma message(__FILE__" : For faster compilation, #include <atlsync.h> in stdafx.h")
	#include <atlsync.h>
#endif


//C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\comdef.h(250) : warning C4995: 'wsprintf': name was marked as #pragma deprecated
#pragma warning(push)
#pragma warning(disable: 4995)
	#include <comdef.h>
#pragma warning(pop)

#include <wininet.h>

#import <shdocvw.dll> named_guids rename("FindText", "ShDocVwFindText")

#pragma comment(lib, "shlwapi.lib")
#pragma comment(lib, "wininet.lib")

#include "BrowserUtils.h"



namespace Riverblade
{
	namespace Libraries
	{

		/// Refresh all WebBrowser controls displaying the file with the given pathname
		///
		/// Note that this technique currently works for Internet Explorer and derived browsers only
		///
		bool Utils::RefreshAllOpenBrowserWindows(const CString& sFullPathName)
		{
			//LOG_METHOD();

			static CCriticalSection cs;
			cs.Enter();

			if (sFullPathName.IsEmpty() )
			{
				cs.Leave();

				return false;
			}

			// Convert the pathname to a uniform URL ready for comparison with the URL in each control
			DWORD dwLen = _MAX_PATH;
			CString sCompareURL;

			if (!::InternetCanonicalizeUrl(sFullPathName, 
											sCompareURL.GetBufferSetLength(_MAX_PATH), 
											&dwLen,
											ICU_BROWSER_MODE) )
			{
				cs.Leave();

				return false;
			}
			(void)sCompareURL.Replace( _T("//"), _T("///") );
			(void)sCompareURL.Replace( _T('\\'), _T('/') );
			(void)sCompareURL.MakeLower();

			SHDocVw::IShellWindowsPtr shellws = NULL;

			bool bSuccess = true;

			try
			{
				// Connect to an instance of the shell
				HRESULT hr = shellws.CreateInstance(__uuidof(SHDocVw::ShellWindows));
				if (FAILED(hr) )
				{
					throw hr;
				}

				// Enumerate through current open windows (internet explorer and explorer)
				const long lCount = shellws->GetCount();

				for (long i = 0; i < lCount; i++)
				{
					// Get a current open shell window
					_variant_t vtIndex(i);
					IDispatchPtr ptrDispatch = shellws->Item(vtIndex);
					if (ptrDispatch == NULL)
					{
						continue;
					}

					// Retrieve an interface to the WebBrowser control
					//
					//lint -save -e929 (Note -- cast from pointer to pointer)
					SHDocVw::IWebBrowser2Ptr ptrWebBrowser = NULL;
					hr = ptrDispatch->QueryInterface(SHDocVw::IID_IWebBrowser2, (LPVOID*)&ptrWebBrowser);	//lint !e1924
					//lint -restore

					ptrDispatch.Release();

					if (ptrWebBrowser != NULL)
					{
						// Which URL is it displaying?
						CString sURL ( COLE2CT(ptrWebBrowser->GetLocationURL() ) );

						(void)sURL.MakeLower();

						// Compare the browser URL to the url needed to be refreshed
						if (sURL == sCompareURL)
						{
							// This WebBrowser control is displaying the file we're
							// interested in, so refresh it
							hr = ptrWebBrowser->Refresh();

							if (SUCCEEDED(hr))
							{
								ATLTRACE( _T("Browser displaying url %s refreshed correctly\n"), sURL);
							}
						}
						ptrWebBrowser.Release();
					}
				}
				// Clean-up
				if (NULL != shellws)
				{
					shellws.Release();
				}
			}
			catch(...)
			{
				// There's been a problem during the enumeration
				bSuccess = false;
			}

			cs.Leave();

			return bSuccess;
		}


	};	// namespace Libraries
};	// namespace Riverblade

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Authors

Anna-Jayne Metcalfe
Founder Riverblade Limited
United Kingdom United Kingdom
I haven't always written software for a living. When I graduated from Surrey University in 1989, it was with an Electronic Engineering degree, but unfortunately that never really gave me the opportunity to do anything particularly interesting (with the possible exception of designing Darth Vader's Codpiece * for the UK Army in 1990).
    * Also known as the Standard Army Bootswitch. But that's another story...
Since the opportunity arose to lead a software team developing C++ software for Avionic Test Systems in 1996, I've not looked back. More recently I've been involved in the development of subsea acoustic navigation systems, digital TV broadcast systems, port security/tracking systems, and most recently software development tools with my own company, Riverblade Ltd.

One of my personal specialities is IDE plug-in development. ResOrg was my first attempt at a plug-in, but my day to day work is with Visual Lint, an interactive code analysis tool environment with works within the Visual Studio and Eclipse IDEs or on build servers.

I love lots of things, but particularly music, photography and anything connected with history or engineering. I despise ignorant, intolerant and obstructive people - and it shows...I can be a bolshy cow if you wind me up the wrong way...Laugh | :laugh:

I'm currently based 15 minutes walk from the beach in Bournemouth on the south coast of England. Since I moved here I've grown to love the place - even if it is full of grockles in Summer!
Follow on   Twitter

-+- Beth Mackenzie -+-
Software Developer Riverblade Ltd
United Kingdom United Kingdom
I'm a software developer and/or tester with Riverblade Ltd (www.riverblade.co.uk) developing our core product range including our Visual Lint integration product and Lint Project Professional.

I incorporate a number of technologies into a daily basis including Windows API, C++ (VS2008), Managed C++, CLI, Databases, Java, JNI, Eclipse Framework, CDT and of course Visual Studio Extensibility (VSIP VSX).

In my spare time I enjoy cooking (prepping ingredients from scratch!), running, cycling, swimming, reading, interested in experimental electronic music (such as ClockDVA), movies, volunteering my IT skills where I can.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 29 Jan 2009
Article Copyright 2004 by Anna-Jayne Metcalfe, -+- Beth Mackenzie -+-
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid