首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

ATL 工程 控件加 tooltip,该怎么处理

2014-07-26 
ATL 工程 控件加 tooltip如题,ATL工程,支持MFC,想给工具栏上的一排按钮(已加贴图)加上 tooltip,试了几种MF

ATL 工程 控件加 tooltip
如题,ATL工程,支持MFC,想给工具栏上的一排按钮(已加贴图)加上 tooltip,试了几种MFC常见的 加tooltip的方式却都不可行,求教。

[解决办法]
Vinod: 


Does the inner control's window cover the entire region of the CAxWindow? In that case, no tooltip will be visible because controls do not forward processing of the message that tells the control to show its tool window to their parents. 
Try setting the hwnd member of my TOOLINFO struct to be the handle of the AX control that is attached to the CAxWindow (not the handle of the CAxWindow itself). I happen to have some code laying around that uses tool windows with CAxWindows; it looks something like this: 


ComPtr<IShape> srpShape; 
CAxWindow wnd; 
HWND hwndToolTip; 
HWND hwndCtl; 
TOOLINFO ti; 


//Create a control. 
srpShape.CoCreateInstance("Some.ProgId"); 


//Create the CAxWindow and host the control inside of it 
wnd.Create(g_hwndDlg, &rc, _T(""), WS_CHILD | WS_VISIBLE); 
wnd.AttachControl(srpShape, NULL); 


//get the HWND of the control (assuming it implements IOleWindow) 
CComQIPtr<IOleWindow> srpWindow = srpShape; 
hwndCtl = NULL; 
srpWindow->GetWindow(&hwndCtl); 
srpWindow.Release(); 


//Create the tooltip window 
hwndToolTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | TTS_BALLOON, CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, NULL, NULL, NULL, NULL); 


//Attach the tooltip to the shape control 
ti.cbSize = sizeof(ti); 
ti.hinst = g_hInst; 
ti.hwnd = hwndCtl; //Note: != wnd 
ti.lParam = NULL; 
ti.lpszText = _T("ToolTip!"); 
ti.uId = 0; 
ti.rect.left = 0; 
ti.rect.top = 0; 
ti.rect.bottom = SHAPESIZE; 
ti.rect.right = SHAPESIZE; 
ti.uFlags = TTF_SUBCLASS; 
SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti); 
SendMessage(hwndToolTip, TTM_SETMAXTIPWIDTH, 0, 300); 
SendMessage(hwndToolTip, TTM_SETDELAYTIME, (WPARAM)TTDT_RESHOW, (LPARAM)10); 


That's not the exact code, and I've left all the error handling out, but I think you can still get the gist from it. Give it try and see if it helps. If you really need to set the tooltip to the CAxWindow itself, and not the hosted control, that should work fine also, as long as you don't hover over part of the CAxWindow that is covered by the hosted control. 


Good luck! 


- Aaron Hare <ahare@online.microsoft.com> 
Please post questions to the newsgroup - everyone benefits. 
This post is provided "AS IS" with no warranties, and confers no rights 
Sample code subject to http://www.microsoft.com/info/cpyright.htm

[解决办法]

探讨
Vinod:


Does the inner control's window cover the entire region of the CAxWindow? In that case, no tooltip will be visible because controls do not forward processing of the message that tells the……

热点排行