Get rid of the Button Focus Rectangle [SOLVED]

Windows specific forum
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Get rid of the Button Focus Rectangle [SOLVED]

Post by SkyManager »

Does anybody know how to get rid of the button's focus dotted rectangle :?:
Last edited by SkyManager on Sat Mar 03, 2007 12:44 am, edited 1 time in total.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

It is possible to avoid the focus rectangles using ownerdraw techniques, which is quite involved, also there are existing "patched" user32.dll's floating around the internet which accomplish it. However, it is generally considered to be a mistake for a programmer to defeat them, as your app is useless to anyone who is forced (usually temporarily, for any number of unforeseen reasons) to navigate your dialogs via the keyboard alone. He just can't tell where the heck the focus is.
BERESHEIT
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Code: Select all

If GetActiveGadget(#Button)
   ActivateGadget(#AnotherGadget)
EndIf
Simply put this in your main loop. If your button retrieves the focus-state, then put the focus manually onto another gadget, e. g. a Text-Gadget or a hidden gadget. :wink:
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

AND51:

- ActivateGadget() isn't a command

- Setting the active gadget to something else on button focus makes it not just difficult to navigate with the keyboard but totally impossible as no button will ever have the focus.
BERESHEIT
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> He just can't tell where the heck the focus is

Unless one codes their own focus technique.

> ActivateGadget() isn't a command

It's in v3.94, because v4.00 renamed it to SetActiveGadget().
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post by SkyManager »

Very well, if there is no alternative. I will try to create my own gadget. :?
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

You tried subclassing yet?

Code: Select all

OpenWindow(0,0,0,400,300,"untitled",#WS_OVERLAPPEDWINDOW | 1)

CreateGadgetList(WindowID(0))

ButtonGadget(0,10,10,100,25,"nofocus1")
ButtonGadget(1,10,40,100,25,"nofocus2")
ButtonGadget(2,10,70,100,25,"nofocus3")
ButtonGadget(3,10,100,100,25,"standard")

Global lpPrevFunc.l

Procedure ButtonProc(hWnd.l,uMsg.l,wParam.l,lParam.l)
    If uMsg = #WM_SETFOCUS : ProcedureReturn 0 : EndIf 
     
    ProcedureReturn CallWindowProc_(lpPrevFunc,hWnd,uMsg,wParam,lParam)
EndProcedure

For i=0 To 2
	lpPrevFunc = SetWindowLong_(GadgetID(i),#GWL_WNDPROC,@ButtonProc())
Next

While WaitWindowEvent() ! 16 : Wend
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post by SkyManager »

Brilliant :lol:
Great works :!:
Hi-Toro
Enthusiast
Enthusiast
Posts: 270
Joined: Sat Apr 26, 2003 3:23 pm

Post by Hi-Toro »

Very clever... I like it.
James Boyd
http://www.hi-toro.com/
Death to the Pixies!
Post Reply