Close popmenu hitself [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Close popmenu hitself [Resolved]

Post 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
Last edited by Kwai chang caine on Wed Jan 23, 2008 9:47 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post 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
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post 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
ImageThe happiness is a road...
Not a destination
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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...
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post 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.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

So what you suggest then?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post 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.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post 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
ImageThe happiness is a road...
Not a destination
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

You should fix the listview so that clicking to close a popup menu doesn't count as a click.
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post 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... :(
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post 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
ImageThe happiness is a road...
Not a destination
Post Reply