Results 1 to 3 of 3

Thread: How to add or remove focus rectangle to controls

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2010
    Posts
    1

    How to add or remove focus rectangle to controls

    Here is how to remove the “Focus Rectangle” from any or all controls on a form. It can also be used, when using XP visual styles, to put the “Focus Rectangle”, back on controls, that is missing from.

    Add these declarations to the main (common) module.
    vb Code:
    1. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    2.     ByVal hwnd As Long, ByVal wMsg As Long, _
    3.     ByVal wParam As Long, lParam As Any) As Long
    4.    
    5. Public Function MakeLong(ByVal wLow As Integer, _
    6.     ByVal wHigh As Integer) As Long
    7.     MakeLong = wHigh * &H10000 + wLow
    8. End Function
    9.  
    10. Public Const WM_ChangeUIState As Long = &H127
    11. Public Const UIS_HideRectangle As Integer = &H1
    12. Public Const UIS_ShowRectangle As Integer = &H2
    13. Public Const UISF_FocusRectangle As Integer = &H1
    Now add one of these to the form load event of each form.
    vb Code:
    1. Call SendMessage(Me.hwnd, WM_ChangeUIState, _
    2.         MakeLong(UIS_HideRectangle, UISF_FocusRectangle), ByVal 0)
    3.  
    4.     Call SendMessage(Me.hwnd, WM_ChangeUIState, _
    5.          MakeLong(UIS_ShowRectangle, UISF_FocusRectangle), ByVal 0)
    If you want to be selective, you can use these commands on individual controls, instead of in the form load event. When you turn it off, it will stay off, until turned on again, and visa versa.

    IMMPORTANT NOTE Some controls, such as command buttons, list boxes, and combo boxes, etc., will work, both in design, and run time. Other controls, such as check boxes, and radio option buttons, etc., will only work at run time, i.e. You must first compile the programme, and run it from the “.EXE” file.

    They will work on standard, or XP visual style, controls, but with one exception I have found so far. When a command button has a picture loaded, it will revert to standard style, if using XP styles, and the focus rectangle will always be visible. If you don’t want it, the only way I can find round this, is to not use a command button at all, but use 2 or 3 picture boxes instead, for the normal, (focused), and pressed states. The focused state can then be just a thin black outline, around the image, the same as a normal button, with the focus rectangle removed.

    Hope this is useful to someone, Trevor.
    Last edited by Hack; Jun 7th, 2010 at 06:08 AM. Reason: Added Highlight Tags

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to add or remove focus rectangle to controls

    Moved To The CodeBank

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to add or remove focus rectangle to controls

    Interesting, didn't know about that message. Here's the official documentation.
    Recommend using the standard documented names for the constants.
    Link also describes the hierarchy applied.
    Note: WM_QUERYUISTATE returns the current setting.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width