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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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
ZoppoCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.