Opening menu programmaticaly

Is there a way to open a menu programmatically? For example, by pressing a button on the toolbar I would like the Edit menu to unfold???
ChristianParentAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ZoppoConnect With a Mentor Commented:
Because I do not have a Windows 9x to test it I can only suggest you to try following:

1. split the first call of mouse_event into two calles, the first with the flag MOUSEEVENTF_MOVE, the second with the flag MOUSEEVENTF_LEFTDOWN

2. If 1.) does not work you can try to use PostMessage( WM_NCLBUTTONDOWN, ...) and PostMessage( WM_NCLBUTTONUP, ...) with hitTest flag HTMENU and screencorrdiantes which are used to calculate x and y in my posted code.

Perhaps you can also try to simulate an ALT-E via keyb_event ...

ZOPPO
0
 
V_BapatCommented:
Interesting. I am listening.
0
 
ZoppoCommented:
Hi ChristianParent,

you can try something like this:

void CMainFrame::OnButtonMedit()
{
 CMenu *pSubMenu, *pMenu = GetMenu();
 ASSERT ( pMenu );
 CString menuName;

 BOOL bFound = FALSE;
 for ( UINT i = 0; i < pMenu->GetMenuItemCount(); i++ )
 {
  pMenu->GetMenuString( i, menuName, MF_BYPOSITION );
  if ( menuName == "&Edit" )
  {
   bFound = TRUE;
   break;
  }
 }
 if ( !bFound )
 {
  // '&Edit' menu not found, do nothing
  return;
 }
 pSubMenu = pMenu->GetSubMenu( i );
 RECT rect;
 
 GetMenuItemRect( m_hWnd, pMenu->m_hMenu, i, &rect );

 DWORD pt = MAKELONG( rect.left + 4, rect.top + 4 );

 int x = 0xFFFF / GetSystemMetrics( SM_CXSCREEN ) * ( rect.left + ( rect. right - rect.left ) / 2 );
 int y = 0xFFFF / GetSystemMetrics( SM_CYSCREEN ) * ( rect.top + ( rect.bottom - rect.top ) / 2 );

 mouse_event( MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTDOWN, x, y, 0, 0 );
}

hope that helps,

ZOPPO
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
ChristianParentAuthor Commented:
This position the cursor over the right menu, but does not open it. After that, I cannot 'click' on any applications anymore and I have to kill my application in order to regain control of my computer
0
 
ZoppoCommented:
I've tested the above code with WinNt4 Sp5 and it works. What OS do you use?

Add following line at the end, perhaps this even work with Win95:
mouse_event( MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_LEFTUP, x, y, 0, 0 );

ZOPPO
0
 
ChristianParentAuthor Commented:
I do use Win95, the above comment corrected the 'locking' problem, but the menu still does not open... Any other ideas?
0
All Courses

From novice to tech pro — start learning today.