Click here to Skip to main content
15,917,565 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generallink error,why Pin
littlelv8-Jul-03 16:58
littlelv8-Jul-03 16:58 
GeneralRe: link error,why Pin
littlelv10-Jul-03 22:59
littlelv10-Jul-03 22:59 
GeneralNatural Language Processing open source.. Pin
JoeSox8-Jul-03 14:00
JoeSox8-Jul-03 14:00 
GeneralProgrammatically starting IE in "a new window" Pin
Iain Clarke, Warrior Programmer8-Jul-03 11:35
Iain Clarke, Warrior Programmer8-Jul-03 11:35 
GeneralRe: Programmatically starting IE in "a new window" Pin
Michael Dunn8-Jul-03 11:56
sitebuilderMichael Dunn8-Jul-03 11:56 
GeneralRe: Programmatically starting IE in "a new window" Pin
Iain Clarke, Warrior Programmer8-Jul-03 12:22
Iain Clarke, Warrior Programmer8-Jul-03 12:22 
GeneralRe: Programmatically starting IE in "a new window" Pin
Michael Dunn8-Jul-03 15:32
sitebuilderMichael Dunn8-Jul-03 15:32 
GeneralRe: Programmatically starting IE in "a new window" Pin
Rob Caldecott8-Jul-03 12:28
Rob Caldecott8-Jul-03 12:28 
You need to fetch the browser EXE from the registry and use this when calling ShellExecute thus:

#define	LINK_KEY	_T("http\\shell\\open\\command")

void CLink::Open(LPCTSTR lpszURL)
{
	// Simply execute the URL
	ShellExecute(NULL, NULL, lpszURL, NULL, NULL, SW_SHOWNORMAL);
}

void CLink::OpenNew(LPCTSTR lpszURL)
{
	// Get the browser
	CString strBrowser = GetBrowser();
	// Success?
	if (strBrowser.IsEmpty())
	{
		Open(lpszURL);
		return;
	}
	// Execute
	ShellExecute(NULL, NULL, strBrowser, lpszURL, NULL, SW_SHOWNORMAL);
	// Done
}

CString CLink::GetBrowser() const
{
	// The full path of the browser
	CString str;
	// Get the default browser from HKCR\http\shell\open\command
	HKEY hKey = NULL;
	// Open the registry
	if (RegOpenKeyEx(HKEY_CLASSES_ROOT, LINK_KEY, 0, KEY_READ, &hKey) ==
		ERROR_SUCCESS)
	{
		// Data size
		DWORD cbData = 0;
		// Get the default value
		if (RegQueryValueEx(hKey, NULL, NULL, NULL, NULL, &cbData) ==
			ERROR_SUCCESS)
		{
			// Check the buffer size
			if (cbData > 0)
			{
				// Allocate a suitable buffer
				TCHAR* psz = new TCHAR [cbData];
				// Success?
				if (psz != NULL)
				{
					if (RegQueryValueEx(hKey, NULL, NULL,
						NULL, (LPBYTE)psz, &cbData) ==
						ERROR_SUCCESS)
					{
						// Success
						str = psz;
					}
					// Delete the buffer
					delete [] psz;
				}
			}
		}
		// Close the registry
		RegCloseKey(hKey);
	}
	// Do we have the browser?
	if (str.GetLength())
	{
		// Strip the full path from the string
		int nStart = str.Find('"');
		int nEnd = str.ReverseFind('"');
		// Do we have either quote?
		// If so, then the path contains spaces
		if (nStart >= 0 && nEnd >= 0)
		{
			// Are they the same?
			if (nStart != nEnd)
			{			
				// Get the full path
				str = str.Mid(nStart + 1, nEnd - nStart - 1);
			}
		}
		else
		{
			// We may have a pathname with spaces but
			// no quotes (Netscape), e.g.:
			//   C:\PROGRAM FILES\NETSCAPE\COMMUNICATOR\PROGRAM\NETSCAPE.EXE -h "%1"
			// Look for the last backslash
			int nIndex = str.ReverseFind('\\');
			// Success?
			if (nIndex > 0)
			{
				// Look for the next space after the final
				// backslash
				int nSpace = str.Find(' ', nIndex);
				// Do we have a space?
				if (nSpace > 0)
					str = str.Left(nSpace);				
			}
		}
	}
	// Done
	return str;
}



When I am king, you will be first against the wall.
GeneralRe: Programmatically starting IE in "a new window" Pin
Iain Clarke, Warrior Programmer8-Jul-03 12:48
Iain Clarke, Warrior Programmer8-Jul-03 12:48 
GeneralRe: Programmatically starting IE in "a new window" Pin
Ryan Binns8-Jul-03 16:54
Ryan Binns8-Jul-03 16:54 
GeneralRe: Programmatically starting IE in "a new window" Pin
Rob Caldecott8-Jul-03 21:22
Rob Caldecott8-Jul-03 21:22 
GeneralRe: Programmatically starting IE in "a new window" Pin
Ryan Binns8-Jul-03 21:24
Ryan Binns8-Jul-03 21:24 
GeneralLZW Data Pin
keb8-Jul-03 11:29
keb8-Jul-03 11:29 
GeneralLinking problem Pin
Navin8-Jul-03 10:55
Navin8-Jul-03 10:55 
GeneralRe: Linking problem Pin
Dave Bryant8-Jul-03 11:00
Dave Bryant8-Jul-03 11:00 
GeneralRe: Linking problem Pin
Navin8-Jul-03 11:54
Navin8-Jul-03 11:54 
GeneralModal Dailog Box Pin
ppathan8-Jul-03 9:57
ppathan8-Jul-03 9:57 
GeneralRe: Modal Dailog Box Pin
valikac8-Jul-03 10:10
valikac8-Jul-03 10:10 
GeneralRe: Modal Dailog Box Pin
ppathan8-Jul-03 10:21
ppathan8-Jul-03 10:21 
GeneralRe: Modal Dailog Box Pin
Dave Bryant8-Jul-03 10:38
Dave Bryant8-Jul-03 10:38 
GeneralRe: Modal Dailog Box Pin
ppathan8-Jul-03 10:45
ppathan8-Jul-03 10:45 
GeneralRe: Modal Dailog Box Pin
Dave Bryant8-Jul-03 10:56
Dave Bryant8-Jul-03 10:56 
GeneralRe: Modal Dailog Box Pin
Ravi Bhavnani8-Jul-03 11:01
professionalRavi Bhavnani8-Jul-03 11:01 
GeneralRe: Modal Dailog Box Pin
ppathan8-Jul-03 11:08
ppathan8-Jul-03 11:08 
GeneralRe: Modal Dailog Box Pin
Ravi Bhavnani8-Jul-03 11:14
professionalRavi Bhavnani8-Jul-03 11:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.