⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addfavoritesdlg.cpp

📁 wince IE浏览器的源码
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
#include "Precomp.h"

#if !defined(NO_FAVORITES)
#include "resource.h"
#include "mainwnd.h"
#include "AddFavoritesDlg.h"
#include "FavInUseDlg.h"
#include "FavFolders.h"
#include "debug.h"
#include "regkeys.h"
#include "defines.h"


BOOL CAddFavoritesDlg::Startup(CMainWnd* pMainWnd, TCHAR* pszTitle, HMENU hFavMenu)
{
	m_wndMainWnd = pMainWnd;			// Main window object pointer
	m_hFavMenu = hFavMenu;				// Favorites menu handle
	m_pszTitle = pszTitle;				// Web page title (default for favorite)
	m_bRegistryChanged = TRUE;			
	
	INIT_STR (m_szPath);

	if (!m_wndMainWnd->_pIFavStorage)
		return FALSE;

	return TRUE;
}

CAddFavoritesDlg::~CAddFavoritesDlg()
{
	m_wndEdit.Detach();
	m_pszTitle = NULL;
	m_wndMainWnd = NULL;
}

LRESULT CAddFavoritesDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CenterWindow (GetParent());
	m_wndEdit.Attach(GetDlgItem(IDC_ADD_FAV_EDIT));

	// if the page title is blank, use the URL instead
	if ( _tcscmp(m_pszTitle, _T("")) == 0 )
	{
		BSTR bstrVal = NULL;
		m_wndMainWnd->_pBrowser->get_LocationURL(&bstrVal);
		_tcsncpy(m_pszTitle, (TCHAR*)bstrVal, FAV_NAME_LEN-1);
		SysFreeString(bstrVal);
	}

	// put the browser page's title in the edit box and hilite it
	m_wndEdit.SetWindowText(m_pszTitle);
	m_wndEdit.SendMessage(EM_LIMITTEXT, FAV_NAME_LEN-1, 0);
	m_wndEdit.SendMessage(EM_SETSEL, 0, -1);
	m_wndEdit.SetFocus();

	return 0;
}

BOOL CAddFavoritesDlg::StoreFavorite(TCHAR* pszFavorite, TCHAR* pszUrl)
{
	LRESULT lResult;
	lResult = m_wndMainWnd->_pIFavStorage->CreateFavorite ((!m_szPath[0])?NULL:m_szPath,
												  	        pszFavorite,
															pszUrl);
	if (lResult != ERROR_SUCCESS)
	{
		if (lResult != ERR_DUPLICATE_ENTRY)
		{
			TCHAR szBfr[512];
			INIT_STR (szBfr);

			if (0 != LoadString(g_hInstance, IDS_ERR_FAV_STORE, szBfr, 512))
				MessageBox(szBfr, NULL, MB_OK|MB_ICONERROR);
		}
		return FALSE;
	}

	return TRUE;
}

BOOL CAddFavoritesDlg::InsertFavoriteIntoMenu(TCHAR* pszFavorite)
{
	MENUITEMINFO oMenuInfo;
	oMenuInfo.fMask = MIIM_TYPE;
	oMenuInfo.fType = MFT_STRING;
	oMenuInfo.dwTypeData = (TCHAR *)LocalAlloc(LPTR, (FAV_NAME_LEN-1) * sizeof(TCHAR));
	oMenuInfo.cbSize = sizeof(oMenuInfo);

	if (oMenuInfo.dwTypeData == NULL)
		return FALSE;
	
	// traverse the menu to determine where to put the new favorite - must start at position 3
	for (UINT nPos=FIRST_FAV_MENU_ITEM_POS; nPos < m_wndMainWnd->_nNumFavorites+FIRST_FAV_MENU_ITEM_POS; nPos++)
	{
		oMenuInfo.cch = (FAV_NAME_LEN-1) * sizeof(TCHAR);
		GetMenuItemInfo(m_hFavMenu, nPos, TRUE, &oMenuInfo);
		if (_tcsicmp(oMenuInfo.dwTypeData, pszFavorite) > 0)
			break;
	} 

	InsertMenu(m_hFavMenu, nPos, MF_BYPOSITION, 
				++m_wndMainWnd->_nLastFavoriteID,  // use the next available ID
			   reinterpret_cast<TCHAR *>(pszFavorite));

	LocalFree(oMenuInfo.dwTypeData);

	return TRUE;
}

LRESULT CAddFavoritesDlg::OnOk (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
{
	TCHAR *szFavorite = NULL;
	TCHAR *szUrl = NULL;
	BSTR bstrVal = NULL;
       LONG lret = 0;
       
	// get current URL from browser control
        
       szUrl = new TCHAR[MAX_URL]; 
	szFavorite = new TCHAR[FAV_NAME_LEN];
       if(!szUrl || !szFavorite)
          goto Exit;
	
	INIT_STR (szFavorite);
	INIT_STR (szUrl);
	m_wndMainWnd->_pBrowser->get_LocationURL(&bstrVal);
	StringCchCopy(szUrl, MAX_URL-1, (TCHAR*)bstrVal);
	SysFreeString(bstrVal);

	// use the favorite name from the edit control
	m_wndEdit.SendMessage(EM_SETSEL, -1, -1); // deselect text
	m_wndEdit.GetWindowText(szFavorite, FAV_NAME_LEN - 1);

	if (m_wndMainWnd->_pIFavStorage->IsDuplicateFavorite (m_szPath,
														   szFavorite))
	{
		CFavInUseDlg dlg;
		dlg.Startup();
		m_wndEdit.SendMessage(EM_SETSEL, 0, -1);
		m_wndEdit.SetFocus();
		goto Exit;
	} // if

	if (StoreFavorite(szFavorite, szUrl))
	{
		// if we added our first favorite (numfavorites still 0), add the separator
		if (m_wndMainWnd->_nNumFavorites == 0)
			AppendMenu(m_hFavMenu, MF_SEPARATOR, 0, 0);

		//InsertFavoriteIntoMenu(szFavorite);
		m_wndMainWnd->_nNumFavorites++;
	}
	else
		goto Exit;

    lret = 1;
    EndDialog (IDOK);
Exit:
	delete[] szUrl;
	delete[] szFavorite;
	return lret;
}

LRESULT CAddFavoritesDlg::OnCancel (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
{
	EndDialog (0);
	m_bRegistryChanged = FALSE;
	return 1;
}

LRESULT CAddFavoritesDlg::OnSelectFolder (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	CFavFoldersDlg dlg (this,IDS_SELFAVFOLDER_TITLE,IDS_SELFAVFOLDER_MESSAGE);
	LPWSTR szDest = NULL;

	dlg.DoModal();
	szDest = dlg.GetDestinationFolder();
	if (NULL != szDest)
		wcscpy (m_szPath,szDest);
	return 1;
}

BOOL CAddFavoritesDlg::IsRegistryChanged ()
{
	return m_bRegistryChanged;
}

#endif // ndef NO_FAVORITES

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -