Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Focus Rectangle

Posted on 2002-03-25
3
Medium Priority
?
894 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
[X]
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
3 Comments
 
LVL 39

Accepted Solution

by:
appari earned 300 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
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 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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

715 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