Results 1 to 5 of 5

Thread: Context Menu

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Posts
    485

    Resolved Context Menu [RESOLVED]

    Hi, I was learning this Context Menu example based on an e-book where I've been supplied with this code
    Code:
     1: void CMenusDlg:: OnContextMenu(CWnd* pWnd, CPoint point) 
     2: {
     3:     // TODO: Add your message handler code here
     4:     
     5:     ///////////////////////
     6:     // MY CODE STARTS HERE
     7:     ///////////////////////
     8: 
     9:     // Declare local variables
    10:     CMenu *m_lMenu;     // A pointer to the menu
    11:     CPoint m_pPoint;    // A copy of the mouse position
    12: 
    13:     // Copy the mouse position to a local variable
    14:     m_pPoint = point;
    15:     // Convert the position to a screen position
    16:     ClientToScreen(&m_pPoint);
    17:     // Get a pointer to the window menu
    18:     m_lMenu - GetMenu();
    19:     // Get a pointer to the first submenu
    20:     m_lMenu = m_lMenu->GetSubMenu(0);
    21:     // Show the Popup Menu
    22:     m_lMenu->TrackPopupMenu(TPM_CENTERALIGN + TPM_LEFTBUTTON,
    23:         m_pPoint.x, m_pPoint.y, this, NULL);
    24: 
    25:     ///////////////////////
    26:     // MY CODE ENDS HERE
    27:     ///////////////////////
    
    28: }
    The compilation went smoothly except there are 2 warnings on line 18 and 20.

    Nevertheless, the application runs, but when I do a right click on the form, it crashes.....

    Any idea what's wrong with it?

    Thanks for any help

    Harddisk

    PS:It's an MFC exe
    Last edited by Harddisk; Oct 10th, 2005 at 09:53 PM.

  2. #2
    amac
    Guest
    Well if this code is the same way you have it then

    Code:
    18:     m_lMenu - GetMenu();
    Its crashing because you are subtracting two pointers here instead of assigning one to the other... making it crash on the next line...

    Code:
    20:     
    m_lMenu = m_lMenu->GetSubMenu(0);
    When you try to use the invalid CMenu pointer...

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Posts
    485
    I've tried to rename either and both of the lines, but my program still crashes on right click.

    Please have a look at the particular chapter that I've attached.
    *rename to *.htm

    Thanks

    Harddisk
    Attached Files Attached Files

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Those pages are scanned with a text recognition algoritm, so code often gets mistyped, - on line 18 should be =
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Posts
    485
    It's working now, except that the context menu appears way far to the bottom right.

    Is there some wrong in my codes or the function ClientToScreen() doesnt work very well?

    Thanks a lot!

    Harddisk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width