Solved

How can I avoid focus rectangle appearing on click ?

Posted on 2001-07-02
10
202 Views
Last Modified: 2008-02-01
I have an application with small buttons which look wrong when the focus rectangle is also visible. I have seen somewhere an API call (or something) which prevents this being shown

Any ideas?

Stewart
0
Comment
Question by:nvms
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 6

Accepted Solution

by:
JonFish85 earned 50 total points
ID: 6247314
try using the DrawFocusRect() API function. I believe if you draw the rect in the same place it will erase it completely. Also, look for the KillFocus() API too... Sorry cant get you the api's now :-/
0
 

Expert Comment

by:shlomof
ID: 6247444
If it is an web application, you can do the following:

<a href="a.htm" Onfocus="blur()">Click</a>

or if it is a button:

<input type="button" value="Click" Onfocus="blur()">

enjoy it.
0
 

Author Comment

by:nvms
ID: 6247468
It is a VB 6.0 application, sorry for not clarifying that...  thanks also Jon, I shall hunt down the DrawFocusRect() call unless someone beats me to it !
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6247494
Public Declare Function DrawFocusRect Lib "user32" Alias "DrawFocusRect" (ByVal hdc As Long, lpRect As RECT) As Long
Public Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

I cant find the KillWindowFocus function :-/
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 6254615
use the Public Declare Function DrawFocusRect Lib "user32" Alias "DrawFocusRect" (ByVal hdc As Long, lpRect
As RECT) As Long
with a 0,0,0,0 rectangle to remove the focus.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:nvms
ID: 6307728
Hi

I think John Fish has got cloest, but I am a little vague on how to actually employ this function on specific (small) buttons on my form.

Public Declare Function DrawFocusRect Lib "user32" Alias "DrawFocusRect" (ByVal hdc As Long, lpRect
As RECT) As Long
Public Type RECT
       Left As Long
       Top As Long
       Right As Long
       Bottom As Long
End Type

looks good, and I take Integam's comment to specify 0,0,0,0 which seems logical but where does this fit ? In the Click sub of the button ? or when the form is loaded ? I don't mind losing ALL rectangles on this particular form

Stewart
p.s. sorry for the delay, this project was on the shelf for a few weeks
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6308696
try in the GotFocus() procedure... Also, if you dont want to bother, you can use this:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_KILLFOCUS = &H8

And in form_load:

Private Sub Form_Load()
  Me.Show
  SendMessage ControlName.hWnd, WM_KILLFOCUS, 0, 0
  '... for each control
End Sub

Now, the controls will never receive focus, as far as I can see anyway. No need for code in any other procedure I dont think...

Hope this helps!
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6729038
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6743536
There has been no activity in this question in quite some time, and it looks like it has been abandoned. As part of our ongoing mission to clean up the topic areas, a Moderator will finalize this question within the next seven (7) days. At that time, either I or one of the other Moderators will force/accept the comment of JonFish85.

DO NOT ACCEPT THIS COMMENT AS AN ANSWER. If you have further comments on this question or the recommendation, please leave them here.

Thanks,

Netminder
Community Support Moderator
Experts Exchange
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6759801
nvms,

You last logged in on 1/14/2002, and you have disregarded our requests for you to clean up your open questions. I am therefore force/accepting a comment to close this question.

Netminder
Community Support Moderator
Experts Exchange
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

Suggested Solutions

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.
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…
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…
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…

760 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