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 555095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:46:46+00:00 2026-05-13T11:46:46+00:00

I am wanting to display a context menu when a user right-clicks on an

  • 0

I am wanting to display a context menu when a user right-clicks on an item within a CListCtrl. My code is as follows:

void DatastoreDialog::OnContextMenu(CWnd *pWnd, CPoint pos)
{
    // Find the rectangle around the list control
    CRect rectMainArea;
    m_itemList.GetWindowRect(&rectMainArea);
    // Find out if the user right-clicked the list control
    if( rectMainArea.PtInRect(pos) )
    {
        LVHITTESTINFO hitTestInfo;
        hitTestInfo.pt = pos;
        hitTestInfo.flags = LVHT_ONITEM;
        m_itemList.HitTest(&hitTestInfo);
        if (hitTestInfo.flags & LVHT_NOWHERE)
        {
             // No item was clicked
        }
        else 
        {
            MyContextHandler(hitTestInfo)
        }
    }
}

When I actually run the code, regardless of where I click; on an item, in empty space within the CListCtrl, anywhere else on the dialog (by removing the first if statement); hitTestInfo.flags is set to 48, which, if I’m reading this correctly, means “Below, and to the right of the whole CListCtrl”. Which doesn’t really make sense when I’m first checking if it’s within the CListCtrl.

So do I have an incorrect assumption somewhere? Is my code incorrect? Am I missing something?

As a possibly-related, or maybe not, BONUS QUESTION, both LVHT_ONITEMSTATEICON and LVHT_ABOVE are #defined as 0x08 – why is this? This may be key to my misunderstanding.

  • 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-13T11:46:47+00:00Added an answer on May 13, 2026 at 11:46 am

    I think HitTest() needs a position in client coordinates. It’s been a while since I last did this, but it doesn’t make sense to me to pass screen coordinates into a client window hit testing routine. Add m_itemList.ScreenToClient(&pos); before hitTestInfo.pt = pos; and see if that helps.

    Furthermore, note that OnContextMenu() may not be the call you’re looking for. It is called in response to (by default) shift-f10 as well. The documentation of WM_CONTEXTMENU is (on reading it diagonally, I don’t remember how it works from when I last did this) not very clear on what the content of ‘pos’ will be in that case; you may need to do an explicit GetCursorPos() to handle that case. Or just show your context in WM_RBUTTONDOWN.

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

Sidebar

Ask A Question

Stats

  • Questions 315k
  • Answers 315k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can't access ViewState of one page from another page… May 13, 2026 at 11:11 pm
  • Editorial Team
    Editorial Team added an answer final declares an object reference that can't be modified, e.g.… May 13, 2026 at 11:11 pm
  • Editorial Team
    Editorial Team added an answer This is perfectly legal. You don't need the override keyword… May 13, 2026 at 11:11 pm

Related Questions

Is there a way to work out the likely size of an HTML element,
Background I'm receiving the following error when trying to render a partial view in
I'm wondering if anyone has a rationale for why web development plugins for browsers
In my ASP.Net app, which is javascript and jQuery heavy, but also uses master
I am using Google Maps API to display a map on a certain page.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.