如题:我的ActiveX控件是要嵌入到网页里的,我想给控件中的按钮加一个提示,就是鼠标移到按钮上面显示提示文本的那种,在一般的工程程序里没问题,可是在ActiveX控件里失效,显示不出来,大家有什么方法吗?
解决方案 »
- ActiveX控件传递自定义类对象
- 如何响应CMFCToolBar中的CMFCToolBarComboBoxButton的编辑改变事件?
- 关于vs2005一个很奇怪的问题????
- send的返回结果为-1,错误代码为10053?着急呀............
- 如何得知当前CWnd的滚动尺寸,可能我太笨了,看似很简单的问题,却找不到答案,急求大家帮助!!!谢谢了!一定结贴:)
- [求助]用truncate清空数据库时间
- 高分求救用NERO SDK 刻录整个目录(包括子目录)到光盘的源代码
- 关于编译时的一个问题。在线等。
- 初级问题:在LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)中的wParam和lParam是做什么用的??获得的
- 超菜问题,selectobject
- treecontrol控件显示多级数据
- 问个关于MessageBox的编译问题
在里面实现 RelayEvent(WM_MOUSEMOVE,(WPARAM)nFlags,MAKELPARAM(LOWORD(point.x),LOWORD(point.y)));3.RelayEvent(UINT message,WPARAM wParam,LPARAM lParam)
{
if (NULL !=m_ttip.m_hWnd){
MSG msg;
msg.hwnd=m_hWnd;
msg.message=message;
msg.lParam=lParam;
msg.time=0;
msg.pt.x=LOWORD(lParam);
msg.pt.y=HIWORD(lParam);
m_ttip.RelayEvent(&msg);
}
}问题是在哪儿初始化m_ttip?????
CWindow m_wndToolTip;
2.Include Commctrl.h in Stdafx.h file.(include Afxcmn.h if application has MFC support).
#include <commctrl.h>
3.Override InplaceActive method and add the following code to create tooltip control.
HRESULT InPlaceActivate(LONG iVerb, const RECT* prcPosRect=NULL)
{
HRESULT hr; hr = CComControlBase::InPlaceActivate(iVerb, prcPosRect);
if (m_wndToolTip.m_hWnd == NULL)
{
// If we're windowless we still need an HWND
if (m_bWndLess)
{
HDC hDC;
// Get the HDC from the client
m_spInPlaceSite->GetDC(NULL, OLEDC_NODRAW, &hDC);
m_hTheWnd = WindowFromDC(hDC);
m_spInPlaceSite->ReleaseDC(hDC);
}
else
m_hTheWnd = m_hWnd; //Load the Common control library and create tooltip control
InitCommonControls();
m_wndToolTip.m_hWnd =
::CreateWindow(TOOLTIPS_CLASS, (LPTSTR)NULL, TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, (HMENU) NULL, _Module.GetModuleInstance(), NULL); // Ensure the tooltip always appears above our window
::SetWindowPos(m_wndToolTip.m_hWnd, HWND_TOPMOST,0,0,0,0,
SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOSIZE); TOOLINFO ti;
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = 0;
ti.hwnd = m_hTheWnd;
ti.uId = 1;
ti.hinst = NULL;
ti.lpszText = m_bWndLess ? ti.lpszText = _T("My Windowless Tip") : ti.lpszText = _T("My Windowed Tip");
m_wndToolTip.SendMessage(TTM_ADDTOOL, 0, (LPARAM)&ti);
}
return hr;
}
4.Create a variable m_hTheWnd of type HWND in control class and then create handlers for WM_LBUTTONDOWN and WM_MOUSEMOVE to the control's class. Relay appropriate messages to the ToolTip control. The sample code is shown in the following:
void RelayEvent(UINT message, WPARAM wParam, LPARAM lParam)
{
if (NULL != m_wndToolTip.m_hWnd)
{
MSG msg; msg.hwnd= m_hTheWnd;
msg.message= message;
msg.wParam= wParam;
msg.lParam= lParam;
msg.time= 0;
msg.pt.x= LOWORD (lParam);
msg.pt.y= HIWORD (lParam); ::SendMessage(m_wndToolTip.m_hWnd, TTM_RELAYEVENT, 0, (LPARAM)&msg);
}
} LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam,BOOL bHandled)
{
bHandled = FALSE;
RelayEvent(uMsg, (WPARAM)wParam,MAKELPARAM(LOWORD(lParam), HIWORD(lParam)));
return 0L;
}
LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam,BOOL& bHandled)
{
if (m_wndToolTip.m_hWnd)
{
POINT pt;
static uId;
pt.x = LOWORD(lParam);
pt.y = HIWORD(lParam); TOOLINFO ti;
ti.cbSize = sizeof(TOOLINFO);
ti.hwnd = m_hTheWnd;
ti.uId = 1;
ti.rect.left = pt.x;
ti.rect.right = pt.x+1;
ti.rect.top = pt.y;
ti.rect.bottom = pt.y+1;
m_wndToolTip.SendMessage(TTM_NEWTOOLRECT, 0, (LPARAM)&ti);
RelayEvent(uMsg, wParam, lParam);
}
return 0;
}
5.Link the project to Comctl32.lib. You can do either by specifying this library name on linker settings of project/settings dialog box (or) by adding this LIB manually to the project.
1.Add MFC support to ATL project. To use MFC's CToolTipCtrl class, an ATL application should support MFC in the first place. You could do this by selecting Support MFC option in Step1 of ATL/COM AppWizard for ATL DLLs. If the project has already been created without MFC support, you will have to add MFC support manually. The following article shows how to add MFC support ATL DLL/EXE:
2.Use CToolTipCtrl instead of CWindow for m_wndToolTip member of control class.
3.Call methods of CToolTipCtrl instead of sending messages.
HRESULT InPlaceActivate(LONG iVerb, const RECT* prcPosRect=NULL)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CWnd parent; HRESULT hr; hr = CComControlBase::InPlaceActivate(iVerb, prcPosRect);
if (m_wndToolTip.m_hWnd == NULL)
{
if (m_bWndLess)
{
HDC hDC;
// Get the HDC from the client
m_spInPlaceSite->GetDC(NULL, OLEDC_NODRAW, &hDC);
m_hTheWnd = WindowFromDC(hDC);
m_spInPlaceSite->ReleaseDC(hDC);
}
else
m_hTheWnd = m_hWnd; ::InitCommonControls();
parent.Attach(m_hTheWnd);
RECT rect = {0,0,0,0};
if (!m_wndToolTip.Create(&parent))
TRACE("Unable to create tip window.\n");
else if (!m_wndToolTip.AddTool(&parent, LPCTSTR("TTip2 Control"),&rect, 1))
TRACE("Unable to add tip for the control window.\n");
else
m_wndToolTip.Activate(TRUE);
parent.Detach();
}
return hr;
} void RelayEvent(UINT message, WPARAM wParam, LPARAM lParam)
{
if (NULL != m_wndToolTip.m_hWnd)
{
MSG msg; msg.hwnd= m_hTheWnd;
msg.message= message;
msg.wParam= wParam;
msg.lParam= lParam;
msg.time= 0;
msg.pt.x= LOWORD (lParam);
msg.pt.y= HIWORD (lParam); m_ttip.RelayEvent(&msg);
}
}
LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam,BOOL& bHandled)
{
if (m_wndToolTip.m_hWnd)
{
POINT pt;
static uId;
pt.x = LOWORD(lParam);
pt.y = HIWORD(lParam); TOOLINFO ti;
ti.cbSize = sizeof(TOOLINFO);
ti.hwnd = m_hTheWnd;
uId = 1;
ti.uId = uId;
ti.rect.left = pt.x;
ti.rect.right = pt.x+1;
ti.rect.top = pt.y;
ti.rect.bottom = pt.y+1;
m_ttip.SendMessage(TTM_NEWTOOLRECT, 0, (LPARAM)&ti);
}
RelayEvent(uMsg, wParam, lParam);
return 0;
} LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam,BOOL bHandled)
{
bHandled = FALSE;
RelayEvent(uMsg, (WPARAM)wParam,MAKELPARAM(LOWORD(lParam), HIWORD(lParam)));
return 0L;
}
1.atlcontrols.h 文件从 ATLCON 复制到控件项目的目录并将其添加到项目中。
2.您可以包括它在 stdafx.h 文件中。
3.使用 MFC 的 CToolTipCtrl 类的使用 CToolTipCtrl 。
我是从上面那个网站直接copy的。