-
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
-
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...
-
1 Attachment(s)
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
-
Those pages are scanned with a text recognition algoritm, so code often gets mistyped, - on line 18 should be =
-
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