Page 1 of 1

Remove CheckboxGadget focus rectangle?

Posted: Sun Jun 23, 2019 6:34 am
by wombats
Hi,

Image

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

Re: Remove CheckboxGadget focus rectangle?

Posted: Sun Jun 23, 2019 7:56 am
by BarryG
The easiest (hack) way is just to resize the checkbox width to something like 15 with no text:

Code: Select all

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

Re: Remove CheckboxGadget focus rectangle?

Posted: Sun Jun 23, 2019 8:54 am
by VB6_to_PBx

Code: Select all

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


Re: Remove CheckboxGadget focus rectangle?

Posted: Sun Jun 23, 2019 3:39 pm
by wombats
Thank you both!

Re: Remove CheckboxGadget focus rectangle?

Posted: Mon Jun 24, 2019 12:06 am
by BarryG
For Windows, there's also the #UISF_HIDEĀ­FOCUS flag with a callback:

https://devblogs.microsoft.com/oldnewth ... 0/?p=97526