IonicWind Software

IWBasic => General Questions => Topic started by: Andy on October 25, 2017, 01:07:19 AM

Title: Detecting when a context menu is open
Post by: Andy on October 25, 2017, 01:07:19 AM
I'm just trying to tidy a few thing up in my reg viewer program and I'm wondering how you detect if a context menu is open or not.

So is there a way to detect if a context menu is open / showing on screen, and likewise if it's been closed i.e. by moving away / clicking elsewhere?

Thanks,
Andy.
Title: Re: Detecting when a context menu is open
Post by: Andy on October 25, 2017, 01:26:04 AM
It's okay,

I found a way via the timer section of the window's handler.

if mousedown(1) then CMenu = 0

'Right click on registry path description
IF ControlRClick(win,12) and WindowHasFocus(win)
CMenu = 1
POINT cursor3
GetCursorPos(cursor3)
ScreenToClient(win.hwnd, cursor3)
CONTEXTMENU win,cursor3.x, cursor3.y
  MENUITEM "Export key",0,2002
  separator
  MENUITEM "Copy key name",0,110
  separator
  MENUITEM "Copy key details",0,111
ENDMENU
endif


The variable CMenu remain at 1 until you click on anything else, then it goes back to zero.
Title: Re: Detecting when a context menu is open
Post by: Egil on October 25, 2017, 01:49:24 AM
Maybe I'm missing something Andy, but I do not understand why you have to make things so complicated.
The few times I have used contextmenues myself, the menues has closed by itself as soon as I clicked on a menu choise or clicked somewhere else in the main window.

Here is an example, it is called from the main loop using this code:

CASE @IDRBUTTONUP
CMenu(win)



And then the sub:

SUB CMenu(wnd:window)
'-------------------------------------------------------------------------------- 
' Context menu   
'--------------------------------------------------------------------------------
CONTEXTMENU win,@MOUSEX,@MOUSEY
menuitem "Start UDP Receive",1,30
menuitem "Stop  UDP Receive",1,31
SEPARATOR
' menuitem "Change Map",1,10
' SEPARATOR
menuitem "Set PC-HFDL log Directory",1,20
menuitem "Set Home position",1,22
menuitem "Set Ground Station Positions",1,23
menuitem "Set UDP Port",1,24
BEGINPOPUP "Adjust Brightness"
menuitem "Darker",1,30
menuitem "Brighter",1,31
ENDPOPUP
SEPARATOR
menuitem "Save Setup",1,40
SEPARATOR
menuitem "About",1,50
menuitem "Help",0,51
SEPARATOR
menuitem "Start DEMO",1,90
menuitem "End Program",0,99
ENDMENU
RETURN
ENDSUB



So why do you have to check if it is still open?


Egil

Title: Re: Detecting when a context menu is open
Post by: Andy on October 25, 2017, 05:31:16 AM
Egil,

I'm using my mouse over controls include file to make buttons slightly larger when the mouse is over any of them.

Now when I added in a right click on a static (which gives you the full path of the registry key you are viewing) I found the context menu was over some of the buttons. If you then moved the mouse up or down the context menu to a position where (although the context menu was over these buttons), the mouse was over any of these buttons location they enlarged - and I wanted to disable that situation.

In other words, although the context menu was masking the buttons, the buttons were still enlarging and I wanted to stop that when the context menu was open.

Sounds complicated I know.

Title: Re: Detecting when a context menu is open
Post by: Egil on October 25, 2017, 06:58:44 AM
QuoteSounds complicated I know.

Think I wait and see what you post when you have finished the program....


Egil
Title: Re: Detecting when a context menu is open
Post by: ckoehn on October 26, 2017, 06:08:45 AM
QuoteIn other words, although the context menu was masking the buttons, the buttons were still enlarging

I know what you mean Andy.  I have a program where a menu is dropped down and when I click a menu item, it clicks the form underneath the menu item.  Quite frustrating. I have not figured out how to stop it.  I am drawing to the form underneath it and it looks like the form is selected to receive the mouse click instead of the menu that is dropped down.

I think what you are experiencing is the same thing I am.  If you figure out how to fix it, please post what you did.  :)

Later,
Clint
Title: Re: Detecting when a context menu is open
Post by: Andy on October 26, 2017, 07:46:18 AM
Clint,

Yes I have found a solution (at least for me).

Can you give me a day or so and I'll publish something on here for you.

Just a bit busy today and tomorrow - but looking into it for you.

Cheers,
Andy.
:)
Title: Re: Detecting when a context menu is open
Post by: Andy on October 27, 2017, 12:21:12 AM
Clint,

I've posted how I did it here:

http://www.ionicwind.com/forums/index.php?topic=6045.0

Any questions, just ask away!

Andy.
:)
Title: Re: Detecting when a context menu is open
Post by: jalih on October 27, 2017, 04:43:02 AM
From MSDN using C:

FindWindowEx( NULL, NULL, MAKEINTATOM(0x8000), NULL );

Note that 0x8000 is the atom for a menu class. When an application calls this function, the function checks whether a context menu is being displayed that the application created.

You might need to substitute MAKEINTATOM macro with your own code when converting to IWB.

Have fun!
Title: Re: Detecting when a context menu is open
Post by: Andy on October 27, 2017, 05:09:37 AM
Jalih,

Yes, there are other ways to do it, the point about the mouse over controls file is that it makes it very easy to do other things with controls.

The commands are already there for you, so with just a little bit of time learning them can save you lots of time.

Andy.