Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6612523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:06:31+00:00 2026-05-25T20:06:31+00:00

This is a sanity check because I’ve lost mine. I have a method IsCaptured()

  • 0

This is a sanity check because I’ve lost mine.

I have a method IsCaptured() which compares an enum state member to a given value and returns a bool. I use this in conjunction with a mouse threshold check to determine if a drag begin message should be sent and a drag operation begun. The problem is this is being triggered on mouse move when it shouldn’t be. I’ve added trace messages as follows:

TRACE(L"%s\n", (IsCaptured()) ? L"true" : L"false");
CPoint delta = pt - m_trackMouse;
static CPoint thresh(GetSystemMetrics(SM_CXDRAG), GetSystemMetrics(SM_CYDRAG));

if (IsCaptured() &&
    abs(delta.x) >= thresh.x || abs(delta.y) >= thresh.y)
{
    TRACE(L"%s\n", (IsCaptured()) ? L"true" : L"false");
    // Send message to enter drag mode
    bool bDrag = ::SendMessage(m_trackWnd, WM_DD_BEGIN, ::GetDlgCtrlID(m_trackWnd), (LPARAM)(void*)&m_info) != 0;

    // ...
}

Now the strange part, the output:

false
false

The method is implemented like so and m_dragState is set to NONE until there is a button down intercepted:

enum { NONE, CAPTURED, DRAGGING };
bool IsCaptured() const { return m_dragState == CAPTURED; }

I’ve tried rebuilding the entire solution to no avail. I’m running VS2010 Debug 64-bit and the program is a single threaded MFC app. What the $@#! is going on here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:06:32+00:00Added an answer on May 25, 2026 at 8:06 pm

    There’s nothing strange in your output. && has higher precedence than ||, which is why your

    if (IsCaptured() &&
        abs(delta.x) >= thresh.x || abs(delta.y) >= thresh.y)
    

    is interpreted as

    if ((IsCaptured() && abs(delta.x) >= thresh.x) || 
        abs(delta.y) >= thresh.y)
    

    I.e. if the abs(delta.y) >= thresh.y condition is met, then the result of the entire if condition does not depend on your IsCaptured() at all.

    The compiler does not care that you “expressed” your intent in line breaks. Operator precedence matters. Line breaks don’t.

    What you apparently were intending to do was

    if (IsCaptured() && 
        (abs(delta.x) >= thresh.x || abs(delta.y) >= thresh.y))
    

    Note the placement of extra braces around the operands of || subexpression.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have debugged this legacy code, and would like a sanity check on it.
Just a quick sanity check here! If I have a static method in an
This is just a sanity check, but I've done several test cases before you
My sanity check fails because a double variable does not contain the expected result,
This is more of a sanity check than anything else. I've found that when
This question is largely a sanity check. I've organized a DB by a collection
This one is for all you ALSA guys. I need a sanity check here.
I have a file with large number of columns. As a sanity check, I
I just need a sanity check here... DEMO Basically, I can't figure out how
I need a sanity check as I've spent about an hour trying to figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.