Remove CheckboxGadget focus rectangle?

Windows specific forum
wombats
Enthusiast
Enthusiast
Posts: 663
Joined: Thu Dec 29, 2011 5:03 pm

Remove CheckboxGadget focus rectangle?

Post by wombats »

Hi,

Image

Is it possible to remove the focus rectangle from a CheckboxGadget?
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Remove CheckboxGadget focus rectangle?

Post 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
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 617
Joined: Mon May 09, 2011 9:36 am

Re: Remove CheckboxGadget focus rectangle?

Post 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

 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
wombats
Enthusiast
Enthusiast
Posts: 663
Joined: Thu Dec 29, 2011 5:03 pm

Re: Remove CheckboxGadget focus rectangle?

Post by wombats »

Thank you both!
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Remove CheckboxGadget focus rectangle?

Post by BarryG »

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

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