Visual Basic
  Home arrow Visual Basic arrow Page 3 - Magnifying The Desktop With Visual Basic
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC

Magnifying The Desktop With Visual Basic
By: Jason Brimblecombe
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 48
    2002-02-21

    Table of Contents:
  • Magnifying The Desktop With Visual Basic
  • Our magnifier app
  • Adding the code
  • Adding code to the timer
  • The magnifier in action
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Magnifying The Desktop With Visual Basic - Adding the code


    (Page 3 of 6 )

    Although there isn't a lot of code to add to our project, the code that we will add makes extensive use of the Windows API and bit blitting, which copies an image from one source to another.

    We will now step through the code that we need to add to make our magnifier function. Add the following four API declarations to the "General Declarations" section of your form (alternatively, you can download the entire app as part of our support material at the end of the article):

    Option Explicit

    Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long

    Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hdc As Long) As Long

    Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long

    Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long


    A device context (DC) is a resource that you borrow from Windows to paint, draw, or print to a form. GetDC returns the device context of a window or other device when given the object's handle. ReleaseDC frees up system resources used by a call to GetDC.

    StretchBlt is used to copy a section of an image from one device to another, and the BitBlt function performs a block transfer of a rectangular portion of an image from one device to another.

    All Windows API calls are written in extremely efficient C code, and the "Declare Function" method allows us to create a wrapper function that Visual Basic will map internally to the specified Windows API call.

    Private Declare Function GetDesktopWindow Lib "user32" () As Long

    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

    Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long


    The GetDesktopWindow function returns a handle to the desktop window, which is the area that makes up the actual desktop part of the Windows operating system. We use this handle in combination with a call to the ReleaseDC function to free the resources occupied by the call.

    GetCursorPos accepts a POINTAPI type (which we will look at in a minute) and returns the x-y co-ordinates of the mouse relative to the Windows desktop. Lastly, the GetDeviceCaps function can be used to get the value of a particular capability of a device, such as how many colors it can display, whether or not it can draw lines and circles, etc.

    Dim frmH As Long

    Dim magnify As Integer

    Private Const HORZRES = 8

    Private Const VERTRES = 10

    Private Const RDW_ERASE = &H4

    Private Const RDW_INVALIDATE = &H1

    Private Const SRCCOPY = &HCC0020

    Private Const WM_PAINT = &HF

    Private Type POINTAPI

    X As Long

    y As Long

    End Type


    Next we declare several constants that will be passed to our API calls, as well as one type, POINTAPI, which is passed to the GetCursorPos to retrieve the x-y co-ordinates of the mouse.

    That's all the code we need in the general declarations section of our form. The only other place we need to add code is to the timer. Let's do that now.

    More Visual Basic Articles
    More By Jason Brimblecombe


       · Nice article.Hope i can get away with trying it out at college :P.
     

    VISUAL BASIC ARTICLES

    - Developing an XML Web Service Using Visual S...
    - Creating an HTML File List with VB
    - Fun with Email: VB6, CDO, MAPI, and a Remote...
    - Extranet/Intranet Dictionary Cracker in VB
    - Finding Default App Icons With Visual Basic
    - Registry Fever With Visual Basic
    - Implementing An ADO Data Control With VB6
    - Printing With Visual Basic
    - MSMQ Part 1/2: Architecture and Simple Imple...
    - Magnifying The Desktop With Visual Basic
    - Sending Email With MAPI Components in Visual...
    - Two Person Chat With The Winsock Control And...
    - A Real-Time ActiveX News Control
    - Accessing the Windows API in Visual Basic







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek