怎么在窗口的任意区域不受任何条件约束地显示一个提示(ToolTip)

boybaby 2002-05-15 09:27:19
包括用不着联系一个控件就能显示。答出来者给500分,不够再加。
...全文
98 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
boybaby 2002-05-15
  • 打赏
  • 举报
回复
To mul:
不知道一个CToolTipCtrl不和一个普通控件连系在一起是否能够显示消息提示
kingzai 2002-05-15
  • 打赏
  • 举报
回复
you can use tooltip wnd,example:
BOOL CPopupTipWnd::Create(CWnd *pParentWnd)
{
_ASSERTE(pParentWnd);

m_pParentWnd = pParentWnd;

DWORD dwStyle = WS_BORDER | WS_POPUP;
DWORD dwExStyle = WS_EX_TOOLWINDOW | WS_EX_TOPMOST;

BOOL bCreated = CreateEx(dwExStyle,
PWDSPY_POPUP_TIP_CLASSNAME,
NULL,
dwStyle,
0, 0, 0, 0,
NULL, NULL, NULL);

return bCreated;
}

//***********************************************
bool CPopupTipWnd::RegisterWindowClass(void)
{
WNDCLASS wndcls = {0};
wndcls.style = CS_SAVEBITS | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndcls.lpfnWndProc = ::DefWindowProc;
wndcls.hCursor = (HCURSOR)::LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE);
wndcls.hbrBackground = (HBRUSH)(COLOR_INFOBK + 1);
wndcls.lpszClassName = PWDSPY_POPUP_TIP_CLASSNAME;

if(!::RegisterClass(&wndcls))
{
AfxThrowResourceException();
return false;
}

return true;
}

//***********************************************
void CPopupTipWnd::ShowPopupWindow(CString strText, CPoint point, CRect rect)
{
// If there is no password, instead hide the window and be done with it
if(strText.IsEmpty())
{
HidePopupWindow();
return;
}

CClientDC dc(this);

// Use same font as parent window
CFont *pOldFont = dc.SelectObject(m_pParentWnd->GetFont());

// Calculate the window size.
CSize sizeText = dc.GetTextExtent(strText);
CSize sizeWindow;
sizeWindow.cx = sizeText.cx + 2 * BORDER_X;
sizeWindow.cy = sizeText.cy + 2 * BORDER_Y;

// Draw information in window
dc.SetBkMode(TRANSPARENT);
dc.DrawText(strText, CRect(0, 0, sizeWindow.cx, sizeWindow.cy), DT_CENTER | DT_VCENTER | DT_SINGLELINE);
dc.SelectObject(pOldFont);

// Calculate window rectangle position on screen
CRect rectWindow;
rectWindow.left = rect.left;
rectWindow.right = rectWindow.left + sizeWindow.cx;
rectWindow.top = rect.top - (sizeWindow.cy + 20);
if(rectWindow.top <= 0)
rectWindow.top = rect.bottom + 20;
rectWindow.bottom = rectWindow.top + sizeWindow.cy;

// Display window
SetWindowPos(&wndTop,
rectWindow.left,
rectWindow.top,
rectWindow.Width(),
rectWindow.Height(),
SWP_SHOWWINDOW | SWP_NOACTIVATE);
}

//***********************************************
void CPopupTipWnd::HidePopupWindow(void)
{
ShowWindow(SW_HIDE);
}
mul 2002-05-15
  • 打赏
  • 举报
回复
BOOL CXXXView::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(m_ctrlHotTip.m_hWnd != 0)
m_ctrlHotTip.RelayEvent(pMsg);
return CView::PreTranslateMessage(pMsg);
}

void CXXXView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_rect.PtInRect(point))
{
m_ctrlHotTip.AddTool(this,LPCTSTR("在此rect中));
m_ctrlHotTip.Activate(TRUE);
}
CView::OnMouseMove(nFlags, point);
}
boybaby 2002-05-15
  • 打赏
  • 举报
回复
我发现CSDN问题越来越多了,提前也无法成功,速度也越来越慢了,是不是CSDN服务器坏了!!!

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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