Results 1 to 5 of 5

Thread: Magnifying glass for your desktop

Threaded View

  1. #1

    Thread Starter
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Magnifying glass for your desktop

    In response to another thread I developed this little app that makes your form into a magnifying glass for your desktop. Try it out it's pretty cool.

    When the form loads, I create a memory device context to store the current contents of the desktop.
    VB Code:
    1. [FONT=Courier New][COLOR=#0000FF]Private[/COLOR] [COLOR=#0000FF]Sub[/COLOR] Form_Load()
    2.  
    3.     Me.AutoRedraw = True
    4.     ScaleFactor = 2
    5.    
    6. [COLOR=#007A00]' Create a normal DC and a memory DC for the entire screen. The
    7. ' normal DC provides a "snapshot" of the screen contents. The
    8. ' memory DC keeps a copy of this "snapshot" in the associated
    9. ' bitmap.
    10. [/COLOR]
    11. hdcScreen = CreateDC("[COLOR=#7A0000]DISPLAY[/COLOR]", vbNullString, vbNullString, 0&)
    12. [COLOR=#0000FF]If[/COLOR] hdcScreen = 0 [COLOR=#0000FF]Then
    13. [/COLOR]    MsgBox "[COLOR=#7A0000]CreateDC failed[/COLOR]"
    14.     [COLOR=#0000FF]Exit[/COLOR] [COLOR=#0000FF]Sub
    15. End[/COLOR] [COLOR=#0000FF]If
    16. [/COLOR]
    17.  
    18. hdcCompatible = CreateCompatibleDC(hdcScreen)
    19. [COLOR=#0000FF]If[/COLOR] hdcCompatible = 0 [COLOR=#0000FF]Then
    20. [/COLOR]    MsgBox "[COLOR=#7A0000]hdcCompatible failed[/COLOR]"
    21.     [COLOR=#0000FF]Exit[/COLOR] [COLOR=#0000FF]Sub
    22. End[/COLOR] [COLOR=#0000FF]If
    23. [/COLOR]
    24. ScreenWidth = GetDeviceCaps(hdcScreen, HORZRES)
    25. screenHeight = GetDeviceCaps(hdcScreen, VERTRES)
    26.  
    27. [COLOR=#007A00]' Create a compatible bitmap for hdcScreen.
    28. [/COLOR]hbmScreen = CreateCompatibleBitmap(hdcScreen, _
    29.                      ScreenWidth, _
    30.                      screenHeight)
    31.  
    32. [COLOR=#0000FF]If[/COLOR] (hbmScreen = 0) [COLOR=#0000FF]Then
    33. [/COLOR]    MsgBox "[COLOR=#7A0000]hbmScreen failed[/COLOR]"
    34.     [COLOR=#0000FF]Exit[/COLOR] [COLOR=#0000FF]Sub
    35. End[/COLOR] [COLOR=#0000FF]If
    36. [/COLOR]
    37. [COLOR=#007A00]' Select the bitmaps into the compatible DC.
    38. [/COLOR][COLOR=#0000FF]If[/COLOR] SelectObject(hdcCompatible, hbmScreen) = 0 [COLOR=#0000FF]Then
    39. [/COLOR]    MsgBox "[COLOR=#7A0000]Compatible Bitmap Selection Failed![/COLOR]"
    40.     [COLOR=#0000FF]Exit[/COLOR] [COLOR=#0000FF]Sub
    41. End[/COLOR] [COLOR=#0000FF]If
    42. [/COLOR]
    43.     UpDateImage
    44.     ZoomIn ScaleFactor
    45.    
    46. [COLOR=#0000FF]End[/COLOR] [COLOR=#0000FF]Sub[/COLOR][/FONT]
    Now, when the user holds down the left mouse button I make the form invisible and read-in the contents of the current desktop to the memory DC.
    VB Code:
    1. [FONT=Courier New][COLOR=#0000FF]Private[/COLOR] [COLOR=#0000FF]Sub[/COLOR] Form_MouseDown(Button [COLOR=#0000FF]As[/COLOR] [COLOR=#0000FF]Integer[/COLOR], Shift [COLOR=#0000FF]As[/COLOR] [COLOR=#0000FF]Integer[/COLOR], X [COLOR=#0000FF]As[/COLOR] [COLOR=#0000FF]Single[/COLOR], Y [COLOR=#0000FF]As[/COLOR] [COLOR=#0000FF]Single[/COLOR])
    2.     [COLOR=#0000FF]Select[/COLOR] [COLOR=#0000FF]Case[/COLOR] Button
    3.     [COLOR=#0000FF]Case[/COLOR] vbLeftButton
    4.         XX = X
    5.         YY = Y
    6.         UpDateImage
    7.     [COLOR=#0000FF]Case[/COLOR] vbRightButton
    8.         PopupMenu mnPopup
    9.     [COLOR=#0000FF]End[/COLOR] [COLOR=#0000FF]Select
    10. End[/COLOR] [COLOR=#0000FF]Sub
    11. [/COLOR]
    12. [COLOR=#0000FF]Sub[/COLOR] UpDateImage()
    13.     Me.Visible = False
    14.     DoEvents
    15.          [COLOR=#007A00]'Copy color data for the entire display into a
    16. [/COLOR]         [COLOR=#007A00]'bitmap that is selected into a compatible DC.
    17. [/COLOR]
    18.         [COLOR=#0000FF]If[/COLOR] BitBlt(hdcCompatible, _
    19.                0, 0, _
    20.                ScreenWidth, screenHeight, _
    21.                hdcScreen, _
    22.                0, 0, _
    23.                vbSrcCopy) = 0 [COLOR=#0000FF]Then
    24. [/COLOR]
    25.                 MsgBox "[COLOR=#7A0000]Screen to Compat Blt Failed[/COLOR]"
    26.             [COLOR=#0000FF]Exit[/COLOR] [COLOR=#0000FF]Sub
    27. [/COLOR]        [COLOR=#0000FF]End[/COLOR] [COLOR=#0000FF]If
    28. [/COLOR]    Me.Visible = True
    29.     DoEvents
    30. [COLOR=#0000FF]End[/COLOR] [COLOR=#0000FF]Sub[/COLOR][/FONT]
    When the mouse is moved with the left button down, the form is dragged across the desktop and a magnified image of the desktop below the form is copied to the from from the memory DC.
    VB Code:
    1. [FONT=Courier New][COLOR=#0000FF]Private[/COLOR] [COLOR=#0000FF]Sub[/COLOR] Form_MouseMove(Button [COLOR=#0000FF]As[/COLOR] [COLOR=#0000FF]Integer[/COLOR], Shift [COLOR=#0000FF]As[/COLOR] [COLOR=#0000FF]Integer[/COLOR], X [COLOR=#0000FF]As[/COLOR] [COLOR=#0000FF]Single[/COLOR], Y [COLOR=#0000FF]As[/COLOR] [COLOR=#0000FF]Single[/COLOR])
    2. [COLOR=#0000FF]If[/COLOR] Button = vbLeftButton [COLOR=#0000FF]Then
    3. [/COLOR]        Me.Left = Me.Left - XX + X
    4.         Me.Top = Me.Top - YY + Y
    5.         ZoomIn ScaleFactor
    6.   [COLOR=#0000FF]End[/COLOR] [COLOR=#0000FF]If
    7. End[/COLOR] [COLOR=#0000FF]Sub
    8. [/COLOR]
    9. [COLOR=#0000FF]Sub[/COLOR] ZoomIn(ZoomFactor [COLOR=#0000FF]As[/COLOR] [COLOR=#0000FF]Long[/COLOR])
    10.  [COLOR=#0000FF]Dim[/COLOR] xLeft [COLOR=#0000FF]As[/COLOR] [COLOR=#0000FF]Long[/COLOR], ytop [COLOR=#0000FF]As[/COLOR] [COLOR=#0000FF]Long
    11. [/COLOR] [COLOR=#0000FF]Dim[/COLOR] nSrcWidth [COLOR=#0000FF]As[/COLOR] [COLOR=#0000FF]Long[/COLOR], nSrcHeight [COLOR=#0000FF]As[/COLOR] [COLOR=#0000FF]Long
    12. [/COLOR] [COLOR=#0000FF]Dim[/COLOR] ScaleFactor [COLOR=#0000FF]As[/COLOR] [COLOR=#0000FF]Single
    13. [/COLOR] [COLOR=#0000FF]Dim[/COLOR] xBorder [COLOR=#0000FF]As[/COLOR] [COLOR=#0000FF]Long
    14. [/COLOR] [COLOR=#0000FF]Dim[/COLOR] yBorder [COLOR=#0000FF]As[/COLOR] [COLOR=#0000FF]Long
    15. [/COLOR] [COLOR=#0000FF]Dim[/COLOR] wndRect [COLOR=#0000FF]As[/COLOR] RECT
    16.  [COLOR=#0000FF]Dim[/COLOR] clientRect [COLOR=#0000FF]As[/COLOR] RECT
    17.  
    18.  GetWindowRect Me.hwnd, wndRect
    19.  GetClientRect Me.hwnd, clientRect
    20.  
    21. [COLOR=#007A00]'get size and location of form
    22. [/COLOR] xBorder = Round((wndRect.Right - wndRect.Left - clientRect.Right) / 2, 0)
    23.  yBorder = wndRect.Bottom - wndRect.Top - clientRect.Bottom - xBorder
    24.  
    25.  nSrcWidth = Round(clientRect.Right / ZoomFactor, 0)
    26.  nSrcHeight = Round(clientRect.Bottom / ZoomFactor, 0)
    27.  
    28.  [COLOR=#007A00]'align the center of windows
    29. [/COLOR] ScaleFactor = (ZoomFactor - 1) / (2 * ZoomFactor)
    30.  xLeft = wndRect.Left + xBorder + Round(clientRect.Right * ScaleFactor, 0)
    31.  ytop = wndRect.Top + yBorder + Round(clientRect.Bottom * ScaleFactor, 0)
    32.  
    33. [COLOR=#007A00]'make the magnified picture
    34. [/COLOR] StretchBlt Me.hdc, 0, 0, clientRect.Right, clientRect.Bottom, hdcCompatible, xLeft, ytop, nSrcWidth, nSrcHeight, vbSrcCopy
    35.  Me.Refresh
    36. [COLOR=#0000FF]End[/COLOR] [COLOR=#0000FF]Sub[/COLOR][/FONT]
    Attached is a project that demos this idea.
    Attached Files Attached Files
    Last edited by moeur; Nov 4th, 2005 at 12:22 PM.

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