Results 1 to 16 of 16

Thread: [RESOLVED] Magnifying form

  1. #1

    Thread Starter
    Addicted Member -SUBS-Lenos's Avatar
    Join Date
    Sep 2005
    Posts
    179

    Resolved [RESOLVED] Magnifying form

    I remember in a windows utitity that Magnify's an area
    Is there any way to make my form sortof like a Magnifying glass?

    Thanks
    Tip use roboform .

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

    Re: Magnifying form

    Check out this thread and see if it helps
    http://www.vbforums.com/showthread.p...54#post2189954

    If you need help adapting it to your needs let me kknow.

  3. #3

    Thread Starter
    Addicted Member -SUBS-Lenos's Avatar
    Join Date
    Sep 2005
    Posts
    179

    Re: Magnifying form

    Yea sortof but can I have it magnify windows not my form?
    Tip use roboform .

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

    Re: Magnifying form

    Yes easily,

    Just use the screen's hdc in place of the big picturebox hdc and your form's hdc in place of the little ones.

  5. #5

    Thread Starter
    Addicted Member -SUBS-Lenos's Avatar
    Join Date
    Sep 2005
    Posts
    179

    Re: Magnifying form

    Ok a little complicated please example
    Tip use roboform .

  6. #6

    Thread Starter
    Addicted Member -SUBS-Lenos's Avatar
    Join Date
    Sep 2005
    Posts
    179

    Re: Magnifying form

    Sorry for my stupidity
    Did it thanks!
    Tip use roboform .

  7. #7
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: [RESOLVED] Magnifying form

    can you please post your code that worked?

  8. #8

    Thread Starter
    Addicted Member -SUBS-Lenos's Avatar
    Join Date
    Sep 2005
    Posts
    179

    Re: [RESOLVED] Magnifying form

    Sure

    If you downloaded his project replace the Image1_MouseMove with this

    VB Code:
    1. Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.  
    3.     If Button = vbLeftButton Then
    4.         Image1.Left = Image1.Left - XX + Me.ScaleX(X, vbTwips, vbPixels)
    5.         Image1.Top = Image1.Top - YY + Me.ScaleY(Y, vbTwips, vbPixels)
    6.         StretchBlt Picture3.hdc, 0, 0, Picture3.Width, Picture3.Height, Me.hdc, Image1.Left, Image1.Top, Image1.Width, Image1.Height, vbSrcCopy
    7.     End If
    8.  
    9. End Sub
    Tip use roboform .

  9. #9

    Thread Starter
    Addicted Member -SUBS-Lenos's Avatar
    Join Date
    Sep 2005
    Posts
    179

    Re: [RESOLVED] Magnifying form

    His code does not work well with transparent forms or opaque forms
    Tip use roboform .

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

    Re: [RESOLVED] Magnifying form

    I finally got a chance to play around with this a bit. The problem with magnifying on the same form you're moving around is that you have to keep hiding the form so that you can see what is behind it. Maybe there is someway to tap into the buffer used to repaint the background and get your data from there. Anyway here is what I have that works pretty well.
    VB Code:
    1. Option Explicit
    2.  
    3. Private srcDc As Long
    4.  
    5. Private Declare Function StretchBlt Lib "gdi32" ( _
    6.     ByVal hdc As Long, _
    7.     ByVal x As Long, _
    8.     ByVal y As Long, _
    9.     ByVal nWidth As Long, _
    10.     ByVal nHeight As Long, _
    11.     ByVal hSrcDC As Long, _
    12.     ByVal xSrc As Long, _
    13.     ByVal ySrc As Long, _
    14.     ByVal nSrcWidth As Long, _
    15.     ByVal nSrcHeight As Long, _
    16.     ByVal dwRop As Long _
    17. ) As Long
    18.  
    19. Private Declare Function GetDC Lib "user32" ( _
    20.     ByVal hwnd As Long _
    21. ) As Long
    22.  
    23. Private Declare Function GetWindowRect Lib "user32" ( _
    24.     ByVal hwnd As Long, _
    25.     lpRect As RECT _
    26. ) As Long
    27.  
    28. Private Declare Function GetClientRect Lib "user32" ( _
    29.     ByVal hwnd As Long, _
    30.     lpRect As RECT _
    31. ) As Long
    32.  
    33. Private Type RECT
    34.         Left As Long
    35.         Top As Long
    36.         Right As Long
    37.         Bottom As Long
    38. End Type
    39.  
    40. Private Sub Form_Load()
    41.     Me.ScaleMode = vbPixels
    42.     srcDc = GetDC(0&)
    43.     Set FormSubClass = New clsSubClass
    44.     FormSubClass.Enable Me.hwnd
    45. End Sub
    46.  
    47. Sub ZoomIn(ZoomFactor As Long)
    48.  Dim xWidth As Long, yHeight As Long
    49.  Dim xLeft As Long, ytop As Long
    50.  Dim nSrcWidth As Long, nSrcHeight As Long
    51.  
    52.  Dim xBorder As Long
    53.  Dim yBorder As Long
    54.  Dim wndRect As RECT
    55.  Dim clientRect As RECT
    56.  
    57.  GetWindowRect Me.hwnd, wndRect
    58.  GetClientRect Me.hwnd, clientRect
    59.  
    60.  'need to hide form so we can see what is behind it
    61.   Me.Visible = False
    62.   DoEvents
    63.  
    64. 'get size and location of form
    65.  xBorder = Int((wndRect.Right - wndRect.Left - clientRect.Right) / 2)
    66.  yBorder = wndRect.Bottom - wndRect.Top - clientRect.Bottom - xBorder
    67.  
    68.  xWidth = clientRect.Right
    69.  yHeight = clientRect.Bottom
    70.  nSrcWidth = Int(xWidth / ZoomFactor)
    71.  nSrcHeight = Int(yHeight / ZoomFactor)
    72.  xLeft = wndRect.Left + xBorder
    73.  ytop = wndRect.Top + yBorder
    74.  
    75. 'make the magnified picture
    76.  StretchBlt Me.hdc, 0, 0, xWidth, yHeight, srcDc, xLeft, ytop, nSrcWidth, nSrcHeight, vbSrcCopy
    77.  Me.Visible = True
    78.  
    79. End Sub
    Now, when do you call the ZoomIn routine? You can subclass the form and call it whenever the form is moved
    VB Code:
    1. Private Sub FormSubClass_WMArrival(hwnd As Long, uMsg As Long, _
    2.     wParam As Long, lParam As Long, lRetVal As Long)
    3.     Select Case uMsg
    4.     Case WM_MOVE
    5.         ZoomIn 2
    6.     End Select
    7. End Sub
    This causes a lot of flashing, so maybe you just want to call it once the form has completed moving

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

    Re: [RESOLVED] Magnifying form

    Here is a much better solution.
    create a memory device context to hold the screen picture
    update that DC only when you start to move the form
    while the form is being moved, copy a region of that DC onto the form
    It works more smoothly if the borders of the form are removed or set to fixed single.
    VB Code:
    1. Option Explicit
    2.  
    3. Private hdcScreen As Long
    4. Private hdcCompatible As Long
    5. Private hbmScreen As Long
    6.  
    7. Private ScreenWidth As Long
    8. Private screenHeight As Long
    9. Private XX As Single
    10. Private YY As Single
    11.  
    12. Private ScaleFactor As Long
    13.  
    14.  
    15. Private Declare Function StretchBlt Lib "gdi32" ( _
    16.     ByVal hdc As Long, _
    17.     ByVal X As Long, _
    18.     ByVal Y As Long, _
    19.     ByVal nWidth As Long, _
    20.     ByVal nHeight As Long, _
    21.     ByVal hSrcDC As Long, _
    22.     ByVal xSrc As Long, _
    23.     ByVal ySrc As Long, _
    24.     ByVal nSrcWidth As Long, _
    25.     ByVal nSrcHeight As Long, _
    26.     ByVal dwRop As Long _
    27. ) As Long
    28.  
    29. Private Declare Function GetWindowRect Lib "user32" ( _
    30.     ByVal hwnd As Long, _
    31.     lpRect As RECT _
    32. ) As Long
    33.  
    34. Private Declare Function GetClientRect Lib "user32" ( _
    35.     ByVal hwnd As Long, _
    36.     lpRect As RECT _
    37. ) As Long
    38.  
    39. Private Type RECT
    40.         Left As Long
    41.         Top As Long
    42.         Right As Long
    43.         Bottom As Long
    44. End Type
    45.  
    46.  
    47. Private Declare Function CreateCompatibleDC Lib "gdi32" ( _
    48.     ByVal hdc As Long _
    49. ) As Long
    50.  
    51. Private Declare Function BitBlt Lib "gdi32" ( _
    52.     ByVal hDestDC As Long, _
    53.     ByVal X As Long, _
    54.     ByVal Y As Long, _
    55.     ByVal nWidth As Long, _
    56.     ByVal nHeight As Long, _
    57.     ByVal hSrcDC As Long, _
    58.     ByVal xSrc As Long, _
    59.     ByVal ySrc As Long, _
    60.     ByVal dwRop As Long _
    61. ) As Long
    62.  
    63. Private Declare Function DeleteDC Lib "gdi32" ( _
    64.     ByVal hdc As Long _
    65. ) As Long
    66.  
    67. Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" ( _
    68.     ByVal lpDriverName As String, _
    69.     ByVal lpDeviceName As String, _
    70.     ByVal lpOutput As String, _
    71.     ByVal lpInitData As Long _
    72. ) As Long
    73.  
    74. Private Declare Function CreateCompatibleBitmap Lib "gdi32" ( _
    75.     ByVal hdc As Long, _
    76.     ByVal nWidth As Long, _
    77.     ByVal nHeight As Long _
    78. ) As Long
    79.  
    80. Private Declare Function GetDeviceCaps Lib "gdi32" ( _
    81.     ByVal hdc As Long, _
    82.     ByVal nIndex As Long _
    83. ) As Long
    84.  
    85. Private Declare Function SelectObject Lib "gdi32" ( _
    86.     ByVal hdc As Long, _
    87.     ByVal hObject As Long _
    88. ) As Long
    89.  
    90. Private Declare Function DeleteObject Lib "gdi32" ( _
    91.     ByVal hObject As Long _
    92. ) As Long
    93.  
    94. Private Const HORZRES = 8            '  Horizontal width in pixels
    95. Private Const VERTRES = 10           '  Vertical width in pixels
    96.  
    97. Sub UpDateImage()
    98.     Me.Visible = False
    99.     DoEvents
    100.          'Copy color data for the entire display into a
    101.          'bitmap that is selected into a compatible DC.
    102.  
    103.         If BitBlt(hdcCompatible, _
    104.                0, 0, _
    105.                ScreenWidth, screenHeight, _
    106.                hdcScreen, _
    107.                0, 0, _
    108.                vbSrcCopy) = 0 Then
    109.  
    110.                 MsgBox "Screen to Compat Blt Failed"
    111.             Exit Sub
    112.         End If
    113.     Me.Visible = True
    114.     DoEvents
    115. End Sub
    116.  
    117. Sub ZoomIn(ZoomFactor As Long)
    118.  Dim xLeft As Long, ytop As Long
    119.  Dim nSrcWidth As Long, nSrcHeight As Long
    120.  Dim ScaleFactor As Single
    121.  Dim xBorder As Long
    122.  Dim yBorder As Long
    123.  Dim wndRect As RECT
    124.  Dim clientRect As RECT
    125.  
    126.  GetWindowRect Me.hwnd, wndRect
    127.  GetClientRect Me.hwnd, clientRect
    128.  
    129. 'get size and location of form
    130.  xBorder = Round((wndRect.Right - wndRect.Left - clientRect.Right) / 2, 0)
    131.  yBorder = wndRect.Bottom - wndRect.Top - clientRect.Bottom - xBorder
    132.  
    133.  nSrcWidth = Round(clientRect.Right / ZoomFactor, 0)
    134.  nSrcHeight = Round(clientRect.Bottom / ZoomFactor, 0)
    135.  
    136.  'align the center of windows
    137.  ScaleFactor = (ZoomFactor - 1) / (2 * ZoomFactor)
    138.  xLeft = wndRect.Left + xBorder + Round(clientRect.Right * ScaleFactor, 0)
    139.  ytop = wndRect.Top + yBorder + Round(clientRect.Bottom * ScaleFactor, 0)
    140.  
    141. 'make the magnified picture
    142.  
    143.  StretchBlt Me.hdc, 0, 0, clientRect.Right, clientRect.Bottom, hdcCompatible, xLeft, ytop, nSrcWidth, nSrcHeight, vbSrcCopy
    144.  Me.Refresh
    145.  
    146. End Sub
    147.  
    148. Private Sub Form_Load()
    149.  
    150.     Me.AutoRedraw = True
    151.     ScaleFactor = 2
    152.    
    153. ' Create a normal DC and a memory DC for the entire screen. The
    154. ' normal DC provides a "snapshot" of the screen contents. The
    155. ' memory DC keeps a copy of this "snapshot" in the associated
    156. ' bitmap.
    157.  
    158. hdcScreen = CreateDC("DISPLAY", vbNullString, vbNullString, 0&)
    159. If hdcScreen = 0 Then
    160.     MsgBox "CreateDC failed"
    161.     Exit Sub
    162. End If
    163.  
    164.  
    165. hdcCompatible = CreateCompatibleDC(hdcScreen)
    166. If hdcCompatible = 0 Then
    167.     MsgBox "hdcCompatible failed"
    168.     Exit Sub
    169. End If
    170.  
    171. ScreenWidth = GetDeviceCaps(hdcScreen, HORZRES)
    172. screenHeight = GetDeviceCaps(hdcScreen, VERTRES)
    173.  
    174. ' Create a compatible bitmap for hdcScreen.
    175. hbmScreen = CreateCompatibleBitmap(hdcScreen, _
    176.                      ScreenWidth, _
    177.                      screenHeight)
    178.  
    179. If (hbmScreen = 0) Then
    180.     MsgBox "hbmScreen failed"
    181.     Exit Sub
    182. End If
    183.  
    184. ' Select the bitmaps into the compatible DC.
    185. If SelectObject(hdcCompatible, hbmScreen) = 0 Then
    186.     MsgBox "Compatible Bitmap Selection Failed!"
    187.     Exit Sub
    188. End If
    189.  
    190.     UpDateImage
    191.     ZoomIn ScaleFactor
    192.    
    193.  
    194. End Sub
    195.  
    196. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    197.     Select Case Button
    198.     Case vbLeftButton
    199.         XX = X 'Me.ScaleX(X, vbTwips, vbPixels)
    200.         YY = Y 'Me.ScaleY(Y, vbTwips, vbPixels)
    201.         UpDateImage
    202.     Case vbRightButton
    203.         PopupMenu mnPopup
    204.     End Select
    205.    
    206. End Sub
    207.  
    208.  
    209. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    210. Dim NewLeft As Integer
    211. Dim NewTop As Integer
    212.     If Button = vbLeftButton Then
    213.         NewLeft = Me.Left - XX + X
    214.         NewTop = Me.Top - YY + Y
    215.         If NewLeft + Me.Width <= Screen.Width Then
    216.             If NewLeft >= 0 Then
    217.                 Me.Left = NewLeft
    218.             Else
    219.                 Me.Left = 0
    220.             End If
    221.         Else
    222.             Me.Left = Screen.Width - Me.Width
    223.         End If
    224.  
    225.         If NewTop + Me.Height <= Screen.Height Then
    226.             If NewTop >= 0 Then
    227.                 Me.Top = NewTop
    228.             Else
    229.                 Me.Top = 0
    230.             End If
    231.         Else
    232.             Me.Top = Screen.Height - Me.Height
    233.         End If
    234.  
    235.     ZoomIn ScaleFactor
    236.   End If
    237.  
    238.  
    239. End Sub
    240.  
    241. Private Sub Form_Unload(Cancel As Integer)
    242.     DeleteObject hbmScreen
    243.     DeleteDC hdcScreen
    244.     DeleteDC hdcCompatible
    245. End Sub
    246.  
    247. Private Sub mnExit_Click()
    248.     Unload Me
    249. End Sub
    250.  
    251. Private Sub mnFactor_Click(Index As Integer)
    252.     ScaleFactor = Index
    253.     ZoomIn ScaleFactor
    254. End Sub
    Last edited by moeur; Oct 29th, 2005 at 02:35 PM.

  12. #12
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: [RESOLVED] Magnifying form

    mouer, the stuff you come up with always amazes me, great job.

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

    Re: [RESOLVED] Magnifying form

    Awe shucks...

  14. #14

    Thread Starter
    Addicted Member -SUBS-Lenos's Avatar
    Join Date
    Sep 2005
    Posts
    179

    Re: [RESOLVED] Magnifying form

    Thats AwsomE!
    Great help
    thanks much!
    Tip use roboform .

  15. #15
    New Member
    Join Date
    Dec 2012
    Location
    Belgian-Holland border
    Posts
    1

    Re: [RESOLVED] Magnifying form

    Hi, this is VERY useful !
    2 questions =>
    1) how can I make it work on a second screen, used as extended desktop, so far it works only on the main screen
    2) will it still work in Windows 7 ?

  16. #16
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: [RESOLVED] Magnifying form

    This thread is 7 years old. These guys probably don't post anymore.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

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