🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
4 messages
4 total messages Started by Marc Wed, 04 Jun 2008 11:53
Canceling a popup event
#303
Author: Marc
Date: Wed, 04 Jun 2008 11:53
37 lines
1835 bytes
Hi all


I use a
    NOTIFYICONDATA  tnd;
structure to display am icon on the Taskbar in WinXP.

The icon has a self declared message WM_SYSTRAYPOPUP as call back.
    tnd.uCallbackMessage = WM_SYSTRAYPOPUP;

The message is then caught by a message map
    VCL_MESSAGE_HANDLER(WM_SYSTRAYPOPUP , TMessage, WMSysTrayPopUp)

and sent to the following function:

void __fastcall TForm::WMSysTrayPopUp(TMessage& Msg)
{
 switch (Msg.LParamLo)
 {
      case WM_RBUTTONDOWN:
               TPoint PopupPoint;
               GetCursorPos(&PopupPoint);
               PopupMenu->Popup(PopupPoint.x,PopupPoint.y);
      break;
 }
}


So far so good, the popup opens and the options can be selected.

But sometimes the user does not want to select an item, but just check which 
options are available.
How can I close the popup again WITHOUT the user clicking an option ?
EG when the user clicks somewhere outside the popup menu ?

Thanks and Regards
Marc
Re: Canceling a popup event
#305
Author: Mike Collins
Date: Wed, 04 Jun 2008 17:43
29 lines
1863 bytes
Don't know if this helps but...

I have a system tray app and i don't have that problem - i've just looked at 
the code (though i don't remember writting it lol) and i have the following:

   if (Message.Msg == WM_TRAYNOTIFY) <- this is the same as WM_SYSTRAYPOPUP
   {
      // Processes mouse events sent from the system tray
      if (Message.LParam == WM_RBUTTONUP)
      {
         /* Find the mouse cursor and popup the popupmenu at that location. 
The SetForegroundWindow
            and PostMessage calls fix an OS bug that prevents the menu from 
closing when the user
            clicks outside the menu. KB article Q135788
         */
         POINT WinPoint;
         GetCursorPos(&WinPoint);
         SetForegroundWindow(Handle);
         popSysTray->Popup(WinPoint.x, WinPoint.y);
         PostMessage(Handle, WM_NULL, 0, 0);
      }

as the comment says, there appears to be a bug in the OS - this works 
perfectly for me..

HTH

Mike C
Re: Canceling a popup event
#306
Author: Remy Lebeau (TeamB)
Date: Wed, 04 Jun 2008 18:54
32 lines
2067 bytes
"Marc" <info@mawnet.com> wrote in message 
news:48468254$1@newsgroups.borland.com...

>      case WM_RBUTTONDOWN:
>               TPoint PopupPoint;
>               GetCursorPos(&PopupPoint);
>               PopupMenu->Popup(PopupPoint.x,PopupPoint.y);

There is a well-known bug in the OS that causes such code to not dismiss the 
menu correctly if the user clicks outside the menu without selecting an 
item.  To workaround that bug, you have to use this code instead:

    case WM_RBUTTONDOWN:
    {
        TPoint PopupPoint;
        GetCursorPos(&PopupPoint);
        SetForegroundWindow(Handle); // <-- add this
        PopupMenu->Popup(PopupPoint.x,PopupPoint.y);
        PostMessage(Handle, WM_NULL, 0, 0); // <-- add this
        break;
    }

> But sometimes the user does not want to select an item, but just
> check which options are available.
> How can I close the popup again WITHOUT the user clicking an option ?

The user has to click somewhere outside the menu (once the above fix is in 
place).


Gambit 
Re: Canceling a popup event
#307
Author: Marc
Date: Thu, 05 Jun 2008 06:04
43 lines
2295 bytes
Thanks, everything is working now.

Rds
Marc




"Remy Lebeau (TeamB)" <no.spam@no.spam.com> schrieb im Newsbeitrag 
news:4846e512$1@newsgroups.borland.com...
>
> "Marc" <info@mawnet.com> wrote in message 
> news:48468254$1@newsgroups.borland.com...
>
>>      case WM_RBUTTONDOWN:
>>               TPoint PopupPoint;
>>               GetCursorPos(&PopupPoint);
>>               PopupMenu->Popup(PopupPoint.x,PopupPoint.y);
>
> There is a well-known bug in the OS that causes such code to not dismiss 
> the menu correctly if the user clicks outside the menu without selecting 
> an item.  To workaround that bug, you have to use this code instead:
>
>    case WM_RBUTTONDOWN:
>    {
>        TPoint PopupPoint;
>        GetCursorPos(&PopupPoint);
>        SetForegroundWindow(Handle); // <-- add this
>        PopupMenu->Popup(PopupPoint.x,PopupPoint.y);
>        PostMessage(Handle, WM_NULL, 0, 0); // <-- add this
>        break;
>    }
>
>> But sometimes the user does not want to select an item, but just
>> check which options are available.
>> How can I close the popup again WITHOUT the user clicking an option ?
>
> The user has to click somewhere outside the menu (once the above fix is in 
> place).
>
>
> Gambit
> 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads