Results 1 to 12 of 12

Thread: [VB6] "Attribution" - a web link control

  1. #1

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    [VB6] "Attribution" - a web link control

    There are useful or fun RESTful Web Services that we can easily use in VB6 programs. Many are free or offer a free tier of use, but may require attribution and a link to "terms of service" or their home page. Some do not require this but it might be good manners to do so.

    Easy enough for a web mashup, but more effort in a desktop application. This Attribution control shows how such a thing might be accomplished.

    Here is an example of such an API: TheySaidSo Famous Quotes API

    Free usage is limited to 10 requests per hour, and they ask for attribution. That's possible but clunky in VB6. We could make a small browser window but here is an alternative: Attribution.cls.

    This Attribution control supports "hover highlighting" though not perfectly. If you want better mouseout detection there are alternatives you can use instead of the simplistic technique used here. Edit: altered this to use the SetCapture/ReleaseCapture API approach.

    It has properties covering their ImgSrc, HRef, displayed Text, and of course ToolTipText can be used for their "powered by" title text.


    Requirements

    VB6 to compile the Project.

    Windows Vista or later. Windows XP SP1 or later could be used if the redist version of WIA 2.0 has been previously installed.


    Interaction with the API provider

    When an instance of Attribution.ctl loads it:

    • Requests the image at ImgSrc if this property is not empty.
    • When the image is received, it is composited onto backgrounds to produce NormalImage and HighlightImage.
    • NormalImage is displayed initially on the Attribution instance.


    When the Form loads it:

    • Makes a "categories" request.
    • When received successfully, it displays them in a ListBox for the user to optionally choose one from.
    • The "Get quote" button is enabled.


    When the user clicks the "Get quote" button the Form:

    • Makes a Quote Of The Day request, with or without a specified "category" depending on whether the user chose a category from the ListBox by selecting it.
    • When received successfully, it extracts several value from the response including a background picture URL.
    • Then it makes another request for the background picture.
    • When the background picture is received it paints that into a PictureBox, and then it draws the text of the quote and related information extracted from the QOD response.


    If the users clicks on Attribution a link to the API provider's site is opened in the user's default web browser.


    This was more of a "concept" Project rather than something "real." There is a lot of random stuff in this program. Maybe you can find some of it useful.
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by dilettante; Apr 27th, 2017 at 11:15 AM. Reason: updated the attachment

  2. #2
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    733

    Re: [VB6] "Attribution" - a web link control

    A good example of the network Programming

  3. #3
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    733

    Re: [VB6] "Attribution" - a web link control

    ToolTipText,can not show if mouse on the usecontrol

  4. #4

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [VB6] "Attribution" - a web link control

    Quote Originally Posted by xxdoc123 View Post
    ToolTipText,can not show if mouse on the usecontrol
    Yep, you are right!

    It looks like SetCapture breaks tooltips. I don't have a fix yet and I don't want the overhead and subclassing headache of TrackMouseEvent so I'll need to look harder at this.

    I might just have to revert to my previous "substandard" mouseout technique.

  5. #5

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [VB6] "Attribution" - a web link control

    Here is a version that reverts to the earlier, simpler behavior. At least this doesn't completely break the ToolTip popup.
    Attached Files Attached Files
    Last edited by dilettante; May 6th, 2017 at 02:02 PM. Reason: replaced attachment

  6. #6
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    733

    Re: [VB6] "Attribution" - a web link control

    very nice code .thanks .

  7. #7
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: [VB6] "Attribution" - a web link control

    Very useful learning material, thank you dilettante.

    I wonder if VB6 can also develop(provide) a web framework similar to RESTful WebService or C# Web API?

  8. #8

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [VB6] "Attribution" - a web link control

    Replaced the attachment in post #5 above.

    There were still issues with ToolTipText, and the problem was "forwarding" these values to the Image and Label inside the UserControl.

    I found issues doing that and found it easier to just use a new Title property to set the tooltip text. At the same time I changed the previous Text property to a Caption property instead. This is more consistent with normal naming of control properties of that kind.

    So while mouseout detection is flawed (we'd need subclassing to do much better) I think it works well enough for most purposes now.

  9. #9

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [VB6] "Attribution" - a web link control

    Quote Originally Posted by dreammanor View Post
    I wonder if VB6 can also develop(provide) a web framework similar to RESTful WebService or C# Web API?
    This demo program consumes a 3rd party web service, but that isn't the topic of this thread. Instead I was offering an example of how one might provide attribution when a 3rd party requests or requires it for access.


    People throw the word "framework" around using it to label everything from a code library to a bag of groceries. I'm not sure what you are asking when you choose that word which has ceased to have meaning.


    Normally a web service is provided in the context of a web server. The web server does all of the hard parts, and you just supply some application-specific logic.

    Sure, you can do this with VB6 by writing your web service as an ActiveX DLL. This gets run from a small bit of VBScript under classic ASP that is in turn run within IIS. If you didn't want any ASP script you'd have to write your VB6 code to use one of the other application APIs exposed by IIS such as CGI/FastCGI or ISAPI Extensions.

    Or you could even write the entire thing as a VB6 program, with the program itself being a web server. Since we do not have SSL support in the Winsock control you would have to use a 3rd party control that does so though if you need to support HTTPS as well as HTTP.

    There are a couple of examples of VB6 web servers here in the CodeBank.

    But it sounds like you have a question that deserves its own thread in the VB6 and Earlier Q&A forum.

  10. #10
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    733

    Re: [VB6] "Attribution" - a web link control

    i test This control also supports local images..

  11. #11
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: [VB6] "Attribution" - a web link control

    I'm sorry I didn't have a clear explanation of my problem. What I mean is how to create a simple web-api sever in VB6? or how to make a RESTful JSON API in VB6?

  12. #12

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [VB6] "Attribution" - a web link control

    Since your question is unrelated to the topic of this thread I have attempted to answer it in a new Q&A forum thread:

    RESTful JSON API in VB6?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width