Solved

Focus Rectangle

Posted on 2002-03-25
3
873 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now