Page 1 of 1

Get rid of the Button Focus Rectangle [SOLVED]

Posted: Thu Mar 01, 2007 4:05 am
by SkyManager
Does anybody know how to get rid of the button's focus dotted rectangle :?:

Posted: Thu Mar 01, 2007 7:18 am
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.

Posted: Thu Mar 01, 2007 8:28 am
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:

Posted: Thu Mar 01, 2007 8:33 am
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.

Posted: Thu Mar 01, 2007 10:50 am
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().

Posted: Fri Mar 02, 2007 12:56 pm
by SkyManager
Very well, if there is no alternative. I will try to create my own gadget. :?

Posted: Fri Mar 02, 2007 6:57 pm
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

Posted: Sat Mar 03, 2007 12:41 am
by SkyManager
Brilliant :lol:
Great works :!:

Posted: Sat Mar 03, 2007 5:26 pm
by Hi-Toro
Very clever... I like it.