怎样实现一个获得当前网页地址(url)的插件?(VC++6.0实现)?

zaolaotou 2006-12-11 02:01:19
大家好。怎样用VC编写一个ie插件,功能就是弹出一个对话框,其中获得了当前网页的地址(url)?谢谢各位!
...全文
318 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
tyong 2006-12-14
  • 打赏
  • 举报
回复
///这是由GUIDGEN产生的GUID:{06926B30-424E-4f1c-8EE3-543CD96573DC}
CRegKey reg;
char KeyName[]="Software\\Microsoft\\Internet Explorer\\Extensions\\{06926B30-424E-4f1c-8EE3-543CD96573DC}";
TCHAR PathName[MAX_PATH];
TCHAR IconPathName[MAX_PATH]; ///正常时的图标全路径
TCHAR HotIconPathName[MAX_PATH]; ///鼠标覆盖时的图标全路径
GetModuleFileName(0,PathName,MAX_PATH); ///得到本可执行文件的路径
strcpy(IconPathName,PathName);
strcpy(HotIconPathName,PathName);
strcat(HotIconPathName,",134"); ///131是图标的ID,你可以以资源方式打开EXE文件就可以看到所有资源及其ID
strcat(IconPathName,",134");
reg.Create(HKEY_LOCAL_MACHINE,KeyName);
reg.SetValue("{1FBA04EE-3024-11D2-8F1F-0000F87ABD16}","CLSID");
reg.SetValue("Yes","Default Visible");
reg.SetValue("我乐网","ButtonText");
reg.SetValue(IconPathName,"Icon");
reg.SetValue(HotIconPathName,"HotIcon");
/////假如是执行脚本,可以是reg.SetValue("c:\\test.html","Script"); ///在test.html 存放你的脚本代码<br>
reg.SetValue("http://www.56.com","Exec");///打开网页
蒋晟 2006-12-11
  • 打赏
  • 举报
回复
www.codeproject.com/shell/AutomateShellWindow.asp
lijunjun 2006-12-11
  • 打赏
  • 举报
回复
可用动态链接库也可用BHO
lion_wing 2006-12-11
  • 打赏
  • 举报
回复
1、http://210.75.112.240:8975/webhtml/ylzx/yl/yy/200608/32330.html
2、http://blog.csdn.net/dtren/archive/2006/11/09/1376121.aspx
zaolaotou 2006-12-11
  • 打赏
  • 举报
回复
你好,那假如我在工具栏上设置一个小图标,点击这个小图标的功能就是导航至另一个页面,比如www.sohu.com,我就是想做这样一个插件。请问如何实现?谢谢!新手请指教。

另外就是刚才我做的这块儿我在ie里测试怎么测试?我怎么测试不出来?谢谢!!!
lion_wing 2006-12-11
  • 打赏
  • 举报
回复
晕!
代码:
USES_CONVERSION;
::MessageBox(0, OLE2A(&strUrl), "当前URL", 0);
zaolaotou 2006-12-11
  • 打赏
  • 举报
回复
STDMETHODIMP CPluginIE::SetSite(IUnknown *pUnkSite)
{
if(pUnkSite != NULL)
{
CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> m_pWebBrowser2;
m_pWebBrowser2 = pUnkSite;
if(m_pWebBrowser2 != NULL)
{
CComBSTR strUrl;
m_pWebBrowser2->get_LocationURL(&strUrl);
USES_CONVERSION;
OLE2A(&strUrl);
::MessageBox(0, strUrl, _T("当前URL"), 0);

}
}
}

错误:error C2440: '=' : cannot convert from 'unsigned short ** ' to 'const unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\CJ\TestPIE\PluginIE.cpp(24) : error C2664: 'MessageBoxA' : cannot convert parameter 2 from 'class ATL::CComBSTR' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.
lion_wing 2006-12-11
  • 打赏
  • 举报
回复
什么错误呀?
zaolaotou 2006-12-11
  • 打赏
  • 举报
回复
还是不行呀?
lion_wing 2006-12-11
  • 打赏
  • 举报
回复
注意:OLE2T前加:
USES_CONVERSION;
lion_wing 2006-12-11
  • 打赏
  • 举报
回复
OLE2T(strUrl); //TCHAR*
OLE2A(strUrl); //char*
OLE2W(strUrl); //wchar*
zaolaotou 2006-12-11
  • 打赏
  • 举报
回复
就是怎样把 ::MessageBox(0, strUrl, _T( "当前URL "), 0); 中带二个参数
strUrl的类型由CComBSTR 转换为:(char *)类型的,强制转换不行?
jacklzw88 2006-12-11
  • 打赏
  • 举报
回复
呵呵,流氓插件
lion_wing 2006-12-11
  • 打赏
  • 举报
回复
m_pWebBrowser2->Naviage(_T("http://www.sohu.com"),NULL,NULL,NULL,NULL);
zaolaotou 2006-12-11
  • 打赏
  • 举报
回复
lion_wing的代码有一个强制转换的问题,怎么试不行?
另外如果插件功能是实现导航至另一个页面,比如:www.sohu.com,只是这个
功能,怎么实现?谢。上一个分已给。
lion_wing 2006-12-11
  • 打赏
  • 举报
回复
Use BHO and Write in SetSite:
//IObjectWithSite
STDMETHODIMP CCnObj::SetSite(IUnknown *pUnkSite)
{
if(pUnkSite != NULL)
{
CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> m_pWebBrowser2;
m_pWebBrowser2 = pUnkSite;
if(m_pWebBrowser2 != NULL)
{
CComBSTR strUrl;
m_pWebBrowser2->get_LocationURL(&strUrl);
::MessageBox(0, strUrl, _T("当前URL"), 0);
}
}
}
Kudeet 2006-12-11
  • 打赏
  • 举报
回复
ZT:

You may want to use IE's Automation (have a look at IWebBrowser2 and
IHTMLDocument2 in particular). And to get a pointer on an existing instance
of IE have a look overthere
http://support.microsoft.com/support/kb/articles/Q176/7/92.ASP


You can also consult
news:microsoft.public.inetsdk.programming.webbrowser_ctl


Also if you don't already have it, I would recommend you to download the
latest version of the Platform SDK in order to have the documention to the
IHTMLxxx interfaces (the documentation of IWebBrowser2 is bundled with
MSVC++6)
Kudeet 2006-12-11
  • 打赏
  • 举报
回复
how to retrieve the URL from all opened IE windows:

1. Enumerate all top-level windows using the EnumWindows callback (this gives us a Handle)
2. Grab the Caption (Title) of each Window
3. Look only for windows whose class name is "IEFrame"
4. Use the FindWindow provided with the Handle and the Caption to locate the correct IE window
5. Call FindWindowEx several times to locate the ComboBox carying the URL, as it is the child to some parent which is a child to our top-level IEFrame (this is the class name) window
6. Send a message to the ComboBox to retrieve the text inside it
7. Nothing more, really.

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧