s

解决方案 »

  1.   

    当cursor移到CMainFrame中的View时能就弹出提示啊
    现在只要求这样而已
      

  2.   

    现在的问题是怎样设置CToolTipCtrl::SetDelayTime在10秒以上,
    好像10秒以上就不筹效
      

  3.   

    现在的问题是怎样设置CToolTipCtrl::SetDelayTime在10秒以上,
    好像10秒以上就不筹效
      

  4.   

    To hw_hlj(微微) 
    还没有,我以为没人会。说出来看看,是不是自己写个新类,我现在的想法就是这样。
      

  5.   

    #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
    {
    // 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;
    }
      

  6.   

    实现方法基本与CMainFrame一样,到Google里找一下。