Page 1 of 2

Close popmenu hitself [Resolved]

Posted: Wed Jan 23, 2008 1:56 pm
by Kwai chang caine
Hello at all

Is it possible to close the popmenu if the cursor of mouse is not on it ?

Image

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Menu example file
;
;    (c) 2001 - Fantaisie Software
;
; ------------------------------------------------------------
;

;
; Create the popup menu. The indent is very important here for a good lisibility
;

If CreatePopupMenu(0)
  MenuItem(1, "Cut")
  MenuItem(2, "Copy")
  MenuItem(3, "Paste")
  MenuBar()
  OpenSubMenu("Options")
    MenuItem(4, "Window...")
    MenuItem(5, "Gadget...")
  CloseSubMenu()
  MenuBar()
  MenuItem( 6, "Quit")
EndIf

;
; We just have to open a window and see when an event happen on the menu
;

If OpenWindow(0, 100, 100, 300, 260, "PureBasic - PopupMenu Example")

  Repeat

    Select WaitWindowEvent()
        
      Case #WM_RBUTTONDOWN
        DisplayPopupMenu(0, WindowID(0))
          
      Case #PB_Event_Menu
      
        Select EventMenu()  ; To see which menu has been selected

          Case 1 ; Cut
            MessageRequester("PureBasic", "Cut", 0)

          Case 2 ; Copy
            MessageRequester("PureBasic", "Copy", 0)

          Case 3 ; Paste
            MessageRequester("PureBasic", "Paste", 0)

          Case 6 ; Quit
            Quit = 1

        EndSelect
        
      Case #PB_Event_CloseWindow
        Quit = 1

    EndSelect

  Until Quit = 1

EndIf

End 
Thanks for your answer

Posted: Wed Jan 23, 2008 8:50 pm
by Fluid Byte

Code: Select all

Procedure WindowCallback(hWnd,uMsg,wParam,lParam)
    Select uMsg
        Case #WM_ENTERIDLE
		GetCursorPos_(cpt.POINT)
		
		If WindowFromPoint_(cpt\x,cpt\y) = hwnd
			EndMenu_()
		EndIf
    EndSelect
     
    ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

CreatePopupMenu(0)

MenuItem(1,"Cut")
MenuItem(2,"Copy")
MenuItem(3,"Paste")
MenuBar()
OpenSubMenu("Options")
	MenuItem(4,"Window...")
	MenuItem(5,"Gadget...")
CloseSubMenu()
MenuBar()
MenuItem(6,"Quit")

OpenWindow(0,0,0,320,240,"void",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)

SetWindowCallback(@WindowCallback())

Repeat
	EventID = WaitWindowEvent()
	
	If EventID = #WM_RBUTTONDOWN
		DisplayPopupMenu(0,WindowID(0))
	EndIf
Until EventID = #PB_Event_CloseWindow

Posted: Wed Jan 23, 2008 9:47 pm
by Kwai chang caine
Thanks a lot FLUID
It's exactly what i wanted :D

Your are an angel 8)

I wish you a very good night
Thanks again

Posted: Wed Jan 23, 2008 9:59 pm
by Trond
Now move the window all down to the bottom of the screen, and try to open the popup menu by right-clicking in the bottom of the window...

Posted: Wed Jan 23, 2008 10:07 pm
by Fluid Byte
Maybe you mean that the menu doesn't show up but that is perfectly normal. For space reasons Windows places the menu above the location you clicked. This means the mouse is right out of the menu window and thus it will be closed. You could either relocate the mouse or the menu but this is both pointless IMHO.

Posted: Wed Jan 23, 2008 10:09 pm
by Trond
I know it's normal that menu gets shown the other way, but I guess you don't want that kind of missing menu in an application.

Posted: Wed Jan 23, 2008 10:10 pm
by Fluid Byte
So what you suggest then?

Posted: Wed Jan 23, 2008 10:15 pm
by Trond
Don't close the menu when the mouse is outside it. Personally I always move my mouse outside the menu so I can read all the items without the cursor in the way. It would be a nuisance if the menu closed all the time.

Posted: Wed Jan 23, 2008 10:17 pm
by Fluid Byte
LMAO Trond! Your personal habbits are not really the issue here, you know? Image

Personally I agree with you but that's the way Kwaï wanted it.

Posted: Wed Jan 23, 2008 10:56 pm
by Trond
Yes, I know most people can read through the cursor so it's not a problem for them, but I mentioned it just in case anyway.

Posted: Thu Jan 24, 2008 12:00 am
by Kwai chang caine
I have a good reason for wanted this option.
My application have the popmenu over a listviewgadget, what do an action for only one clic.
When i right clic for appears the popmenu, and i dont left clic, he stay over my listview and that disturb me :?
The first reflex is to left clic anywhere for do disappears the popmenu and this action create an event not wanted by the user :?

I'm special, i know, i want always five-legged sheep :D
I'm knowed for this, in the french forum :wink:

Thanks at you two for your precious help.
It's again christmas, two mega programmer just for me, over my cradle of baby programmer :D

Posted: Thu Jan 24, 2008 10:55 am
by PB
> I always move my mouse outside the menu so I can read all the items

I agree with Trond here. The first thing I do when typing or opening a menu
is flick my mouse away so the cursor gets the hell out of the way. :)

Posted: Thu Jan 24, 2008 11:19 am
by Trond
You should fix the listview so that clicking to close a popup menu doesn't count as a click.

Posted: Thu Jan 24, 2008 2:58 pm
by superadnim
You know, you can tell Windows to hide the cursor when typing ;)
That's how I have it setup but I still have a slight reflex to go grab the mouse and push it... :(

Posted: Thu Jan 24, 2008 3:02 pm
by Kwai chang caine
You should fix the listview so that clicking to close a popup menu doesn't count as a click.
It's a good idea :D
Thats why you are a "big boss" of the programmation, obviously 8)

My empire for 10% of your knowledge :wink:

I have installed the good code of FLUID now, and i have happy to the
effect. :D
But for the next time, i use this great idea.

Thanks at all, for your precious help.

I am proud to tell you every day. :D
You can not imagine what purebasic and all of you, gave me in life. 8)
I could never thank you enough