Loading ...
Sorry, an error occurred while loading the content.
 

Re: Problem with MenuSelect

Expand Messages
  • Dennis K. Paulsen
    Hi, Upon experimenting with this on a simple MFC AppWizard generated MDI application (with child maximized), I also witnessed the crash... By adding the
    Message 1 of 2 , May 30, 2003
      Hi,

      Upon experimenting with this on a simple MFC AppWizard generated MDI
      application (with child maximized), I also witnessed the crash...
      By adding the "minfo.fType == MFT_STRING" line to the existing if()
      block of Win32::GUITest (v1.49.2)'s GetMenuItemIndex, resolved the
      issue for me.

      Example Fix:

      if (GetMenuItemInfo(hm, mi, TRUE, &minfo) &&
      minfo.fType == MFT_STRING && /* << Here is the new line */
      minfo.dwTypeData != NULL &&
      strnicmp(minfo.dwTypeData, sitem, strlen(sitem)) == 0) {
      /* Got what we came for, so return index. */
      RETVAL = mi;
      break;
      }

      Ernesto, please consider adding this change into a future version of
      Win32::GuiTest.

      Thanks,
      Dennis K. Paulsen

      --- In perlguitest@yahoogroups.com, "timhood40" <timhood40@y...>
      wrote:
      > Anybody else having a problem with MenuSelect?
      >
      > I'm using "Win32-GuiTest-1.49.2".
      >
      > For me it works fine on SDI applications such as Notepad and on
      MDI
      > applications where the documents are not maximised but crashes
      when I
      > use it with MDI applications where the documents are maximised.
      >
      > When the documents are maximised the first menu item appears to be
      an
      > icon or bitmap rather than a string. When this is the case the
      > function GetMenuItemIndex appears to crash.
      >
      > The code below is an amended version of GetMenuItemIndex which
      seems
      > to work under Visual C++?
      >
      > Anybody have a view on this?
      >
      > ---------------------------------------------
      >
      >
      > void CMainFrame::OnEditDummy()
      > {
      > CString menuItem = "&View";
      >
      > HMENU hm = GetMenu() ->GetSafeHmenu();
      > const int INDEX = GetMenuItemIndex( hm, ( char* ) ( LPCSTR )
      > menuItem );
      >
      > CString msg;
      > msg.Format( "GetMenuItemIndex of (%s) = (%d)", menuItem,
      INDEX );
      > AfxMessageBox( msg );
      > }
      >
      > int CMainFrame::GetMenuItemIndex( HMENU hm, char *sitem )
      > {
      > int mi = 0;
      > int mic = 0;
      > MENUITEMINFO minfo;
      > char buff[ 256 ] = ""; /* Menu Data Buffer */
      > BOOL found = FALSE;
      >
      > int RETVAL = -1;
      >
      > mic = GetMenuItemCount( hm );
      > if ( mic != -1 )
      > {
      > /* Look at each item to determine if it is the one we want
      */
      > for ( mi = 0; mi < mic; mi++ )
      > {
      > // first find out what type of item we've got
      > memset( buff, 0, sizeof( buff ) );
      > minfo.cbSize = sizeof( MENUITEMINFO );
      > minfo.fMask = MIIM_TYPE;
      > minfo.dwTypeData = NULL;
      > minfo.cch = 0;
      >
      > // quit if can't get the info
      > if ( ! GetMenuItemInfo( hm, mi, TRUE, &minfo ) )
      > {
      > break;
      > }
      >
      > // only interested in strings
      > if ( minfo.fType && MFT_STRING == 0 )
      > {
      > continue;
      > }
      >
      > // okay so get string data
      > memset( buff, 0, sizeof( buff ) );
      > minfo.cbSize = sizeof( MENUITEMINFO );
      > minfo.fMask = MIIM_DATA | MIIM_TYPE;
      > minfo.dwTypeData = buff;
      > minfo.cch = sizeof( buff );
      >
      > if ( GetMenuItemInfo( hm, mi, TRUE, &minfo ) &&
      > minfo.dwTypeData != NULL &&
      > strnicmp( minfo.dwTypeData, sitem, strlen(
      > sitem ) ) == 0 )
      > {
      > /* Got what we came for, so return index. */
      > RETVAL = mi;
      > break;
      > }
      > }
      > }
      > return RETVAL;
      > }
    Your message has been successfully submitted and would be delivered to recipients shortly.