Important alert: (current site time 7/16/2013 3:08:29 AM EDT)
 

winzip icon

Hyperlink Sample (one API function used:-)

Email
Submitted on: 2/7/2002 6:10:05 AM
By: Vlad Vissoultchev 
Level: Intermediate
User Rating: By 120 Users
Compatibility: VB 6.0
Views: 33540
author picture
(About the author)
 
     This is in response to a yesterday's submission. No timer. No Set/Release capture (almost). The trick is that windowless controls ARE capturing mouse events upon mousedown BY DESIGN. So every label, image, or custom windowless control has the capture ability build-in. Thank you VB, I just figured out how to use this. Purely as an excercise you can encapsulate this code in a windowless usercontrol. Anyway, this implementation has at least two flaws. Can you find them? :-)) UPDATED: By popular demand now supports right click context menu, OLE drag&drop (good enough), "hand" mouse cursor (with shadow on win2k!), WM_CANCELMODE (pretty decently). More API's used but still under 160 lines of code. 10x for the votes

 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :Hyperlink Sample (one API function used:-)
'**************************************
Private Declare Sub mouse_event Lib "user32"( _
ByVal dwFlags As Long, ByVal dx As Long, _
ByVal dy As Long, ByVal cButtons As Long, _
ByVal dwExtraInfo As Long)
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 12 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
2/7/2002 9:02:25 AMNiknak!!

There's me sitting there wondering how you got 4 excellent votes for this, the link only does one thing doesnt it hmm?? maybe you want to change it from "http://www.planet-source-code.com" to vote for my code!
(If this comment was disrespectful, please report it.)

 
2/7/2002 5:35:27 PMVlad Vissoultchev

:-))) yeah, you are right. "users can't read! -- joel spolsky"... sure, you don't think this will get to be the code of the month!
(If this comment was disrespectful, please report it.)

 
2/8/2002 10:07:34 AMLCensoni

Alright, i'm giving up... what are the flaws? :)
(If this comment was disrespectful, please report it.)

 
2/11/2002 1:27:02 PMGary Choma

Actually, I found 3 flaws:

1. Mouse cursor should change to a hand when cursor is over the link.

2. Right-clicking on the link should not activate it.

3. On mouse-down, hold it and drag off the link, underline goes away, but link stays red until you let the mouse button up.

I have a cursor (.cur) file that I can send to anyone interested in fixing problem #1. You just set the MouseIcon property of the label control to that file.
(If this comment was disrespectful, please report it.)

 
2/11/2002 1:45:26 PMGary Choma

Replace similar call in project with this one to fix problem #3:

Label1.ForeColor = IIf(m_bPressed And m_bOver, vbRed, IIf(m_bOver, vbBlue, vbButtonText))
(If this comment was disrespectful, please report it.)

 
2/11/2002 1:46:52 PMGary Choma

Here's 2 modified procedures to fix problem #2:

Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
If m_bEatMouseEvent Then
m_bEatMouseEvent = False
Exit Sub
End If
'--- press the link
ChangeLinkState m_bOver, True
End If
End Sub

Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'--- eat mouse event if signalled
If m_bEatMouseEvent Then
m_bEatMouseEvent = False
Exit Sub
End If
'--- fire click if mouse released over the link
If Button = 1 Then
If m_bOver Then
FireClick
End If
'--- change link color
ChangeLinkState False, False
End If
End Sub
(If this comment was disrespectful, please report it.)

 
2/11/2002 1:47:02 PMVlad Vissoultchev

1. Well i have this .cur file too. (Though it does not have shadow on win2k, what about yours?:-))

2. Yeah, probably. Should change a line to fix this :-)) Line 81 should be "If Button = vbLeftButton Then FireClick"

3. I thought that this would be more interesting. So this is BY DESIGN (i.e. i meant it to be like this). If you want the behaviour your describe change Line 31 to "Label1.ForeColor = IIf(m_bOver, IIf(m_bPressed, vbRed, vbBlue), vbButtonText)"

HTH,


p.s. What i meant as flaws was:

1. WM_CANCELMODE is not handled. Demo: press and hold the link. Press Ctrl+Esc. Move out ot the link. It stays "pressed" (red)

2. It depends ot mouse clicks to function. Demo: Open Form1. Start Notepad (restored state). Focus Notepad. Move mouse pointer over the hyperlink (so a part of it should be visible below the Notepad). Voilla: Form1 has the focus. This is because it's sending an extra mouse click to windows mouse queue :-)) this is a "design flaw" :-))
(If this comment was disrespectful, please report it.)

 
2/11/2002 1:51:08 PMGary Choma

After my enhancements, I'd give this code 5 globes ;)

And if you really want to get picky, there's no support for drag-and-drop of the link (like if you wanted to drag the link to your desktop as a shortcut).
(If this comment was disrespectful, please report it.)

 
2/12/2002 11:13:34 AMVlad Vissoultchev

check out the new updated version
(If this comment was disrespectful, please report it.)

 
6/22/2002 1:50:57 PMvbmaster

sorry, I think this doesn't deserve to be code of the month :[
If code verification thanks to PSC for add vote verification :)
(If this comment was disrespectful, please report it.)

 
7/14/2002 5:52:43 PMVlad Vissoultchev

vbmaster: relax, it wasn't! though the code has certain virtues it was clearly an experiment with users ability to discern latin letters and as a result to read message boxes :-))

</wqw>
(If this comment was disrespectful, please report it.)

 
3/31/2003 12:10:47 PMA1Programmer

Not bad at all!!! But you could also use the Form_MouseMove to handle ALL your elements MouseOut Events.
(If this comment was disrespectful, please report it.)

 
6/13/2003 2:16:30 PMJohn Weir

Thank you as was looking for this little pice of code. Well done
(If this comment was disrespectful, please report it.)

 
8/7/2003 9:08:42 PM

I have been looking for something like this for days! THANK YOU!

1. I did away with the msgbox "please vote etc" :-) and so clicking on the link calls ShellExecute immediately. But the IE window doesn't have focus. The title bar is dark blue indicating that it has focus, but when you scroll over any link on the page, nothing happens, just as if it did not have focus. You have to first click on the IE window someplace, and then all the links work normally when you mouse over them. But then the IE title bar is light blue, as if it were not in focus!! (But it is).

2. If I slowly move the cursor up to the link from under the link, the underline is displayed slightly before the cursor changes. (This is a nit that I am completely not bothered about, but just interesting…)

3. I notice that the ShellExecute nShowCmd is set to 5 and normally I use 1 (SW_SHOWNORMAL). Changing it doesn't seem to do anything – is there a difference?

PS-I gave you 5 globes!
(If this comment was disrespectful, please report it.)

 
6/3/2004 4:32:02 PMYaser Hani

Man, I'll have to kill u someday, I just finished checking another code of urs and I didn't notice that this one is also yours, I think must go and find a better thing to do, coz now I know that what I've been writing for the last 4 years was not code (compared to yours), keep the good work man.. ;-)..5 for me...
(If this comment was disrespectful, please report it.)

 
7/11/2004 7:28:59 AMquartz

hahahahahahaha
what is this very funny Give Five globes ?? ,
Now i know how you got 105 excellent votes
the work was good though .

(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.