Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling private function from message handler

Status
Not open for further replies.

titanandrews

Programmer
Feb 27, 2003
130
0
0
US
Hello All,
Is it possible to call a private function ( I don't think access modifier matters ) from a message handler function. In particular, I am using OnContextMenu and within this function I want to call another member function to split up some of the logic. But my program crashes every time. Right now, the function doesn't do anything but return true. If I remove the call to the function, then it works okay.



many thanks,

Barry
 
If program crashes it means it is not a problem of public/private. If it was a problem of public/private, the program would not compile.

Ion Filipski
1c.bmp
 
Right! Didn't think about that. This problem is not a matter of access at all. Any ideas?
 
I just realized the problem is not calling a function at all. If I have any conditional processing within the OnContextMenu I get a crash when I call TrackPopupMenu. All I have to have is this.
Code:
if (true)
{   
    //...
    pContextMenu->InsertMenu(0,MF_ENABLED | MF_POPUP | MF_STRING | MF_BYPOSITION, reinterpret_cast<UINT> mn_a.GetSafeHmenu()), _T(&quot;Menu A&quot;)); 
    
    //mn_a is the popup CMenu I just created.
}

m_bTrackingPopupMenu = true;
pContextMenu->TrackPopupMenu(...);
m_bTrackingPopupMenu = false;

Then if I remove the if(true), it works! Very strange!

Anyone have ideas about this?


 
I ususally do it like this:
Code:
void CFoo::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	CMenu contextMenus;
	// All context menus share the same menu resource        
	contextMenus.LoadMenu(IDR_CONTEXT_MENUS);

	CMenu* cm = contextMenus.GetSubMenu(0);   // Index of the menu I want to show
	ASSERT(cm);

	cm->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, point.y, this);
}

/Per
[sub]
&quot;It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure.&quot;[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top