===如何在vc中获取和处理ie的button按下的事件???

K99 2003-10-02 04:30:25
想实现当按下ie中button的时候,vc响应这个消息,
我搜索了一些代码,
msdn的Handling HTML Element Events
也看了,但是我找不到如何得到运行中的ie的IWebBrowser2 Interface 。
Accessing the DHTML Object Model 中的m_pBrowser我不知道如何获取


还有一篇文章是用
SHDocVw::IShellWindowsPtr m_spSHWinds;
m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows))
获取运行中的ie的接口的,但是我转换不了SHDocVw::IWebBrowser2Ptr为IWebBrowser2 。
大侠请帮俺一把,感激不尽
...全文
146 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2003-10-14
  • 打赏
  • 举报
回复
说了是调用QueryInterface就可以获得啊
K99 2003-10-13
  • 打赏
  • 举报
回复
或者给我点关于SHDocVw::IWebBrowser2Ptr资料也行
我自己看。benimuru@vip.sina.com
K99 2003-10-13
  • 打赏
  • 举报
回复
楼上的大侠不妨再具体写点啊
我对com是不懂
蒋晟 2003-10-13
  • 打赏
  • 举报
回复
QueryInterface
其实SHDocVw::IWebBrowser2Ptr是封装了IWebBrowser2的智能指针……
K99 2003-10-12
  • 打赏
  • 举报
回复
ding
K99 2003-10-05
  • 打赏
  • 举报
回复
大侠们啊,都放假了吗?
K99 2003-10-03
  • 打赏
  • 举报
回复
能详细一些玛?
K99 2003-10-03
  • 打赏
  • 举报
回复
bho我不能用

我的东西要用在ug(绘图软件里面)的二次开发中

能够把SHDocVw::IWebBrowser2Ptr变为IWebBrowser2就好了

我不知道哪里有关于SHDocVw::IWebBrowser2Ptr的资料,里面的函数都不知道
Skt32 2003-10-03
  • 打赏
  • 举报
回复
Tracking The Mouse In A View
By John Simmons / outlaw programmer

Track a mouse click, even in a scrolled view
http://codeproject.com/docview/regiontracker.asp
Skt32 2003-10-03
  • 打赏
  • 举报
回复
Hooking Keyboard messages from Internet Explorer

--------------------------------------------------------------------------------
This article was contributed by Robert Nagy.
Environment: VC6, Windows 2000

The following code demonstrates an example on hooks. A friend of mine asked me to write a program that logs keyboard messages from a given application. Here is how it works:

After executing the program it installs the hook functions to monitor keyboard messages from IE then writes the chars to a file. The program has no window, so it can be stopped only through Task Manager (or by CTR-ALT-DEL in Win95/98). It is simple to modify the code to monitor all/another running application's keyboard messages. A hook function must be a CALLBACK function and must be placed in a dll. So you have to create a dll and an exe that calls it.

The dll
If you want to create a Win32 dll (there is MFC dll but its size is big) run Visual C++ and from the FILE MENU click NEW - make sure the projects tab is selected - fill out the edit-boxes then click on "Win32 Dynamic-Link Library", click OK, then choose "An Empty Dll project". Now you have to add two files (.h, .c). To do this choose FILE/NEW - make sure the files tab is selected - click on "C/C++ Header file" fill out the edit-boxes and click OK. Now repeat the process but choose "C++ Source File" and you are ready for writing the code. From the workspace window choose FileView and by clicking on the "+" signs move in the tree until the .h file is not visible (it's in "Header Files"). Double click on it, so it will be active. Now you can write your code and do this for the .c file, and include the header file in the .c file than Build the dll. The __declspec(dllexport) means that the associated functions are exported (they can be called from an exe though are in the dll). Now take a look at the .c file in the dllsource code. There are three important functions:

SetKbHook
CBTProc
KeyboardProc
In SetKbHook you install the hooks (KeyboardProc and CBTProc are the hook functions) through the SetWindowsHookEx function (VC++ help). The KeyboardProc hook function monitors keyboard messages and writes them to a file. The wParam parameter contains the virtual-key codes. The CBTProc function monitors active windows, and from it's handle it gets the "class name" of the window through the GetClassName function (VC++ help).

The exe
Now you will create a Win32 Application. Select FILE MENU/CLOSE WORKSPACE and close all windows. FILE MENU/NEW then click on "Win32 Application" (make sure Projects tab is selected), fill out the edit-boxes then click OK. Choose An empty project then click OK. Copy the dll's .h file to this project's folder, then PROJECT MENU/Add to Project/Files add the copied .h file to the exe project (it will appear in the workspace window under "Header Files"). FILE MENU/NEW add a "C++ Source File" to the project. Include the dll's .h file, so the exe will now know about the dll's exported functions. Use LoadLibrary to load the dll, and call SetKbHook function through GetProcAddress (VC++ help). This is explicit linking.

If you want to link the dll implicit you don't have to use LoadLibrary you can directly call the SetKbHook function. You can achive this if you copy and add the .lib file of the dll to the exe project (The compiler builds the .lib file during Build). It's important that you set BUILD MENU/SET ACTIVE CONFIGURATION to Release both in the exe and dll project. The program will not monitor a window if it became active before it's been executed.

You can easily add a window to the program if you define the window-handler CALLBACK function and fill the WNDCLASS and CREATEWINDOW structures and call RegisterClassEx, ShowWindow and UpdateWindow functions in the exe project's .c code.

Downloads
Download exe and dll source - 20 Kb

History
Date Posted: August 2, 2001
http://www.codeguru.com/system/hooktut.html
liuchengdan 2003-10-03
  • 打赏
  • 举报
回复
贴我的源码。用CHtmlFile类实现。

BOOL GetSourceByURL(CString sURL, CString &fileContent)
{
CInternetSession internetSession;
CHttpConnection* pHttpConnection = NULL;
CHttpFile* pHttpFile = NULL;
CString strServer, strObject;
DWORD dwServiceType = 0;
DWORD dwHttpRequestFlags = INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_AUTO_REDIRECT;
TCHAR szHeaders[] = _T("Accept: text/*\r\nUser-Agent: LCD's Sample Http Client\r\n");
INTERNET_PORT nPort;
int nRet = 0;

nRet = AfxParseURL( (LPCTSTR)sURL, dwServiceType, strServer, strObject, nPort );
if( !nRet || dwServiceType != INTERNET_SERVICE_HTTP )
{
fileContent.Empty();
AfxMessageBox( "不能保存请求保存的网页的源代码。原因可能如下:\r\n\r\n1)请求不是一个HTTP请求。\r\n\r\n2)所请求的URL无法到达。" );
return FALSE;
}

pHttpConnection = internetSession.GetHttpConnection( strServer, nPort );
pHttpFile = pHttpConnection->OpenRequest( CHttpConnection::HTTP_VERB_GET, strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags);
pHttpFile->AddRequestHeaders( szHeaders );
pHttpFile->SendRequest();

DWORD dwRet = 0;
pHttpFile->QueryInfoStatusCode( dwRet );
if( dwRet == HTTP_STATUS_DENIED )
{
AfxMessageBox( "连接被拒绝" );
return FALSE;
}

CString string, prefix, suffix, path, sCopy, sTemp, strFilePath;
int iStart = 0, iEnd = 0;

strFilePath = sURL.Left( ( sURL.ReverseFind( '/' ) ) );

fileContent.Empty();
while( pHttpFile->ReadString( string ) )
{
fileContent += "\r\n" + string;
}

pHttpFile->Close();
pHttpConnection->Close();
delete pHttpFile;
delete pHttpConnection;

return TRUE;
}
Onega 2003-10-02
  • 打赏
  • 举报
回复
write a BHO, get IWebbrowser2* pointer, on its DownloadComplete event, install onclick event handler to button objects.
http://www.codeproject.com/atl/popupblocker.asp

3,055

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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