popup menus & its massage handling

i've crerated a floting popup menu which its items are getting to a popup menus as well. when i compile the program in a debug mode everything works well, but when i compile it in a release mode i get an access violation message. i guess that the problem is somehow related to message routing.
 thanks for any help!
matidAsked:
Who is Participating?
 
abdijConnect With a Mentor Commented:
When getting the handle of the Menu or Window donot simply get the owner. Use the functions

1> GetSafeHwnd() while getting HWND pointer.
2> GetSafeHmenu() while getting HMENU pointer
3> GetSafeHandle() while getting HGDIOBJ pointer.

The cause is invalid parent pointers.

0
 
ZoppoCommented:
Hi matid,

I once had the same problem with a popup menu within a modeless dialog. I could not solve the problem directly, only found a workaround:

CMyDialog::OnContextMenu(CWnd* pWnd, CPoint point)
{
 CMenu menu;
 // create/load menu
 ...
 UINT cmd = ::TrackPopupMenu( hMenu, TPM_RETURNCMD, point.x, point.y, 0, pWnd->m_hWnd, 0 );
 if ( cmd != 0 )
 {
  // successfully selected an item
  pWnd->SendMessage( WM_COMMAND, MAKELONG( cmd, 0 ), NULL );
 }
}

hope that helps,

ZOPPO
0
 
bhatCommented:
It will be easier to find the problem if u send the code on how u are creating the popup menu. One way of debugging such problems is to comment out certain chunk of code and see if the crash still occurs. For example, comment out OnContextMenu and if the release version works, then u have to look into OnContextMenu.
0
 
mikeblasCommented:
You need to debug your application. We can't do it for you.  If you want us to do it for you, you'll need to send along a lot more information!

As outside guesses, you might've made a mistake in declaring a message handler. Or, you might have abused the ASSERT() macro.

..B ekiM


0
 
mikeblasCommented:
> The cause is invalid parent pointers.

It is?  Why would they be valid in a debug build and not in a release build?

..B ekiM
0
All Courses

From novice to tech pro — start learning today.