Solved

Focus Rectangle

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

759 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

20 Experts available now in Live!

Get 1:1 Help Now