Thread: Context Menu cursor problem

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    2

    Context Menu cursor problem

    Hi,

    I was wondering if anyone else has seen this problem:

    When I right click and open up a context menu in a CWnd sub-classed dialog, then go into a submenu my mouse cursor goes from the arrow to the hourglass and never reverts back to the arrow cursor until after I close the dialog box.

    It doesn't seem to matter which way I create the menu (either through resources or purely by code) and I have tried overwritting the OnSetCursor function which always sets the mouse to the arrow.

    I know that OnSetCursor is being called because outside of a menu the cursor is not an arrow.

    Here is the sample of my code:

    for cursor override:
    <pre>
    BOOL CCMFrame::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
    {

    if (message == 0) // owner is in menu mode
    {
    // only set the cursor if the object open is a menu.
    HCURSOR hCursor = LoadCursor(NULL, IDC_ARROW);
    SetCursor(hCursor);
    return TRUE;
    }

    return CWnd::OnSetCursor(pWnd, nHitTest, message);
    }
    </pre>

    for menu creation:

    <pre> CMenu mnuTop;
    mnuTop.LoadMenu(IDR_POPUP_MENU);

    CMenu* pPopup = mnuTop.GetSubMenu(0);
    ASSERT_VALID(pPopup);

    pPopup->TrackPopupMenu(TPM_RIGHTBUTTON |
    TPM_LEFTALIGN, Point.x, Point.y, this, NULL);

    </pre>


    Thank you for any insight into what could be causing this!!

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    zip up your project and attach it.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Use code tags.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    2

    sorry for the previous format.... here it is with code tags

    // code for the cursor override

    Code:
    BOOL MyFrame::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
    {
    
        if (message == 0) // owner is in menu mode
          {
            // only set the cursor if the object open is a menu.
            HCURSOR	 hCursor = LoadCursor(NULL, IDC_ARROW);
            SetCursor(hCursor);
            return TRUE;
          }
    
        return CWnd::OnSetCursor(pWnd, nHitTest, message);
    }
    for menu creation:

    Code:
             CMenu mnuTop;
              mnuTop.LoadMenu(IDR_POPUP_MENU);
    
              CMenu* pPopup = mnuTop.GetSubMenu(0);
              ASSERT_VALID(pPopup); 
    
              pPopup->TrackPopupMenu(TPM_RIGHTBUTTON |
                                   TPM_LEFTALIGN, Point.x, Point.y, this, NULL);

    Sorry, I can't include the whole project (much too big)

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    well either post it anyway or a small excert that can reproduce and illustrate the problem. If i cant run a debugger thru it i cant find your problem. Good luck.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Double click for context menu?
    By mepaco in forum Windows Programming
    Replies: 1
    Last Post: 12-19-2002, 06:17 PM
  4. context menu
    By larry in forum Windows Programming
    Replies: 2
    Last Post: 02-18-2002, 01:54 PM