15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Tray Icons and Popup Menus

John Addis -- jaddis@erols.com
Tuesday, December 10, 1996

Environment: VC++ 4.2b, NT 4.0

I'm having difficulty doing a proper popup-menu in response to a click on
my icon in the system tray. The menu is created okay and works perfectly
_if_ I select an item from the menu. However, clicking outside the menu
does *not* dismiss the menu as one would expect.

Relevant code:
--------------
 CPoint pt;
 GetCursorPos( &pt );

 CMenu mnu;
 VERIFY( mnu.LoadMenu( IDR_MAINFRAME ) );

 CMenu* pMenu = mnu.GetSubMenu( 0 );
 ASSERT( NULL != pMenu );

 pMenu->TrackPopupMenu( TPM_RIGHTALIGN|TPM_RIGHTBUTTON, pt.x, pt.y, this,
NULL );


I've also tried the following with the same results:
+ Calling TrackPopupMenu API directly
+ Passing a pointer to an empty rect instead of NULL
+ Passing a pointer to a non-empty rect instead of NULL
+ Using the "OnContextMenu" code generated by Component Gallery instead of
the above
+ Shouting obscenities

Any ideas?

--
John Addis                   http://www.xorbit.com
"Power failure; please turn your computer on."




Mike Morel -- mmorel@mushroomsoft.com
Friday, December 13, 1996

[Mini-digest: 7 responses]

John,
You must first make the owner window the foreground window.  My code looks like:
	::SetForegroundWindow(m_hWnd);  
	pMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
					mouse.x,
					mouse.y,
					this,
					NULL);

Check out KB article Q135788.

Mike Morel
mmorel@mushroomsoft.com
Mushroom Software
Home of MFC For Yourself
http://www.mushroomsoft.com


----------
From: 	John Addis[SMTP:jaddis@erols.com]
Sent: 	Tuesday, December 10, 1996 8:56 PM
To: 	mfc-l
Subject: 	Tray Icons and Popup Menus

Environment: VC++ 4.2b, NT 4.0

I'm having difficulty doing a proper popup-menu in response to a click on
my icon in the system tray. The menu is created okay and works perfectly
_if_ I select an item from the menu. However, clicking outside the menu
does *not* dismiss the menu as one would expect.

Relevant code:
--------------
 CPoint pt;
 GetCursorPos( &pt );

 CMenu mnu;
 VERIFY( mnu.LoadMenu( IDR_MAINFRAME ) );

 CMenu* pMenu = mnu.GetSubMenu( 0 );
 ASSERT( NULL != pMenu );

 pMenu->TrackPopupMenu( TPM_RIGHTALIGN|TPM_RIGHTBUTTON, pt.x, pt.y, this,
NULL );


I've also tried the following with the same results:
+ Calling TrackPopupMenu API directly
+ Passing a pointer to an empty rect instead of NULL
+ Passing a pointer to a non-empty rect instead of NULL
+ Using the "OnContextMenu" code generated by Component Gallery instead of
the above
+ Shouting obscenities

Any ideas?

--
John Addis                   http://www.xorbit.com
"Power failure; please turn your computer on."





-----From: "John Addis" 

Found the answer. It _is_ in the KB -- under Win32 SDK. Q135788.

----------
> Environment: VC++ 4.2b, NT 4.0
> 
> I'm having difficulty doing a proper popup-menu in response to a click on
> my icon in the system tray. The menu is created okay and works perfectly
> _if_ I select an item from the menu. However, clicking outside the menu
> does *not* dismiss the menu as one would expect.
> 
> Relevant code:
> --------------
>  CPoint pt;
>  GetCursorPos( &pt );
> 
>  CMenu mnu;
>  VERIFY( mnu.LoadMenu( IDR_MAINFRAME ) );
> 
>  CMenu* pMenu = mnu.GetSubMenu( 0 );
>  ASSERT( NULL != pMenu );
> 
>  pMenu->TrackPopupMenu( TPM_RIGHTALIGN|TPM_RIGHTBUTTON, pt.x, pt.y, this,
> NULL );
> 

-----From: "Dmitry A. Dulepov" 

        [Mailer: "Groupware E-Mail". Version 1.02.048]


Did you have checked \MSDEV\SAMPLES\SDK\WIN95\TRAYNOT sample from M=
SDEV ? It works OK.


Dmitry A. Dulepov
Samsung Electronics Co., Ltd.
Russian Research Center
Phone: +7 (095) 213-9207
Fax: +7 (095) 213-9196
E-mail: dima@src.samsung.ru
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

-----------------------------
>        [From: John Addis
>        [Address: jaddis@erols.com
>        [To: Dmitry A. Dulepov
>        [Date: Sat Dec 14 08:01:19 1996
>Environment: VC++ 4.2b, NT 4.0
>
>I'm having difficulty doing a proper popup-menu in response to a c=
lick on
>my icon in the system tray. The menu is created okay and works per=
fectly
>_if_ I select an item from the menu. However, clicking outside the=
 menu
>does *not* dismiss the menu as one would expect.
>
>Relevant code:
>--------------
> CPoint pt;
> GetCursorPos( &pt );
>
> CMenu mnu;
> VERIFY( mnu.LoadMenu( IDR_MAINFRAME ) );
>
> CMenu* pMenu =3D mnu.GetSubMenu( 0 );
> ASSERT( NULL !=3D pMenu );
>
> pMenu->TrackPopupMenu( TPM_RIGHTALIGN|TPM_RIGHTBUTTON, pt.x, pt.y=
, this,
>NULL );
>
>
>I've also tried the following with the same results:
>+ Calling TrackPopupMenu API directly
>+ Passing a pointer to an empty rect instead of NULL
>+ Passing a pointer to a non-empty rect instead of NULL
>+ Using the "OnContextMenu" code generated by Component Gallery in=
stead of
>the above
>+ Shouting obscenities
>
>Any ideas?
>
>--
>John Addis                   http://www.xorbit.com
>"Power failure; please turn your computer on."=

-----From: Lee 

Hi,

I just ran accross this last week, see the kb article Q135788 which is
in the vc4.2 help, just search for the number.  Basically it says:

The second problem is caused by a problem with TrackPopupMenu. It is
necessary to force a task switch to the application that called
TrackPopupMenu at some time in the near future. This can be
accomplished  by posting a benign message to the window or thread.
 
The following code will take care of all of this:
 
   SetForegroundWindow(hDlg);
 
   // Display the menu
   TrackPopupMenu(   hSubMenu,
                     TPM_RIGHTBUTTON,
                     pt.x,
                     pt.y,
                     0,
                     hDlg,
                     NULL);
 
   PostMessage(hDlg, WM_USER, 0, 0);
 


This should make it work as expected.

Lee Thompson
-----From: Carlo Arditi 

Hi John,
Add at the top of your relevant code a call to the SetForegroundWindow =
() function.

If you have a default selection in response to a double click on the =
icon of the system tray, I would like to remember you that Microsoft =
suggest to bold it in the popup-menu.
You can do this using the:
::SetMenuDefaultItem (pMenu->GetSafeHmenu (), ID_YOURDEFAULTITEM, =
FALSE);

Carlo Arditi
OLIVETTI LEXIKON S.p.A.

----------
From: 	John Addis[SMTP:jaddis@erols.com]
Sent: 	Wednesday, 11 December 1996 02:56
To: 	mfc-l
Subject: 	Tray Icons and Popup Menus

Environment: VC++ 4.2b, NT 4.0

I'm having difficulty doing a proper popup-menu in response to a click =
on
my icon in the system tray. The menu is created okay and works perfectly
_if_ I select an item from the menu. However, clicking outside the menu
does *not* dismiss the menu as one would expect.

Relevant code:
--------------
 CPoint pt;
 GetCursorPos( &pt );

 CMenu mnu;
 VERIFY( mnu.LoadMenu( IDR_MAINFRAME ) );

 CMenu* pMenu =3D mnu.GetSubMenu( 0 );
 ASSERT( NULL !=3D pMenu );

 pMenu->TrackPopupMenu( TPM_RIGHTALIGN|TPM_RIGHTBUTTON, pt.x, pt.y, =
this,
NULL );


I've also tried the following with the same results:
+ Calling TrackPopupMenu API directly
+ Passing a pointer to an empty rect instead of NULL
+ Passing a pointer to a non-empty rect instead of NULL
+ Using the "OnContextMenu" code generated by Component Gallery instead =
of
the above
+ Shouting obscenities

Any ideas?

--
John Addis                   http://www.xorbit.com
"Power failure; please turn your computer on."




-----From: "Richard Vanek" 

Hi,


> I'm having difficulty doing a proper popup-menu in response to a
click on
> my icon in the system tray. The menu is created okay and works
perfectly
> _if_ I select an item from the menu. However, clicking outside the
menu
> does *not* dismiss the menu as one would expect.
> 

Read this:

PSS ID Number: Q135788
Article last modified on 09-29-1995
 
4.00
 
WINDOWS
 

------------------------------------------------------------------------
-
The information in this article applies to:
  - Microsoft Win32 Application Programming Interface (API) included
with:
     - Microsoft Windows 95 version 4.0
------------------------------------------------------------------------
-
 
SYMPTOMS
========
 
When you display a context menu for a Notify Icon (see
Shell_NotifyIcon),
clicking anywhere besides the menu or the window that created the menu
(if
it is visible) doesn't cause the menu to disappear. When this behavior
is
corrected, the second time this menu is displayed, it displays and then
immediately disappears.
 
RESOLUTION
==========
 
To correct the first behavior, you need to make the current window the
foreground window before calling TrackPopupMenu or TrackPopupMenuEx.
 
The second problem is caused by a problem with TrackPopupMenu. It is
necessary to force a task switch to the application that called
TrackPopupMenu at some time in the near future. This can be
accomplished by
posting a benign message to the window or thread.
 
The following code will take care of all of this:
 
   SetForegroundWindow(hDlg);
 
   // Display the menu
   TrackPopupMenu(   hSubMenu,
                     TPM_RIGHTBUTTON,
                     pt.x,
                     pt.y,
                     0,
                     hDlg,
                     NULL);
 
   PostMessage(hDlg, WM_USER, 0, 0);
 
STATUS
======
 
This behavior is by design.
 
Additional reference words: 4.00
KBCategory: kbui kbprb kbcode
KBSubcategory: UsrMisc
========================================================================
=====
Copyright Microsoft Corporation 1995.

-----From: "Jeff S. Shanholtz" 

I, too, have had the same problem. If you find a solution, please let me
know; I have tried to find a solution and eventually gave up.

Jeff Shanholtz

----------
> From: John Addis 
> To: mfc-l 
> Subject: Tray Icons and Popup Menus
> Date: Tuesday, December 10, 1996 5:56 PM
> 
> Environment: VC++ 4.2b, NT 4.0
> 
> I'm having difficulty doing a proper popup-menu in response to a click on
> my icon in the system tray. The menu is created okay and works perfectly
> _if_ I select an item from the menu. However, clicking outside the menu
> does *not* dismiss the menu as one would expect.




Kashito Raiva -- raiva@unixg.ubc.ca
Monday, December 16, 1996

There's a "bug"  (Microsoft calls it a feature) in Windows 95 that requires
calling
SetForegroundWindow before calling your menu. To find out more, search for
Q135788 in MSDN.
This code should work:

  CMenu* pMenu = mnu.GetSubMenu( 0 );
  ASSERT( NULL != pMenu );
  CPoint mouse;
  GetCursorPos(&mouse);
   ::SetForegroundWindow(m_hWnd);  //m_hWnd is the handle to your main
window  
   ::TrackPopupMenu(pMenu->m_hMenu, 0, mouse.x, mouse.y, 0,
       m_hWnd, NULL);

> I'm having difficulty doing a proper popup-menu in response to a click on
> my icon in the system tray. The menu is created okay and works perfectly
> _if_ I select an item from the menu. However, clicking outside the menu
> does *not* dismiss the menu as one would expect.
> 
> Relevant code:
> --------------
>  CPoint pt;
>  GetCursorPos( &pt );
> 
>  CMenu mnu;
>  VERIFY( mnu.LoadMenu( IDR_MAINFRAME ) );
> 
>  CMenu* pMenu = mnu.GetSubMenu( 0 );
>  ASSERT( NULL != pMenu );
> 
>  pMenu->TrackPopupMenu( TPM_RIGHTALIGN|TPM_RIGHTBUTTON, pt.x, pt.y, this,
> NULL );
> 
> 

> 




| Вернуться в корень Архива |