Wednesday, January 05, 2005

 

Some notes on IE search

1.
Contrl the search bar of IE

1.1
让Google嵌入IE浏览器搜索栏

在浏览器的地址栏输入www.google.com/google.reg,按Enter,将Google.reg保存到桌面。然后双击桌面上的Google.reg,确认把该文件导入注册表。关闭IE中已打开的“搜索”窗格,然后再点击工具栏上的“搜索”按钮,可以看到现在搜索引擎已经变成了Google.

如果要恢复IE默认的搜索引擎,只要在浏览器地址栏输入www.google.com/default.reg,下载Default.reg,然后双击Default.reg将它导入注册表即可。

或者麻烦一点,手动

打开系统运行对话框,输入组策略编辑命令“gpedit.msc”,单击回车键,在随后的编辑界面中,依次展开“用户配置”“Windows设置”“InternetExp-lorer维护”节点,然后选中“URL”选项;在图3窗口的右边区域中,用鼠标双击“重要URL”选项,在随后出现的窗口中,选中“自定义搜索栏”选项,并在“搜索栏”文本框中输入Google的详细地址—httpwww.google.com,输入完毕后单击“确定”按钮,Google搜索引擎就会被“接纳”到IE浏览器窗口中了,以后只要你单击IE工具栏中的“搜索”命令,就能快速访问到Google搜索页面。

1.2

By 张硕(CathyEagle)
From http://blog.csdn.net/cathyeagle/archive/2004/09/29/120093.aspx

IE的搜索栏有默认的搜索页面“http://ie.search.msn.com/{SUB_RFC1766}/srchasst/srchasst.htm”,可以指定为自己的搜索页面。
打开注册表HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Search,找到“SearchAssistant”键,其默认值为“http://ie.search.msn.com/{SUB_RFC1766}/srchasst/srchasst.htm”,是显示在IE搜索面板中的页面Url,将其修改为自己需要的搜索页面Url,如“http://www.google.com”。
在HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Search下还有一个“CustomizeSearch”键,其默认值为“http://ie.search.msn.com/{SUB_RFC1766}/srchasst/srchcust.htm”(注意与SearchAssistant不同),当在IE搜索面板上点击“自定义”按钮时,将在弹出的Html对话框中显示该页面,同样可以修改为我们希望的Url。
如果你希望使用自定义的快捷搜索方式(像3721等那样只输入一个关键字就自动去到相应的网站),IE还提供了你自定义的机会。当IE无法确认用户在地址栏输入的地址(关键字)所使用的协议(如http://等)时,它就会跟根据HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\UrlSearchHooks下的Class ID创建URL Search Hook对象并调用其Translate方法来解析地址栏输入的地址(关键字)。所以我们可以写一个COM对象,实现IUrlSearchHook接口并在其Translate方法中按照你自己喜欢的方式或选择你自己喜欢的搜索引擎来搜索。

2.
Control IE search features

2.1
Adding a custom search feature to CHtmlViews
By Marc Richarme
http://www.codeproject.com/miscctrl/chtmlview_search.asp

The search feature is based on three functions owned by your CHtmlView-derived class:

CMyHtmlView::FindText(CString searchText, long lFlags /* =2 */, BOOL bNNF /* =FALSE (for internal use)*/)
Searches through the document for the specified word/text and highlights the next match.

Parameters:
searchText -Text to search for (duh!)
lFlags - Search flags passed to IHTMLTxtRange::fidText. Can be any combination of 2 (search for whole words only) and 4 (match case)
bNNF - Used internally. If you want to know what this does, look at the code, I don't remember.
CMyHtmlView::FindText2(CString searchText, long lFlags /* =2 */, CString matchStyle, CString searchID)
Searches through the document for the specified word/text and highlights all found occurrences.

Parameters:
searchText - Text to search for (again, duh!)
lFlags - Search flags passed to IHTMLTxtRange::findText. Can be any combination of 2 (search for whole words only) and 4 (match case)
matchStyle - Allows you to customize the way the found text is highlighted in the document. This is a CSS style assigned to the HTML tag. Default: white text on dark blue background.
searchID - Use this if you want to highlight multiple search results at one time (you could use a different matchStyle for each different searchID. Normally you would leave this to default.
CMyHtmlView::ClearSearchResults(CString searchID /* ="CHtmlView_Search" */)
Un-highlights the search results from FindText2.

Parameters:
searchID - the searchID you used in FindText2. If you used the default value, do the same here.

2.2
Find in CWebBrowser Control
By Jeremy Davis
http://www.codeproject.com/tips/mshtmlfind.asp

#include
DEFINE_GUID(CGID_IWebBrowser,0xED016940L,
0xBD5B,0x11cf,0xBA, 0x4E,0x00,
0xC0,0x4F,0xD7,0x08,0x16);

//1 : FIND, 2: VIEWSOURCE, 3 : OPTIONS
DWORD nCmdID = 1;

LPDISPATCH lpDispatch = NULL;
LPOLECOMMANDTARGET lpOleCommandTarget = NULL;

//m_htmlview is the member variable
//for the CWebBrowser2 control.

lpDispatch = m_htmlview.GetDocument();
ASSERT(lpDispatch);

// Get an IDispatch pointer for the
// IOleCommandTarget interface.
lpDispatch->QueryInterface(
IID_IOleCommandTarget,
(void**)&lpOleCommandTarget);
ASSERT(lpOleCommandTarget);

lpDispatch->Release();

// Invoke the given command id for
// the WebBrowser control
lpOleCommandTarget->Exec(
&CGID_IWebBrowser, nCmdID, 0,
NULL, NULL);

// Release the command target
lpOleCommandTarget->Release();

重点还是Exec方法。一般来说直接用Exec比较方便,但是要创建更加丰富的特性,我们还是要想1的方法那样来。

2.3
Search and mark words in html document

By Gleb Golovin March 14, 2001
From http://www.codeguru.com/Cpp/I-N/ieprogram/article.php/c4373

How CMoreHtmlView works.
NavigateMemory() function loads template html document from resource with identifier IDR_EMPTY_HTML and sets m_bMemoryMode to TRUE. PutBodyContent, SetScript etc. functions call IHtmlDocument2 methods only if document object exists, in other case functions only store content in private variables. If these functions execute with NULL parameter then content modification does from member variable values.
OnDownloadComplete function overloading makes for reloading html content if refresh browser command will be called.

Search and mark words in html document
Sometime you need make your own search system in application that uses web browser control. MarkWords member function you could use in that case. You only need to pass a search string as input parameter.

for( ; ;)
{
// Find text
hr = pPtr1->FindText( poSearchStr, 0, pPtr2, NULL );

if (hr == S_FALSE) // did not find the text
break;

IHTMLElement *pFontEl;

// create FONT element with attributes for selection
OLECHAR pchAttributes=0;
hr=pMS->CreateElement(TAGID_FONT,
L"COLOR=white STYLE=\"backgroundcolor:darkblue\"", &pFontEl);

// Insert created element to context
hr=pMS->InsertElement( pFontEl, pPtr1, pPtr2);

// Continue searching
pPtr1->MoveToPointer( pPtr2);
}

It's main part of MarkWords function, at the beginning makes search of string after that creates ... element. This tag marks the located string.

Just like google does.



<< Home

This page is powered by Blogger. Isn't yours?