如何在非CDialog的窗体中(如CMainFrame)中使用CToolTipCtrl,最好有简单代码 s 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 当cursor移到CMainFrame中的View时能就弹出提示啊现在只要求这样而已 现在的问题是怎样设置CToolTipCtrl::SetDelayTime在10秒以上,好像10秒以上就不筹效 现在的问题是怎样设置CToolTipCtrl::SetDelayTime在10秒以上,好像10秒以上就不筹效 To hw_hlj(微微) 还没有,我以为没人会。说出来看看,是不是自己写个新类,我现在的想法就是这样。 #if !defined(AFX_SINGLETIP_H__B1722C88_9D7D_49CD_BC94_64DE8AB2BCC1__INCLUDED_)#define AFX_SINGLETIP_H__B1722C88_9D7D_49CD_BC94_64DE8AB2BCC1__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000// SingleTip.h : header file///*用法:void CMyView::OnCreate(){ m_wndTip.Create(this,WM_USER_MESSAGE_1); m_bTipHasCreated=TRUE; }BEGIN_MESSAGE_MAP(CMyView,CView) ON_MESSAGE(WM_USER_MESSAGE_1,OnUserMessage)END_MESSAGE_MAP()LRESULT CMyView::OnUserMessage1(WPARAM wParam,LPARAM lParam){ CString* pString=(CString*) wParam; CPoint ptCursor; GetCursorPos(&ptCursor); pString.Format("cursor pos %d %d",ptCursot.x,ptCursor.y); return TRUE; // TRUE for showing tip,otherwise the tip do nothing. // also,you can add the code below to determind whether show tip or not //ScreenToClient(ptCursot); //CRect rcClient; //GetClientRect(&rcClient); //if (rcClient.PtInRect(ptCursor)) //{ // pString->Format("cursor pos %d %d",ptCursor.x,ptCursor.y); // return TRUE; //} //else // return FALSE; // do not show tip.}BOOL CMyView::PretranslateMessage(MSG* pMsg){ if (m_bTipHasCreated) m_wndTip.RelayEvent(pMsg); return CView::PretranslateMessage(pMsg);}*//////////////////////////////////////////////////////////////////////////////// CSingleTip window#define LEFT_LEAVE 3 //窗体文本左边的空白宽度#define TOP_LEAVE 3 //窗体文本上面的空白宽度class CSingleTip : public CWnd{// Constructionpublic: CSingleTip(); BOOL Create(CWnd* pParent,DWORD dwNeedTextMsg); void RelayEvent(MSG* pMsg); void SetWaitTime(int nWaitTime); void SetShowTime(int nShowTime); void SetFont(CFont* pFont);private: void Reset();// Attributespublic:private: int m_nInitDelay,m_nShowDelay; int m_nCurInit,m_nCurShow; BOOL m_bWaited; BOOL m_bShow; CPoint m_ptClientCursor; CFont* m_pFont; int m_nCharWidth,m_nCharHeight; CWnd* m_pWndParent; DWORD m_dwNeedTextMsg; CString m_strWndText; // Operationspublic:// Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CSingleTip) //}}AFX_VIRTUAL// Implementationpublic: virtual ~CSingleTip(); // Generated message map functionsprotected: //{{AFX_MSG(CSingleTip) afx_msg void OnPaint(); afx_msg void OnTimer(UINT nIDEvent); //}}AFX_MSG DECLARE_MESSAGE_MAP()};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_SINGLETIP_H__B1722C88_9D7D_49CD_BC94_64DE8AB2BCC1__INCLUDED_)// SingleTip.cpp : implementation file//#include "stdafx.h"#include "ProcessLook.h"#include "SingleTip.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CSingleTipCSingleTip::CSingleTip(){ m_nInitDelay=5; m_nShowDelay=3; Reset(); m_pFont=NULL; m_pWndParent=NULL;}CSingleTip::~CSingleTip(){}BEGIN_MESSAGE_MAP(CSingleTip, CWnd) //{{AFX_MSG_MAP(CSingleTip) ON_WM_PAINT() ON_WM_TIMER() //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CSingleTip message handlersvoid CSingleTip::OnPaint() { CPaintDC dc(this); // device context for painting CRect rcClient; GetClientRect(&rcClient); CBrush brush; brush.CreateSolidBrush(RGB(255,255,111)); CBrush* pOld=dc.SelectObject(&brush); CFont* pOldFont; if (m_pFont) pOldFont=dc.SelectObject(m_pFont); dc.Rectangle(&rcClient); dc.SetBkColor(RGB(255,255,111)); dc.TextOut(LEFT_LEAVE,TOP_LEAVE,m_strWndText); dc.SelectObject(pOld); if (m_pFont) dc.SelectObject(pOldFont); // Do not call CWnd::OnPaint() for painting messages}BOOL CSingleTip::Create(CWnd* pParent,DWORD dwNeedTextMsg){ // pParent指定要显示tip的窗体(如CView CWnd等) // dwNeedTextMsg要发向pParent用于获取显示文本的用户定义消息 CRect rcWnd(0,0,100,20); LPCTSTR szClass=::AfxRegisterWndClass(0,NULL,NULL,0); if (!CWnd::CreateEx(0 ,szClass,NULL,WS_POPUP ,rcWnd,pParent,0)) return FALSE; // SetWindowPos(&wndTop,100,100,0,0,SWP_NOSIZE | SWP_NOACTIVATE); // ShowWindow(SW_SHOWNOACTIVATE); m_pWndParent=pParent; m_dwNeedTextMsg=dwNeedTextMsg; SetTimer(1,100,NULL); SetTimer(2,1000,NULL); m_nCharWidth=10; m_nCharHeight=16; return TRUE;}void CSingleTip::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default switch (nIDEvent) { case 1: if (!m_bWaited) { m_nCurInit++; if (m_nCurInit>=m_nInitDelay) { m_bWaited=TRUE; m_bShow=TRUE; m_nCurShow=0; } } break; case 2: if (m_bShow) { if (m_nCurShow==0) { if (m_pWndParent->SendMessage(m_dwNeedTextMsg,(WPARAM)&m_strWndText)==TRUE) { int nWndWidth,nWndHeight; nWndWidth=m_strWndText.GetLength() * m_nCharWidth + LEFT_LEAVE *2+ 5; nWndHeight=m_nCharHeight +TOP_LEAVE*2; SetWindowPos(&wndTop,m_ptClientCursor.x+10,m_ptClientCursor.y+10,nWndWidth,nWndHeight,SWP_NOACTIVATE); ShowWindow(SW_SHOWNOACTIVATE); } //MessageBox("!"); } if (m_nShowDelay!=-1) { m_nCurShow++; if (m_nCurShow>=m_nShowDelay) { m_bShow=FALSE; ShowWindow(SW_HIDE); } } } break; } //SetWindowPos(&wndTop,100,100,0,0,SWP_NOSIZE | SWP_NOACTIVATE); // ShowWindow(SW_SHOWNOACTIVATE); CWnd::OnTimer(nIDEvent);}void CSingleTip::RelayEvent(MSG* pMsg){ //由要显示Tip的m_pParent窗体在CWnd::WindowProc或CWnd::PretranslateMessage //调用的事件函数 switch (pMsg->message) { case WM_KEYUP: case WM_KEYDOWN: case WM_LBUTTONUP: case WM_LBUTTONDOWN: case WM_RBUTTONUP: case WM_RBUTTONDOWN: case WM_MBUTTONUP: case WM_MBUTTONDOWN: if (m_bShow) { ShowWindow(SW_HIDE); } Reset(); break; case WM_MOUSEMOVE: if (m_ptClientCursor!=pMsg->pt) { if (m_bShow) { ShowWindow(SW_HIDE); } Reset(); m_ptClientCursor=pMsg->pt; } break; } }void CSingleTip::SetFont(CFont* pFont){ //设置Tip的字体 m_pFont=pFont; CDC dc; dc.CreateCompatibleDC(NULL); CFont* pOld; pOld=dc.SelectObject(pFont); TEXTMETRIC tm; dc.GetTextMetrics(&tm); m_nCharWidth=tm.tmAveCharWidth; m_nCharHeight=tm.tmHeight+tm.tmExternalLeading; dc.SelectObject(pOld);}void CSingleTip::Reset(){ m_bWaited=FALSE; m_bShow=FALSE; m_nCurInit=0; m_nCurShow=0;}void CSingleTip::SetWaitTime(int nWaitTime){ //设置在显示Tip之前必须经厉的时间,单位 1/10秒,默认半秒 m_nInitDelay=nWaitTime;}void CSingleTip::SetShowTime(int nShowTime){ //设置Tip显示惟持的时间,单位秒,默认3秒 m_nShowDelay=nShowTime;} 实现方法基本与CMainFrame一样,到Google里找一下。 求助:动态网页中的图片获取(验证码的获取)? 在Win sock里用connect()建立起一个连接,然后一直不断开,请问这个连接能保持多久? 响应菜单,客户区接收输入问题 谁帮我解释用SendMessage发送Timer消息 关于FLOAT和CString 型的转换 请问针对HTTP或FTP连接,如何防止被盗链.....(请高手回答...一个很有难度的问题) 如何从C语言的学习走想VC? 那位来帮我翻译一下,毕业论文急用,拜托了 对话框编程遇到的问题 怪事!关于动态连接dll 关于菜单项消息的返回值问题 那里有用vc做的用于播放avi文件的原代码或书籍!
现在只要求这样而已
好像10秒以上就不筹效
好像10秒以上就不筹效
还没有,我以为没人会。说出来看看,是不是自己写个新类,我现在的想法就是这样。
#define AFX_SINGLETIP_H__B1722C88_9D7D_49CD_BC94_64DE8AB2BCC1__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// SingleTip.h : header file
///*
用法:
void CMyView::OnCreate()
{
m_wndTip.Create(this,WM_USER_MESSAGE_1);
m_bTipHasCreated=TRUE;
}BEGIN_MESSAGE_MAP(CMyView,CView)
ON_MESSAGE(WM_USER_MESSAGE_1,OnUserMessage)
END_MESSAGE_MAP()LRESULT CMyView::OnUserMessage1(WPARAM wParam,LPARAM lParam)
{
CString* pString=(CString*) wParam;
CPoint ptCursor;
GetCursorPos(&ptCursor);
pString.Format("cursor pos %d %d",ptCursot.x,ptCursor.y);
return TRUE; // TRUE for showing tip,otherwise the tip do nothing.
// also,you can add the code below to determind whether show tip or not
//ScreenToClient(ptCursot);
//CRect rcClient;
//GetClientRect(&rcClient);
//if (rcClient.PtInRect(ptCursor))
//{
// pString->Format("cursor pos %d %d",ptCursor.x,ptCursor.y);
// return TRUE;
//}
//else
// return FALSE; // do not show tip.
}BOOL CMyView::PretranslateMessage(MSG* pMsg)
{
if (m_bTipHasCreated)
m_wndTip.RelayEvent(pMsg);
return CView::PretranslateMessage(pMsg);
}*/
/////////////////////////////////////////////////////////////////////////////
// CSingleTip window
#define LEFT_LEAVE 3 //窗体文本左边的空白宽度
#define TOP_LEAVE 3 //窗体文本上面的空白宽度class CSingleTip : public CWnd
{
// Construction
public:
CSingleTip(); BOOL Create(CWnd* pParent,DWORD dwNeedTextMsg);
void RelayEvent(MSG* pMsg);
void SetWaitTime(int nWaitTime);
void SetShowTime(int nShowTime);
void SetFont(CFont* pFont);
private:
void Reset();
// Attributes
public:private:
int m_nInitDelay,m_nShowDelay;
int m_nCurInit,m_nCurShow;
BOOL m_bWaited;
BOOL m_bShow;
CPoint m_ptClientCursor; CFont* m_pFont;
int m_nCharWidth,m_nCharHeight;
CWnd* m_pWndParent;
DWORD m_dwNeedTextMsg;
CString m_strWndText;
// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSingleTip)
//}}AFX_VIRTUAL// Implementation
public:
virtual ~CSingleTip(); // Generated message map functions
protected:
//{{AFX_MSG(CSingleTip)
afx_msg void OnPaint();
afx_msg void OnTimer(UINT nIDEvent);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_SINGLETIP_H__B1722C88_9D7D_49CD_BC94_64DE8AB2BCC1__INCLUDED_)
// SingleTip.cpp : implementation file
//#include "stdafx.h"
#include "ProcessLook.h"
#include "SingleTip.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CSingleTipCSingleTip::CSingleTip()
{
m_nInitDelay=5;
m_nShowDelay=3;
Reset();
m_pFont=NULL;
m_pWndParent=NULL;
}CSingleTip::~CSingleTip()
{
}
BEGIN_MESSAGE_MAP(CSingleTip, CWnd)
//{{AFX_MSG_MAP(CSingleTip)
ON_WM_PAINT()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSingleTip message handlersvoid CSingleTip::OnPaint()
{
CPaintDC dc(this); // device context for painting CRect rcClient;
GetClientRect(&rcClient);
CBrush brush;
brush.CreateSolidBrush(RGB(255,255,111));
CBrush* pOld=dc.SelectObject(&brush);
CFont* pOldFont;
if (m_pFont)
pOldFont=dc.SelectObject(m_pFont);
dc.Rectangle(&rcClient);
dc.SetBkColor(RGB(255,255,111));
dc.TextOut(LEFT_LEAVE,TOP_LEAVE,m_strWndText);
dc.SelectObject(pOld);
if (m_pFont)
dc.SelectObject(pOldFont);
// Do not call CWnd::OnPaint() for painting messages
}BOOL CSingleTip::Create(CWnd* pParent,DWORD dwNeedTextMsg)
{
// pParent指定要显示tip的窗体(如CView CWnd等)
// dwNeedTextMsg要发向pParent用于获取显示文本的用户定义消息
CRect rcWnd(0,0,100,20);
LPCTSTR szClass=::AfxRegisterWndClass(0,NULL,NULL,0);
if (!CWnd::CreateEx(0 ,szClass,NULL,WS_POPUP ,rcWnd,pParent,0))
return FALSE;
// SetWindowPos(&wndTop,100,100,0,0,SWP_NOSIZE | SWP_NOACTIVATE);
// ShowWindow(SW_SHOWNOACTIVATE);
m_pWndParent=pParent;
m_dwNeedTextMsg=dwNeedTextMsg;
SetTimer(1,100,NULL);
SetTimer(2,1000,NULL);
m_nCharWidth=10;
m_nCharHeight=16; return TRUE;}void CSingleTip::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch (nIDEvent)
{
case 1:
if (!m_bWaited)
{
m_nCurInit++;
if (m_nCurInit>=m_nInitDelay)
{
m_bWaited=TRUE;
m_bShow=TRUE;
m_nCurShow=0;
}
}
break;
case 2:
if (m_bShow)
{
if (m_nCurShow==0)
{
if (m_pWndParent->SendMessage(m_dwNeedTextMsg,(WPARAM)&m_strWndText)==TRUE)
{
int nWndWidth,nWndHeight;
nWndWidth=m_strWndText.GetLength() * m_nCharWidth + LEFT_LEAVE *2+ 5;
nWndHeight=m_nCharHeight +TOP_LEAVE*2;
SetWindowPos(&wndTop,m_ptClientCursor.x+10,m_ptClientCursor.y+10,nWndWidth,nWndHeight,SWP_NOACTIVATE);
ShowWindow(SW_SHOWNOACTIVATE);
}
//MessageBox("!");
}
if (m_nShowDelay!=-1)
{
m_nCurShow++;
if (m_nCurShow>=m_nShowDelay)
{
m_bShow=FALSE;
ShowWindow(SW_HIDE);
}
}
}
break;
}
//SetWindowPos(&wndTop,100,100,0,0,SWP_NOSIZE | SWP_NOACTIVATE);
// ShowWindow(SW_SHOWNOACTIVATE);
CWnd::OnTimer(nIDEvent);
}void CSingleTip::RelayEvent(MSG* pMsg)
{
//由要显示Tip的m_pParent窗体在CWnd::WindowProc或CWnd::PretranslateMessage
//调用的事件函数
switch (pMsg->message)
{
case WM_KEYUP:
case WM_KEYDOWN:
case WM_LBUTTONUP:
case WM_LBUTTONDOWN:
case WM_RBUTTONUP:
case WM_RBUTTONDOWN:
case WM_MBUTTONUP:
case WM_MBUTTONDOWN:
if (m_bShow)
{
ShowWindow(SW_HIDE);
}
Reset();
break;
case WM_MOUSEMOVE:
if (m_ptClientCursor!=pMsg->pt)
{
if (m_bShow)
{
ShowWindow(SW_HIDE);
}
Reset();
m_ptClientCursor=pMsg->pt;
}
break;
}
}void CSingleTip::SetFont(CFont* pFont)
{
//设置Tip的字体
m_pFont=pFont;
CDC dc;
dc.CreateCompatibleDC(NULL);
CFont* pOld;
pOld=dc.SelectObject(pFont);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
m_nCharWidth=tm.tmAveCharWidth;
m_nCharHeight=tm.tmHeight+tm.tmExternalLeading;
dc.SelectObject(pOld);
}void CSingleTip::Reset()
{
m_bWaited=FALSE;
m_bShow=FALSE;
m_nCurInit=0;
m_nCurShow=0;
}void CSingleTip::SetWaitTime(int nWaitTime)
{
//设置在显示Tip之前必须经厉的时间,单位 1/10秒,默认半秒
m_nInitDelay=nWaitTime;
}void CSingleTip::SetShowTime(int nShowTime)
{
//设置Tip显示惟持的时间,单位秒,默认3秒
m_nShowDelay=nShowTime;
}