Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - CXTTipWindow
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTTipWindow

 Post Reply Post Reply
Author
Message
Karnize View Drop Down
Newbie
Newbie
Avatar

Joined: 20 October 2003
Location: Italy
Status: Offline
Points: 19
Post Options Post Options   Thanks (0) Thanks(0)   Quote Karnize Quote  Post ReplyReply Direct Link To This Post Topic: CXTTipWindow
    Posted: 17 December 2003 at 8:04am

Hello,

I start to use your CXTTipWindow to display tooltips in my program and found some constraints. If tooltip popups near the screen border it can partly goes outside the screen, but standard Windows tooltips always shown entirely. The same problem with Windows taskbar.

There is no possibility to calculate the rect of the tooltip before it will be showed so there is no possibility to solve this problem in my sources.

It will be very good if CXTTipWindow modify the point there it will be displayed to fit the screen or you add the function to calculate the tooltip rect before show the tooltip.

Back to Top
vladsch View Drop Down
Newbie
Newbie


Joined: 04 February 2004
Location: Canada
Status: Offline
Points: 30
Post Options Post Options   Thanks (0) Thanks(0)   Quote vladsch Quote  Post ReplyReply Direct Link To This Post Posted: 05 February 2004 at 9:30pm

Hi Giovanni:

If you are interested here is the code for a derivative of CXTTipWindow that will make sure the popup fully displays (provided it is not too big to fit) on the screen. In cases where there is more than one monitor then the tip will display on the same monitor that contains the mouse pointer. Actually, I found that this is the only way to make the tip show up at all.

Ignore the class name, I pulled the code from a class that has many more mods including Notifications to parent to allow updating of the tooltip text just before displaying the tip. Hence the suffix Notify.

Header File


class _XT_EXT_CLASS CXTTipWindowNotify : public CXTTipWindow
{
public:

    // Summary: Constructs a CXTTipWindowNotify object
    CXTTipWindowNotify() { };

    // Summary: Destroys a CXTTipWindowNotify object, handles cleanup and de-allocation
    virtual ~CXTTipWindowNotify() { };
   
    // Summary: Call this member function to hide the tip window
    virtual BOOL ShowTipWindow(const CPoint& point, DWORD dwTipStyle=TWS_XT_DROPSHADOW, UINT nDelay=0, UINT nElapse=5000, BOOL bCenterHorz = FALSE);
};


CPP File
       


BOOL CXTTipWindowNotify::ShowTipWindow(const CPoint& point, DWORD dwTipStyle, UINT nDelay, UINT nElapse, BOOL bCenterHorz)
{
    BOOL bRetVal = CXTTipWindow::ShowTipWindow(point, dwTipStyle, nDelay, nElapse, bCenterHorz);

    if (bRetVal)
    {
        CRect rc;
        CRect rc2;
        CPoint pt;
        GetCursorPos(&pt);
        HMONITOR hMon = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
        MONITORINFO monInfo;
        bool bChanged = false;

        monInfo.cbSize = sizeof(monInfo);
        if (hMon && GetMonitorInfo(hMon, &monInfo))
        {
             rc = monInfo.rcMonitor;
        }
        else
        {
             // can't get mon info, just use desktop
             ::GetClientRect(::GetDesktopWindow(), &rc);
        }

        InitializeSize(m_ptMousePos, m_bCenterHorz); //Calculates m_rcScreenWindow values
        rc2 = m_rcScreenWindow;

        if (rc2.left < rc.left)
        {
             // move right
             int nDelta = rc.left - rc2.left;
             m_ptMousePos.x += nDelta;
             m_rectTipArea.right -= nDelta;
             bChanged = true;
        }
        else if (rc2.right > rc.right)
        {
             // move left
             int nDelta = rc2.right - rc.right;
             m_ptMousePos.x -= nDelta;
             m_rectTipArea.left += nDelta;

             // this is needed to make the tooltip hide as soon as you cross over the monitor boundary
             if (m_rectTipArea.right+m_ptMousePos.x > rc.right) m_rectTipArea.right = rc.right - m_ptMousePos.x;
             bChanged = true;
        }

        if (!nDelay && bChanged)
        {
             // lets move the tip it is already displayed
             InitializeSize(m_ptMousePos, m_bCenterHorz); //Calculates m_rcScreenWindow values
             SetWindowPos(&wndTop, m_rcScreenWindow.left, m_rcScreenWindow.top, m_rcScreenWindow.Width(), m_rcScreenWindow.Height(), SWP_SHOWWINDOW|SWP_NOACTIVATE);
        }
    }
    return bRetVal;
}


       

Back to Top
vladsch View Drop Down
Newbie
Newbie


Joined: 04 February 2004
Location: Canada
Status: Offline
Points: 30
Post Options Post Options   Thanks (0) Thanks(0)   Quote vladsch Quote  Post ReplyReply Direct Link To This Post Posted: 06 February 2004 at 8:00am

Noticed a bug in CXTTipWindow that does not display the drop shadow if delayed display is selected. I copied the SetWindow... line from OnTimer which has the bug. change that line in CXTTipWindowNotify::OnTimer to:

        SetWindowPos(&wndTop, m_rcScreenWindow.left, m_rcScreenWindow.top, m_rcShadow.right - m_rcWindow.left,
             m_rcShadow.bottom - m_rcWindow.top, SWP_SHOWWINDOW|SWP_NOACTIVATE);

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.