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

📄 addressbarex.cpp

📁 一个多窗口的浏览器的程序benbrowse
💻 CPP
字号:
// AddressBarEx.cpp : implementation file
//

#include "stdafx.h"
#include "benbenBrowser.h"
#include "AddressBarEx.h"

#include "generaldata.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


//#pragma optimize( "s", on)

/////////////////////////////////////////////////////////////////////////////
// CAddressBarEx

CAddressBarEx::CAddressBarEx()
{
	ShowGoButton =TRUE;
}

CAddressBarEx::~CAddressBarEx()
{
}


BEGIN_MESSAGE_MAP(CAddressBarEx, CToolBar)
	//{{AFX_MSG_MAP(CAddressBarEx)
	ON_WM_SIZE()
	ON_NOTIFY_REFLECT( TBN_GETINFOTIP, OnGetInfoTip )
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAddressBarEx message handlers

void CAddressBarEx::OnSize(UINT nType, int cx, int cy) 
{
	CToolBar::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	//===
	if(m_wndAddress)
		
	{
		CRect rect2,rect3,rect4;
		GetItemRect(1, rect2);
		GetItemRect(2,rect3);
		GetItemRect(3,rect4);
		int w;
		if(ShowGoButton)
			w= cx-rect2.Width()-rect3.Width()-rect4.Width()-2;
		else
			w = cx;
		
		SetButtonInfo(0, 0, TBBS_SEPARATOR, w);
		m_wndAddress.SetWindowPos(NULL,  0, 0, w, cy, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCOPYBITS);
		if(!m_wndAddress.IsWindowVisible())
			m_wndAddress.ShowWindow(SW_SHOW);
		//====
		
	}
}


CComboBoxEx* CAddressBarEx::GetAddressBox()
{
	return &m_wndAddress;
}

void CAddressBarEx::Init() 
{
	// TODO: Add your specialized creation code here
	// create a combo box for the address bar
	if (!m_wndAddress.Create(WS_VISIBLE|WS_CHILD|WS_VSCROLL|CBS_DROPDOWN, CRect(0, 0, 10, 120), this, AFX_IDW_TOOLBAR + 1))
	{
		TRACE0("Failed to create combobox\n");
		return ;      // fail to create
	}
	m_wndAddress.SetExtendedStyle(0, m_wndAddress.GetExtendedStyle()|CBES_EX_NOSIZELIMIT);


	CImageList img;
	HBITMAP hbmp = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP4));
	img.Create(16, 16, ILC_COLOR8|ILC_MASK, 7, 1);
	ImageList_AddMasked(img.GetSafeHandle(), hbmp, RGB(255,0,255));
	m_wndAddress.SetImageList(&img);
	img.Detach();

	BOOL success = m_dropTarget.Register(&m_wndAddress);
    if(!success )
      MessageBox("Ole Register Drop Target Failed");   
	return;
}

void CAddressBarEx::GetSelText(int index, CString & str)
{
	if(index<0)
		return;

	try{

	static TCHAR           sz[MAX_PATH];
	COMBOBOXEXITEM item;
	item.mask = CBEIF_TEXT;
	item.pszText = (LPTSTR)sz;
	item.cchTextMax = MAX_PATH;

	item.iItem = index;
	m_wndAddress.GetItem(&item);
	str = sz;
	}catch(...)
	{
	}
}

int CAddressBarEx::FindStringExact(int start, CString & str)
{
	//try to add static
	static TCHAR           sz[MAX_PATH];

	try{
	COMBOBOXEXITEM item;
	item.mask = CBEIF_TEXT;
	item.pszText = (LPTSTR)sz;
	item.cchTextMax = MAX_PATH;

	int nc = m_wndAddress.SendMessage(CB_GETCOUNT, 0, 0);
	for(register int i=start+1;i<nc;i++)
	{
		item.iItem = i;
		m_wndAddress.GetItem(&item);
		if(str.CompareNoCase(sz)==0)
			return i;
	}
	}catch(...)
	{
	}

	return CB_ERR;
}

void CAddressBarEx::OnGetInfoTip( NMHDR* pNMHDR, LRESULT* pResult )
{
	//  16/08/2002 benben start
    NMTBGETINFOTIP* lptbgit = ( NMTBGETINFOTIP* )pNMHDR;
    CString strTip;
	CString strFull,strNew;
    if(strFull.LoadString( lptbgit->iItem ) )
	{
		GetText(strFull,strNew,menuhint_item_text);
		( AfxExtractSubString( strTip, strNew, 1, _T('|') ) );	
	    _tcsncpy( lptbgit->pszText, strTip, lptbgit->cchTextMax );
	}

    *pResult = 0;
	//benben end
}

⌨️ 快捷键说明

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