PureBasic Forum
https://www.purebasic.fr/english/

Remove CheckboxGadget focus rectangle?
https://www.purebasic.fr/english/viewtopic.php?f=5&t=73072
Page 1 of 1

Author:  wombats [ Sun Jun 23, 2019 6:34 am ]
Post subject:  Remove CheckboxGadget focus rectangle?

Hi,

Image

Is it possible to remove the focus rectangle from a CheckboxGadget?

Author:  BarryG [ Sun Jun 23, 2019 7:56 am ]
Post subject:  Re: Remove CheckboxGadget focus rectangle?

The easiest (hack) way is just to resize the checkbox width to something like 15 with no text:

Code:
If OpenWindow(0, 0, 0, 200, 100, "CheckBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CheckBoxGadget(0, 10,  10, 15, 20, "") ; Won't show a focus rectangle when you Tab to it.
  CheckBoxGadget(1, 10,  40, 250, 20, "CheckBox checked")
  SetGadgetState(1, #PB_Checkbox_Checked)
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Author:  VB6_to_PBx [ Sun Jun 23, 2019 8:54 am ]
Post subject:  Re: Remove CheckboxGadget focus rectangle?

Code:
Procedure No_Focus_Rectangle(HWnd, Msg, WParam, LParam)
          ;=====   HWnd   : a handle to the window to process the message for.
          ;=====   Msg    : the message to process.
          ;=====   WParam : additional information about the message.
          ;=====   LParam : additional information about the message.
  Static oldproc
  oldproc = GetProp_(HWnd, "oldproc")
  Select Msg
    Case #WM_NCDESTROY
      RemoveProp_(HWnd, "oldproc")
     
    Case #WM_SETFOCUS
      ProcedureReturn 0
  EndSelect
  ProcedureReturn CallWindowProc_(oldproc, HWnd, Msg, WParam, LParam)
EndProcedure



If OpenWindow(0, 0, 0, 200, 100, "CheckBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

  CheckBoxGadget(0, 10,  10, 250, 20, "#0 CheckBox")
  SetProp_(GadgetID(0), "oldproc", SetWindowLongPtr_(GadgetID(0), #GWL_WNDPROC, @No_Focus_Rectangle()))  ;<<--- No Focus Rectangle

  CheckBoxGadget(1, 10,  40, 250, 20, "#1 CheckBox")
  SetGadgetState(1, #PB_Checkbox_Checked)
  SetProp_(GadgetID(1), "oldproc", SetWindowLongPtr_(GadgetID(1), #GWL_WNDPROC, @No_Focus_Rectangle()))  ;<<--- No Focus Rectangle

  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf


Author:  wombats [ Sun Jun 23, 2019 3:39 pm ]
Post subject:  Re: Remove CheckboxGadget focus rectangle?

Thank you both!

Author:  BarryG [ Mon Jun 24, 2019 12:06 am ]
Post subject:  Re: Remove CheckboxGadget focus rectangle?

For Windows, there's also the #UISF_HIDEĀ­FOCUS flag with a callback:

https://devblogs.microsoft.com/oldnewthing/20171206-00/?p=97526

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/