为什么webBrowser无法复制、粘贴。

niatguomin 2011-08-23 04:03:07
写了一个程序,win32的,不是MFC的。加载了webBrowser控件,胆识打开网页后,发现没有复制、粘贴的快捷键,ctrl-c,ctrl-v无效。同事做了一个js,里面有个onkeyup事件,也是无效。也就是说,键盘消息没有传递到网页上,或者没有处理。
向各位请教。如何处理。
...全文
567 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
niatguomin 2011-08-31
  • 打赏
  • 举报
回复
问题基本搞定,原来是没有调用OleInitialize(NULL);
谢谢各位。结贴给分。
niatguomin 2011-08-30
  • 打赏
  • 举报
回复
使用菜单也是无法复制,真是头大。
niatguomin 2011-08-30
  • 打赏
  • 举报
回复
to newerC 不是太明白你的意思。我并没有这个接口。我的继承体系是,
class CActiveX :
public IOleClientSite,
public IOleInPlaceSiteWindowless,
public IOleControlSite,
public IObjectWithSite,
public IOleContainer,
public IDocHostUIHandler
{
};

spInPlace->TranslateAccelerator(pMsg)之后,进入了IDocHostUIHandler的IDocHostUIHandler接口。
newerC 2011-08-26
  • 打赏
  • 举报
回复
会不会SetExternalUIHandler(IDocHostUIHandlerDispatch),但是自己的IDocHostUIHandlerDispatch又没有处理好的缘故.
Waistcoat23 2011-08-24
  • 打赏
  • 举报
回复
你的控件父窗口要处理PreTranslateMessge,把消息传给WebBrowser对象

CComQIPtr<IOleInPlaceActiveObject> spInPlace = pYourWebBrowser;
if (spInPlace) spInPlace->TranslateAccelerator(pMsg);
niatguomin 2011-08-24
  • 打赏
  • 举报
回复
to ndy_w,好像不对啊,用getfocus获取hwnd,得到的hwnd就是Internet Explorer_Server的对应HWND.
许文君 2011-08-24
  • 打赏
  • 举报
回复
1.要焦点,2要重载pretranslatemessage
niatguomin 2011-08-24
  • 打赏
  • 举报
回复
我以为,鼠标点下去之后,应该已经setfoucs在IE控件上了。先试试看。
ndy_w 2011-08-24
  • 打赏
  • 举报
回复
我认为是。你setfocus一下
niatguomin 2011-08-24
  • 打赏
  • 举报
回复
to ndy_w 没有跳转。焦点的问题?
ndy_w 2011-08-24
  • 打赏
  • 举报
回复
不对啊!那么你按TAB键,是否能在链接里跳转?
niatguomin 2011-08-24
  • 打赏
  • 举报
回复
to fishion,没有屏蔽。
to ndy_w 焦点在IE控件上面。
niatguomin 2011-08-24
  • 打赏
  • 举报
回复
会不会跟权限之类的有关系?ctrl-c,ctr-z,ctr-x等,都是将删除的东西保存在内存里面,这些操作都是可以撤销的。
niatguomin 2011-08-24
  • 打赏
  • 举报
回复
to Waistcoat23
我是这么处理的消息循环,
// 主消息循环:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
if ( !PreTranslateMessage(&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
//PreTranslateMessage是自己定义的。如下。
BOOL PreTranslateMessage(MSG* pMsg )
{
if(pMsg->message == WM_CHAR || pMsg->message == WM_KEYUP || pMsg->message == WM_KEYDOWN)
{
TCHAR str[MAX_PATH] = {'\0'};
GetClassName(pMsg->hwnd,str,MAX_PATH);
//IE控件
if( StrCmp(L"Internet Explorer_Server",str) == 0 )
{
/* if ( ::GetKeyState(VK_CONTROL) < 0)
{*/
::SetFocus(pMsg->hwnd);
CComQIPtr<IOleInPlaceActiveObject> spInPlace = g_pControl;
if (spInPlace)
{
HRESULT hr = spInPlace->TranslateAccelerator(pMsg);
DWORD dw = 0;
if ( hr == S_OK)
{
return TRUE;
}
else if ( hr == S_FALSE)
{
dw = ::GetLastError();
return FALSE;
}
}
}
}
return FALSE;
}
Waistcoat23 2011-08-24
  • 打赏
  • 举报
回复
spInPlace->TranslateAccelerator(pMsg);如果返回成功你的Return TRUE.
niatguomin 2011-08-24
  • 打赏
  • 举报
回复
真是妖了,ctrl-a,ctrl-v可以,ctrl-c,ctrl-z不可以,而且菜单的复制都不可以。奇怪了。
代码如下:

BOOL PreTranslateMessage(MSG* pMsg )
{
if(pMsg->message == WM_CHAR || pMsg->message == WM_KEYUP || pMsg->message == WM_KEYDOWN)
{
TCHAR str[MAX_PATH] = {'\0'};
GetClassName(pMsg->hwnd,str,MAX_PATH);
//IE控件
if( StrCmp(L"Internet Explorer_Server",str) == 0 )
{
if ( ::GetKeyState(VK_CONTROL) < 0)
{
::SetFocus(pMsg->hwnd);
CComQIPtr<IOleInPlaceActiveObject> spInPlace = g_pControl;
if (spInPlace)
{
spInPlace->TranslateAccelerator(pMsg);
}
}
}
}
return FALSE;
}
ndy_w 2011-08-23
  • 打赏
  • 举报
回复
焦点何在?
fishion 2011-08-23
  • 打赏
  • 举报
回复
是不是你把鼠标消息屏蔽了
niatguomin 2011-08-23
  • 打赏
  • 举报
回复
顶下的人都没有?

3,245

社区成员

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

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