Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Focus Rectangle

Posted on 2002-03-25
3
879 Views
Last Modified: 2012-06-21
How do I remove the focus rectangle from a Command button that's on my form?
0
Comment
Question by:inethog
3 Comments
 
LVL 39

Accepted Solution

by:
appari earned 75 total points
ID: 6895694
copy this to a bas module
'API Declarations
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

'Consts
Private Const GWL_WNDPROC = (-4)
Private Const WM_SETFOCUS = &H7

'Vars
Public StandardButtonProc As Long

Public Sub NoFocusRect(Button As Object, vValue As Boolean)
    If vValue = True Then 'Focus rect on
        'Save the adress of the standard button procedure
        StandardButtonProc = GetWindowLong(Button.hWnd, GWL_WNDPROC)
        SetWindowLong Button.hWnd, GWL_WNDPROC, AddressOf ButtonProc
    Else 'Focus rect off
        SetWindowLong Button.hWnd, GWL_WNDPROC, StandardButtonProc
    End If
End Sub

Public Function ButtonProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    'The procedure that gets all windows messages for the subclassed
    'button
    On Error Resume Next
    Select Case uMsg&
        'The button is going to get the focus
        Case WM_SETFOCUS
        'Exit the procedure The message doesn´t reach the button
        Exit Function
    End Select
    'Call the standard Button Procedure
    ButtonProc = CallWindowProc(StandardButtonProc, hWnd&, uMsg&, wParam&, lParam&)
End Function


add this in formload

NoFocusRect command1, True

replace command1 with ur button name
0
 
LVL 6

Expert Comment

by:xSinbad
ID: 6895695
Setfocus elsewhere on another object.
0
 
LVL 1

Author Comment

by:inethog
ID: 6897081
Thanks.

That did the trick :)

Cheers,

D.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question