The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: zemtex on July 28, 2011, 11:52:07 PM

Title: Get rid of button focus dotted dashed rectangle
Post by: zemtex on July 28, 2011, 11:52:07 PM
How do you remove or change style of the dotted selection bar on pushbuttons? I think that it is a userfriendly feature, but in my situation I think that it is nice to have only a black underlying rectangle around the button instead of the dotted rectangle inside the button frame.

Can I remove it entirely, if not can I change the style of it?
Title: Re: Remove button selection
Post by: Twister on July 29, 2011, 12:36:47 AM
I think you are talking about the focusing of a control. Could you possibly take a screen-shot?

You can do this by immediately remove focus of the control after clicking/double-click.
Title: Re: Remove button selection
Post by: zemtex on July 29, 2011, 12:54:36 AM
I am talking about focus styles, the inner dotted rectangle on the button and you also have a black solid rectangle on the outer layer. I want to keep the black one, the dotted needs to go as it clutters the screen and makes it harder to read the button text.
I've had it working many times before but I have just forgot what I did  :snooty:

Horton: Removing focus from the control requires that I remove IsDialogMessage for handling keyboard with controls. It sounds a bit dirty  :dazzled:

Here is a random google picture, the right button has dashed/dotted rectangle

(http://www.yevol.com/en/windows/images/focus1.gif)
Title: Re: Remove button selection
Post by: baltoro on July 29, 2011, 12:59:13 AM
The most aesthetically satisfying solution to your problem would be to create your own custom bitmap of the buttom and paint it in the appropriate location.
Of course, you'd have to write the code to make it completely dysfunctional,... :bg
Title: Re: Remove button selection
Post by: hutch-- on July 29, 2011, 02:19:28 AM
zemtex,

The standard buttons have that characteristic built into them, to do it differently you create a custom control or use a bitmap control instead.

There is a custom bitmap control in the MASM32 library, you provide 2 bitmaps, one up, the other down.
Title: Re: Remove button selection
Post by: zemtex on July 29, 2011, 03:06:17 AM
hutch, I checked the bmbutton sample, the dotted rectangle is visible as you click the button but I suppose you didn't paint the edges? A different problem is when you switch windows theme and the buttons have the same look.

I can make it work by using modal dialogs and when IsDialogMessage handles keyboard internally, then it works nicely but I can not get it to work if I create window/controls manually even if I use the exact same styles. If you use modal dialogs and resource files you will notice the dotted rectangle is gone even if you push a button, but as soon as you hit the tab key the dotted rectangle appear again.


EDIT: Solved it, I added an xp manifest and somehow the buttons now dont have dotted rectangle. It will appear if you hit TAB, but I can live with that, as long as the buttons don't show the dotted rectangle by default.
Title: Re: Remove button selection
Post by: WillASM on July 29, 2011, 05:13:27 AM
Have you tried using DrawFocusRect? Perhaps that would work for you. Not at home right now so can not try this out right now..
Title: Re: Get rid of button focus dotted dashed rectangle
Post by: zemtex on July 29, 2011, 05:34:18 AM
Alright thanks all. I think I have it the way I want it.
Title: Re: Get rid of button focus dotted dashed rectangle
Post by: hutch-- on July 29, 2011, 06:28:19 AM
The BMbutton example actually uses a standard windows button with the bitmap style and it will have the focus rectangle but the library has a completely different one that does not do it that way, it simply has an UP and DOWN bitmap so you have absolute control of the appearance.

It sounds like you have solved the problem for later OS versions, (XP and later) so this may not matter to you any longer.
Title: Re: Get rid of button focus dotted dashed rectangle
Post by: xroot on July 29, 2011, 02:03:13 PM
Hi, Zemtec

To use regular contols with out the focus dots, here is what I do, it's real simple,
just a little subclass of the controls.



include \masm32\include\masm32rt.inc

.data?
hCnt      dd ?
oProc     dd ?
.data

.code

No_Dots Proc hCntl:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
    .If uMsg==WM_SETFOCUS
        ret
    .endif
    invoke CallWindowProc,oProc,hCntl,uMsg,wParam,lParam
    Ret
No_Dots endp

Msg_Proc Proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
    Switch uMsg
        Case WM_INITDIALOG
            mov hCnt,rv(GetDlgItem,hWin,IDCANCEL)
            invoke SetWindowLong,rv(GetDlgItem,hWin,69),GWL_WNDPROC,offset No_Dots
            invoke SetWindowLong,hCnt,GWL_WNDPROC,offset No_Dots
            mov oProc,eax
        Case WM_COMMAND
            .If wParam==IDCANCEL || wParam==2
                invoke EndDialog,hWin,NULL
            .EndIf
    EndSw
    xor eax,eax
    ret
Msg_Proc endp

start:
    Dialog "Test Dialog","MS Sans Serif",14,WS_OVERLAPPED or WS_MINIMIZEBOX or DS_CENTER or WS_SYSMENU,\
           3,0,0,150,100,512
    DlgButton "Exit",WS_TABSTOP,50,60,50,15,IDCANCEL
    DlgButton "Check-Button",BS_AUTOCHECKBOX,15,25,40,10,69
    DlgStatic "The MASM Forum is Cool",SS_CENTER,5,10,140,9,100
    CallModalDialog FUNC(GetModuleHandle,NULL),NULL,Msg_Proc,NULL
    invoke SetWindowLong,hCnt,GWL_WNDPROC,oProc
    exit
end start
Title: Re: Get rid of button focus dotted dashed rectangle
Post by: hutch-- on July 30, 2011, 05:18:02 AM
Compliments xroot,

That is a nice clean and simple solution to the problem and should work on older versions of Windows.
Title: Re: Get rid of button focus dotted dashed rectangle
Post by: donkey on July 30, 2011, 09:18:22 AM
I would use an owner drawn button for this, they are compaitble with all versions of Windows and returning an undefined result from WM_SETFOCUS could have some side effects, such as disabling tab selection etc.. OD buttons are very simple to work with, there is an example on my website:

http://www.quickersoft.com/donkey/files/OwnerDrawBtn.zip
Title: Re: Get rid of button focus dotted dashed rectangle
Post by: MichaelW on July 30, 2011, 11:30:32 AM
The are simple with bitmaps, but not so simple using DrawFrameControl, etc, to draw the components individually.