关于bitmapbutton的问题,急!

jadeking 2001-07-17 11:17:53
我的程序是基于单文档,我在View中创建一个CbitmapButton;
但我不知道给如何给这个bitmapbutton设置cursor和tooltip;

多谢各位大虾鼎力相助!
...全文
187 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
jadeking 2001-07-17
  • 打赏
  • 举报
回复
zzh,如何设置?

多谢111222,但这样出来整个view中都出现手型了,我只要点击bitmap按钮时出现!
111222 2001-07-17
  • 打赏
  • 举报
回复
CToolTipCtrl m_ToolTip;


void CMyBmpBtn::PreSubclassWindow()
{
CRect rect;
GetClientRect(rect);
m_ToolTip.Create(this);
m_ToolTip.AddTool(this, _T("按时扩大解放和喀什的"), rect, 0);
}
BOOL CMyBmpBtn::PreTranslateMessage(MSG* pMsg)
{
m_ToolTip.RelayEvent(pMsg);
return CBitmapButton::PreTranslateMessage(pMsg);
}
111222 2001-07-17
  • 打赏
  • 举报
回复
重载一个CBitmapButton,填加WM_SETCURSOR响应函数

BOOL CMyBmpBtn::OnSetCursor( CWnd* pWnd, UINT nHitTest, UINT message )
{
static HCURSOR m_hLinkCursor;

if (m_hLinkCursor == NULL) // No cursor handle
{
// Get the windows directory
CString strWndDir;
GetWindowsDirectory(strWndDir.GetBuffer(100), 100);
strWndDir.ReleaseBuffer();

strWndDir += _T("\\winhlp32.exe");
// This retrieves cursor #106 from winhlp32.exe, which is a hand pointer
HMODULE hModule = LoadLibrary(strWndDir);
if (hModule) {
HCURSOR hHandCursor = ::LoadCursor(hModule, MAKEINTRESOURCE(106));
if (hHandCursor)
m_hLinkCursor = CopyCursor(hHandCursor);
}
FreeLibrary(hModule);
}

::SetCursor(m_hLinkCursor);
return TRUE;
}


//这样鼠标放上去就出现手型了
zzh 2001-07-17
  • 打赏
  • 举报
回复
你如果是创建出来的按钮,可以通过设置它的属性来完成这些功能。
jadeking 2001-07-17
  • 打赏
  • 举报
回复
case
111222 2001-07-17
  • 打赏
  • 举报
回复
BOOL AddTool( CWnd* pWnd, LPCTSTR lpszText = LPSTR_TEXTCALLBACK, LPCRECT lpRectTool = NULL, UINT nIDTool = 0 );

抱歉,我没有看MSDN里面AddTool函数的原形,其中第3个参数指定是NULL
jadeking 2001-07-17
  • 打赏
  • 举报
回复
多谢111222,50分送上!

有个小问题:
void CMyBmpBtn::SetToolTip(CString str)
{
CRect rect;
GetClientRect(rect);
m_ToolTip.Create(this);
m_ToolTip.AddTool(this, str, rect, 0);

}函数中,这样用在我的程序中,一启动就报错!
问题出在m_ToolTip.AddTool(this , str, rect, 0);这行,单步调试到
VC中TOOLTIP.CPP文件的138行:(lpRectTool == NULL) && (nIDTool == 0));处:

我将rect, 改为NULL, 就OK了!!不知是什么原因?

不管怎么说,多谢111222大虾!多谢!

111222 2001-07-17
  • 打赏
  • 举报
回复
SmartHeart:
嘻,考完试偶就回来勒,到水员还报了个好,只是很快就结帖子了
回来准备好好学习科学技术,不灌水了:)
我也挺想大伙的,总能想起
111222 2001-07-17
  • 打赏
  • 举报
回复
我写了个类,包括cursor和tooltip

用法: #include "CMyBmpBtn.h"

CMyBmpBtn btn;

btn.SetToolTip("提示");//初始化时候设置就成了

---------------下面是代码---------------------
///////////////////////////////////
// CMyBmpBtn.h ////////////////////
///////////////////////////////////

#if !defined(AFX_MYBMPBTN_H__E4B18361_7AAC_11D5_9D99_444553540000__INCLUDED_)
#define AFX_MYBMPBTN_H__E4B18361_7AAC_11D5_9D99_444553540000__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MyBmpBtn.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CMyBmpBtn window

class CMyBmpBtn : public CBitmapButton
{
// Construction
public:
CMyBmpBtn();

// Attributes
public:

// Operations
public:
CToolTipCtrl m_ToolTip;


// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyBmpBtn)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
//}}AFX_VIRTUAL

// Implementation
public:
void SetToolTip(CString str);
virtual ~CMyBmpBtn();

// Generated message map functions
protected:
//{{AFX_MSG(CMyBmpBtn)
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MYBMPBTN_H__E4B18361_7AAC_11D5_9D99_444553540000__INCLUDED_)











/////////////////////////////////////////
// MyBmpBtn.cpp : implementation file
/////////////////////////////////////////

#include "stdafx.h"
#include "MyBmpBtn.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyBmpBtn

CMyBmpBtn::CMyBmpBtn()
{
}

CMyBmpBtn::~CMyBmpBtn()
{
}


BEGIN_MESSAGE_MAP(CMyBmpBtn, CButton)
//{{AFX_MSG_MAP(CMyBmpBtn)
ON_WM_SETCURSOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyBmpBtn message handlers

BOOL CMyBmpBtn::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
// TODO: Add your message handler code here and/or call default
static HCURSOR m_hLinkCursor;

if (m_hLinkCursor == NULL) // No cursor handle
{
// Get the windows directory
CString strWndDir;
GetWindowsDirectory(strWndDir.GetBuffer(100), 100);
strWndDir.ReleaseBuffer();

strWndDir += _T("\\winhlp32.exe");
// This retrieves cursor #106 from winhlp32.exe, which is a hand pointer
HMODULE hModule = LoadLibrary(strWndDir);
if (hModule) {
HCURSOR hHandCursor = ::LoadCursor(hModule, MAKEINTRESOURCE(106));
if (hHandCursor)
m_hLinkCursor = CopyCursor(hHandCursor);
}
FreeLibrary(hModule);
}

::SetCursor(m_hLinkCursor);
return TRUE;
}

BOOL CMyBmpBtn::PreTranslateMessage(MSG* pMsg)
{
m_ToolTip.RelayEvent(pMsg);
return CButton::PreTranslateMessage(pMsg);
}

void CMyBmpBtn::SetToolTip(CString str)
{
CRect rect;
GetClientRect(rect);
m_ToolTip.Create(this);
m_ToolTip.AddTool(this, str, rect, 0);

}



////我用了着,还成:)

jadeking 2001-07-17
  • 打赏
  • 举报
回复
case
jadeking 2001-07-17
  • 打赏
  • 举报
回复
111222,多谢,关于set cursor的问题,我已经用你的方法解决了!

但为什么tooltip用这段代码,程序运行时就会报错!
"a exception breakpoint!"

另外再问你一下:我有好多个bitmapbutton,我要给它们都加上tooltip
是不是要加一个CMyBmpBtn::SetToolTip(LPCTSTR lpszTip);函数?
SmartHeart 2001-07-17
  • 打赏
  • 举报
回复
111222,你回来了?考试还好吗?很多人很关心你的
SmartHeart 2001-07-17
  • 打赏
  • 举报
回复
WM_MOUSEMOVE
nustchen 2001-07-17
  • 打赏
  • 举报
回复
至于ToolTip,可以在父窗口中响应TTN_NEEDTEXT消息就可以了。

ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )

BOOL OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
{
TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
if( (HWND)pNMHDR->idFrom == m_Button.GetSafeHwnd() )
_tcscpy( pTTT->lpszText, strHint );
......
nustchen 2001-07-17
  • 打赏
  • 举报
回复
我是在控件的父窗口里响应OnSetCursor函数,然后判断光标位置是否在控件中
BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
GetCursorPos( &ptCursor );
m_Button.GetWindowRect( &rtWindow );
if( rtWindow.PtInRect( *lpCursor ) )
......

16,472

社区成员

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

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

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