VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This program enables to view zoomed mode when mouse cursor placed on any position or desired. Zoom

by Ganti.Jagannath Sastry (1 Submission)
Category: Windows System Services
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 17th December 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This program enables to view zoomed mode when mouse cursor placed on any position or desired. Zoom factor can be changed by increasing and

API Declarations


'***********************************************************************
'Open standard exe and take picturebox, textbox, timer and updown controls
'********************************************************************

Option Explicit

Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetParent Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function WindowFromPoint Lib "user32.dll" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "USER32" (lpPoint As POINTAPI) As Long
Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function GetWindowDC Lib "USER32" (ByVal hwnd As Long) As Long
Private Declare Function GetDesktopWindow Lib "USER32" () 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

Rate This program enables to view zoomed mode when mouse cursor placed on any position or desired. Zoom



'*********************************************************************
Private Sub Form_Load()
  Me.Move 30, 30, 5775, 7390 'position form
  UpDown1.Value = 90
  Text1.Text = UpDown1.Value & "%"
  Me.AutoRedraw = True
End Sub
'***********************************************************************
Private Sub Form_Resize()
  Picture1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight - 315
  Text1.Move 0, Me.ScaleHeight - 315, 765, 315
  UpDown1.Move 765, Me.ScaleHeight - 315, 195, 315
End Sub
'***********************************************************************
Private Sub Timer1_Timer()
Dim rv As Long, mXY As POINTAPI, magFCT As Single
Dim hWP As Long, hPP As Long, maxWIDTH As Long, maxHEIGHT As Long
Dim src_LEFT As Long, src_TOP As Long, src_WIDTH As Long, src_HEIGHT As Long
Dim dst_LEFT As Long, dst_TOP As Long, dst_WIDTH As Long, dst_HEIGHT As Long
Dim dst_centerX As Long, dst_centerY As Long
Dim src_HANDLE As Long, src_DC As Long
Dim meW As Long, meH As Long
    magFCT = 1 - (UpDown1.Value / 100) 'magnification factor
    rv = GetCursorPos(mXY) 'get mouse position
    hWP = WindowFromPoint(mXY.x, mXY.y) 'handle to window under mouse
    hPP = GetParent(hWP) 'handle to parent to window under mouse
    If hPP = 0 Then hPP = hWP 'if no parent, use window from point
    If hPP <> Me.hwnd Then 'do not magnify our form
        '--describe area to accept magnification----------------
        dst_centerX = Picture1.ScaleWidth / 2
        dst_centerY = Picture1.ScaleHeight / 2
        dst_LEFT = 0
        dst_TOP = 0
        dst_WIDTH = Picture1.ScaleWidth / Screen.TwipsPerPixelX
        dst_HEIGHT = Picture1.ScaleHeight / Screen.TwipsPerPixelY
        '--describe area of screen to magnify------
        meH = (Picture1.ScaleHeight / Screen.TwipsPerPixelX) * magFCT
        meW = (Picture1.ScaleWidth / Screen.TwipsPerPixelY) * magFCT
        src_LEFT = mXY.x - (meW / 2)
        src_TOP = mXY.y - (meH / 2)
        src_WIDTH = meW
        src_HEIGHT = meH
        '--adjust for edge of screen----------------------------
        maxWIDTH = Screen.Width / Screen.TwipsPerPixelX
        maxHEIGHT = Screen.Height / Screen.TwipsPerPixelY
        If src_LEFT < 0 Then
            dst_centerX = dst_centerX + (src_LEFT * (Screen.TwipsPerPixelX / magFCT))
            src_LEFT = 0
        ElseIf src_LEFT + src_WIDTH > maxWIDTH Then
            dst_centerX = dst_centerX + (src_LEFT + src_WIDTH - maxWIDTH) * (Screen.TwipsPerPixelX / magFCT)
            src_LEFT = src_LEFT - (src_LEFT + src_WIDTH - maxWIDTH)
        End If
        If src_TOP < 0 Then
            dst_centerY = dst_centerY + (src_TOP * (Screen.TwipsPerPixelY / magFCT))
            src_TOP = 0
        ElseIf src_TOP + src_HEIGHT > maxHEIGHT Then
            dst_centerY = dst_centerY + (src_TOP + src_HEIGHT - maxHEIGHT) * (Screen.TwipsPerPixelY / magFCT)
            src_TOP = src_TOP - (src_TOP + src_HEIGHT - maxHEIGHT)
        End If
        
        
        src_HANDLE = GetDesktopWindow() 'get a handle to screen
        src_DC = GetWindowDC(src_HANDLE) 'get device context to screen
        '--copy section of screen to form-----------------------------
        StretchBlt Picture1.hdc, _
                   dst_LEFT, dst_TOP, dst_WIDTH, dst_HEIGHT, _
                   src_DC, _
                   src_LEFT, src_TOP, src_WIDTH, src_HEIGHT, vbSrcCopy
        rv = ReleaseDC(src_HANDLE, src_DC) ' release screen dc
        '--draw spotter on screen
        Picture1.Line (dst_centerX, dst_centerY - 300)-(dst_centerX, dst_centerY + 300)
        Picture1.Line (dst_centerX - 300, dst_centerY)-(dst_centerX + 300, dst_centerY)
    End If
    Me.Caption = "(x,y)=" & mXY.x * Screen.TwipsPerPixelX & "," & mXY.y * Screen.TwipsPerPixelY
End Sub
'******************************************************************************
Private Sub UpDown1_Change()
  Text1.Text = UpDown1.Value & "%"
End Sub



Download this snippet    Add to My Saved Code

This program enables to view zoomed mode when mouse cursor placed on any position or desired. Zoom Comments

No comments have been posted about This program enables to view zoomed mode when mouse cursor placed on any position or desired. Zoom . Why not be the first to post a comment about This program enables to view zoomed mode when mouse cursor placed on any position or desired. Zoom .

Post your comment

Subject:
Message:
0/1000 characters