Test if button has focus

Windows specific forum
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Test if button has focus

Post by IdeasVacuum »

When the mouse cursor hovers over a button, a focus rectangle is displayed around the button border. If there is a tooltip associated with the button, it is displayed.

I would like to be able to test for focus on button gadgets so that I can display my own tooltip widget. PB does not support #PB_EventType_Focus or #PB_EventType_LostFocus for ButtonGadget() or ButtonImageGadget().

Does the API deliver focus/lost focus events for buttons?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

Re: Test if button has focus

Post by Julian »

Focus isn't strictly the same as mouse over, which is what I think you're after.

Focus changes when you click on a button or TAB through buttons that allow input focus on them. Focus is defined as the item that will receive input which is different to mouse over highlighting, but I know what you mean.

You would need to track #PB_EventType_MouseEnter and #PB_EventType_MouseLeave which is also not supported by ButtonGadget.

I could quickly add this feature to my BetterButtons library if you wished?
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Test if button has focus

Post by IdeasVacuum »

Your lib looks very very interesting Julian. I have made canvas-based buttons for tiny apps where only a few buttons are required, but your 'swap a ButtonImageGadget for a BetterButton' sounds great. I don't understand your notes about using tooltips though - perhaps you could explain how/why that works and does it mean that the button cannot have a tooltip to provide the User with, erm, a tip?

Edit: Just ran your Example, that really is nice, I'm going to see how painfull it is to replace all my ImageButtons (I don't have a .pbf) :D
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

Re: Test if button has focus

Post by Julian »

I have updated to version 0.1.3 to add #B8_Event_MouseEnter and #B8_Event_MouseLeave for you.

I have made an example using button 2 in both "Example.pb" and "Example Form.pb" for you to see how the Tooltip system works a little more clearly.

Let me know if you're still running into problem and I'll bring forward the production of a tutorial video that I plan on doing for the library.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Test if button has focus

Post by IdeasVacuum »

Hi Julian

I have certainly learnt a few things from your code, but it currently does not sit well with my own code. When I find the time, I will re-write my button stuff. Keep up the good work 8)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Test if button has focus

Post by RASHAD »

Try the next

Code: Select all


OpenWindow(0,300,350,400,200,"Track Mouse Test",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget| #PB_Window_MaximizeGadget|#PB_Window_SizeGadget| #PB_Window_ScreenCentered)
ButtonGadget(1,10,10,80,20,"Test #1")
ButtonImageGadget(2,10,40,80,20,0)
TextGadget(3,10,70,80,20,"TEST 3",#SS_NOTIFY)
EditorGadget(4,10,100,200,80,0)


Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
        Quit = 1

    Case #WM_MOUSEMOVE
          GetCursorPos_ (@p.POINT) 
          ScreenToClient_ (WindowID(0), @p)
          hWnd = ChildWindowFromPoint_ (WindowID(0), p\y<< 32 + p\x)
          
          TRACK.TRACKMOUSEEVENT
          TRACK\cbSize = SizeOf(TRACK)
          TRACK\dwFlags = #TME_HOVER|#TME_LEAVE
          TRACK\hwndTrack = hWnd
          TRACK\dwHoverTime = 10
          TrackMouseEvent_(@TRACK)
                   
    Case #WM_MOUSEHOVER
         Gad =  GetDlgCtrlID_(hWnd)
         If Gad > 0
           Debug "MOUSEHOVER Gadet : "  + Str(Gad)
         EndIf
         
    Case #WM_MOUSELEAVE
         If Gad > 0
           Debug "MOUSELEAVE Gadget : " + Str(Gad)
         EndIf
  EndSelect
  
Until Quit = 1
Egypt my love
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Test if button has focus

Post by IdeasVacuum »

Hi Rashad

Now that is a very handy piece of code, thank you!
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply