An Unclickable Button

  Download Source Code and Demo Project

Environment: VC++ 5.0 (SP3) NT 4.0 (SP3), Win95

I wrote this a while back for a friend. It is basically just a normal pushbutton, except that when the user tries to click on it, it moves out of the way making it practically un-clickable.

I have no idea what anyone would ever want to use such a control in their app, apart from wanting to be extremely annoying to users (and hey - don't we all get like that on occasion?) :)

The button is just a normal button with OnMouseMove overridden: (m_nJumpDistance is the distance in pixels to jump once the mouse has moved over the control).
void CTrickButton::OnMouseMove(UINT nFlags, CPoint point) 
{
    CWnd* pParent = GetParent();
    if (!pParent) pParent = GetDesktopWindow();

    CRect ParentRect;                                   // Parent client area (Parent coords)
    pParent->GetClientRect(ParentRect);

    ClientToScreen(&point);                             // Convert point to parent coords
    pParent->ScreenToClient(&point);

    CRect ButtonRect;                                   // Button Dimensions (Parent coords)
    GetWindowRect(ButtonRect);  
    pParent->ScreenToClient(ButtonRect);
    CPoint Center = ButtonRect.CenterPoint();           // Center of button (parent coords)

    CSize CriticalSize(ButtonRect.Width()/6, ButtonRect.Height()/6);


    CRect NewButtonRect = ButtonRect;                    // New position (parent coords)

    if (point.x - CriticalSize.cx > Center.x)            // Mouse is right of center
    {
        if (ButtonRect.left > ParentRect.left + ButtonRect.Width() + m_nJumpDistance)
            NewButtonRect -= CSize(ButtonRect.right - point.x + m_nJumpDistance, 0);
        else
            NewButtonRect += CSize(point.x - ButtonRect.left + m_nJumpDistance, 0);
    }
    else if (point.x + CriticalSize.cx < Center.x)      // Mouse is left of center
    {
        if (ButtonRect.right < ParentRect.right - ButtonRect.Width() - m_nJumpDistance)
            NewButtonRect += CSize(point.x - ButtonRect.left + m_nJumpDistance, 0);
        else
            NewButtonRect -= CSize(ButtonRect.right - point.x + m_nJumpDistance, 0);
    }

    if (point.y - CriticalSize.cy > Center.y)           // Mouse is below center
    {
        if (ButtonRect.top > ParentRect.top + ButtonRect.Height() + m_nJumpDistance)
            NewButtonRect -= CSize(0, ButtonRect.bottom - point.y + m_nJumpDistance);
        else
            NewButtonRect += CSize(0, point.y - ButtonRect.top + m_nJumpDistance);
    }
    else if (point.y + CriticalSize.cy < Center.y)      // Mouse is above center
    {
        if (ButtonRect.bottom < ParentRect.bottom - ButtonRect.Height() - m_nJumpDistance)
            NewButtonRect += CSize(0, point.y - ButtonRect.top + m_nJumpDistance);
        else
            NewButtonRect -= CSize(0, ButtonRect.bottom - point.y + m_nJumpDistance);
    }

    MoveWindow(NewButtonRect);
    RedrawWindow();
    
	CButton::OnMouseMove(nFlags, point);
}

Last updated: 16 June 1998



Comments

  • thanks

    Posted by Legacy on 05/02/2003 12:00am

    Originally posted by: mahmoud

    it's good as beginner but what is the advance

    Reply
  • HaHa :)

    Posted by Legacy on 04/28/2003 12:00am

    Originally posted by: garaber

    Cute but other than a gag what would you use it for. It's cute though.

    Reply
  • button can be unclickable if

    Posted by Legacy on 05/21/2002 12:00am

    Originally posted by: Pradeep Kumar

    we can it by one of the following.
    
    1. disable the button when it get focuse;
    2. hide the button when mouse is just over the button.
    3. make button, like not having tab order.
    4. disable button when mouse over.

    Reply
  • The Unclickable clickable.

    Posted by Legacy on 08/04/2000 12:00am

    Originally posted by: BiGcOcK

    There is two ways I found the button could be clicked.
    1 Move the mouse on the button realy quickly and click
    2 Tab it to the button, Press Enter and the mouse will be right on the button.

    Reply
  • Saw s.th. similar

    Posted by Legacy on 03/29/2000 12:00am

    Originally posted by: Thorsten S.

    Hi!
    I saw something like that, where the icons of the detop were moving out of the way when the mouse approaches.
    BTW: How could I do s.th. like that? Subclassing the desktop is dangerous, everybody keeps telling me . . .
    TsT

    Reply
  • don't forget to clear the tab stop property :)

    Posted by Legacy on 09/15/1999 12:00am

    Originally posted by: Ivailo Bardarov

    don't forget to clear the tab stop property :)

    Reply
  • also seen the button

    Posted by Legacy on 04/28/1999 12:00am

    Originally posted by: beavis

    I have seen the button on the clinton survey-liked it so much i thought of my own theme-sent by your significant other to see if you have been faithful. just try to push yes-was funny.
    I am not much of a programmer though, but trying to learn. but did figure out how to open it and change the text.

    Reply
  • I've seen this in use

    Posted by Legacy on 03/20/1999 12:00am

    Originally posted by: Dave Williss

    A few months ago, a friend sent me a program that
    actually used this. It came up with a dialog titled
    "Slick Willie's idea of a fair public opinion survey..."
    It pretended to be from Bill Clinton and asked if
    he should resign and leave public office in shame.
    The "yes" button jummpd around so you couldn't click
    it (And if you managed to do so, it did nothing).
    The "no" button thanked you for your honest opinion.
    It was good for a laugh.

    I find it ironic that as I type this, the banner ad at
    the top of the page is for personalized email addresses
    and the example it gives is "monica@saintly.com" They
    certianly wern't thinking of Lewinsky :-)

    Reply
  • Really funny !!

    Posted by Legacy on 03/19/1999 12:00am

    Originally posted by: T.S.Venkateswaran

    Hi
    I've allways wondered abt. creating such apps.
    This one is real fun !
    Hope it keeps users busy ;-))
    Pls. keep posting such 'interesting' stuffs.

    Cheers
    ~,|,~
    tsV

    Reply
  • it has to be

    Posted by Legacy on 02/26/1999 12:00am

    Originally posted by: jay

    It has to be clickable, otherwise, what about keyboard input?

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • With 81% of employees using their phones at work, companies have stopped asking: "Is corporate data leaking from personal devices?" and started asking: "How do we effectively prevent corporate data from leaking from personal devices?" The answer has not been simple. ZixOne raises the bar on BYOD security by not allowing email data to reside on the device. In addition, Zix allows employees to maintain complete control of their personal device, therefore satisfying privacy demands of valued employees and the …

  • Available On-Demand Today's changing workforce dynamics, economic challenges, and technological advances are placing immense pressure on business leaders to turn their focus on people – their most valuable asset – in order to remain competitive. Research shows that a significant number of new employees quit within one year of taking a new job*. Whether it's through a merger and acquisition, or standard hiring process, like any first impression, early experiences shape their opinions of their new …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds