Jump to content

Icon Magnifyer


Recommended Posts

I want to write a program that zooms icons when the mouse is close to it. However I can't seem to get it right. Can anyone please help me? Thanks a lot!

Here are my problems:

  • I tried but can not erase the icon's image after it is magnified. It is commented.
  • After magnifying, the images started to magnify itself again and again instead of staying at the same image.
  • There is always a black box at the top left corner of the screen. I don't know how to erase it.
  • I can't get the _GUICtrlListView_GetItemRect working because of the index value. It is commented also.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
Global $finalDistance, $msg, $desktop, $iconNumber, $x, $y, $pos, $iconPos, $counter2, $counter

$SI = GUICreate("Smart Icons", 625, 445, 192, 124,$WS_MINIMIZEBOX)
GUISetFont(20, 800, 0, "Australian Sunrise")
$Group1 = GUICtrlCreateGroup("Sound Options", 168, 32, 297, 105)
$Slider1 = GUICtrlCreateSlider(184, 80, 193, 49)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 384, 96, 17, 17)
$Label1 = GUICtrlCreateLabel("Mute", 400, 96, 32, 19)
GUICtrlSetFont(-1, 10, 800, 0, "Times New Roman")

$Group2 = GUICtrlCreateGroup("Magnifying Size", 168, 168, 297, 105)
GUICtrlCreateInput("", 216, 208, 97, 32)
$Label2 = GUICtrlCreateLabel("X", 320, 224, 13, 19)
GUICtrlSetFont(-1, 10, 800, 0, "Times New Roman")

$Quit = GUICtrlCreateButton("Quit", 240, 304, 145, 57, $WS_GROUP)
GUICtrlSetFont(-1, 28, 800, 0, "Australian Sunrise")
GUICtrlSetOnEvent(-3, "Quit")



While 1


Global $distance[$iconNumber]
Global $distance2[$iconNumber]
For $i=0 To UBound($iconPos) -1
For $i=0 To UBound($distance) -1
If $distance[$i]<=100 Then
For $i=0 To UBound($counter2) -1
;~ $hbitmap=_ScreenCapture_Capture("",0,0,-1,-1,False)
;~ $bitmap=_GDIPlus_BitmapCreateFromHBITMAP($hbitmap)
;~ _GDIPlus_GraphicsDrawImageRectRect($graphics,$bitmap,0,0,878,737,0,0,878,737)
;~ _WinAPI_DeleteObject($hbitmap)
;~ _WinAPI_DeleteObject($bitmap)

Func getMousePosition()

Func getIconPositions()
If $iconNumber>0 Then
Global $iconPos[$iconNumber][2]
For $i=0 To UBound($iconPos) -1
$iconPos[$i][0]=_GUICtrlListView_GetItemPositionX($desktop, $i)
$iconPos[$i][1]=_GUICtrlListView_GetItemPositionY($desktop, $i)
MsgBox(64,"Error","No icons on desktop.", 3)

; _ArrayDisplay($iconPos, "Icon X Position - Icon Y Position")

Func Quit()

Func accessArrayData()
Global $counter2[UBound($distance2)]
for $i=0 To UBound($distance2) -1
If $distance2[$i]>0 Then

My Projects:Smart Icons

Link to comment
Share on other sites

I found similar magnifiers, but they all put magnified image on the GUI they created. I want to put the image so that it cover the original icon

Then Guicreate next to your mouseposition and guidelete when not on an icon.

Maybe that will work.

Edited by Gideon

Many times you need to think like hobby-bob:')

Link to comment
Share on other sites

  • Moderators


I am not sure you can put the image directly over the cursor - because you cannot then read the actual pixels to get the magnified image :) . This script is not quite what you want (it does not recognise when it is over icons) but it should give you a fair few pointers as to what to do next:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>

Opt("GUICloseOnESC", 0)

HotKeySet("{ESC}", "On_Exit")

Global $hMag_GUI, $hMagDC, $hDeskDC, $hPen, $oObj, $aMouse_Pos[2], $iLast_Mouse_X = 0, $iLast_Mouse_Y = 0

; Create GUI
$hMag_Win = GUICreate("MAG", 100, 100, 0, 0, $WS_POPUP)
GUISetState(@SW_SHOW, $hMag_Win)
$hMag_GUI = WinGetHandle("MAG")
; Get device context for Mag GUI
$hMagDC = _WinAPI_GetDC($hMag_GUI)
If @error Then Exit
; Get device context for desktop
$hDeskDC = _WinAPI_GetDC(0)
If @error Then
    _WinAPI_ReleaseDC($hMag_GUI, $hMagDC)
; Create pen
$hPen = _WinAPI_CreatePen($PS_SOLID, 5, 0x7E7E7E)
$oObj = _WinAPI_SelectObject($hMagDC, $hPen)

While 1
    ; Check if cursor has moved
    $aMouse_Pos = MouseGetPos()
    If $aMouse_Pos[0] <> $iLast_Mouse_X Or $aMouse_Pos[1] <> $iLast_Mouse_Y Then
        ; Redraw Mag GUI
        ; Reset position
        $iLast_Mouse_X = $aMouse_Pos[0]
        $iLast_Mouse_Y = $aMouse_Pos[1]

Func On_Exit()

    ; Clear up Mag GUI
    _WinAPI_SelectObject($hMagDC, $oObj)
    _WinAPI_ReleaseDC(0, $hDeskDC)
    _WinAPI_ReleaseDC($hMag_GUI, $hMagDC)


EndFunc   ;==>On_Exit

Func Loupe($aMouse_Pos)

    Local $iX, $iY

    ; Fill Mag GUI with 5x expanded contents of desktop area (10 pixels around mouse)
    DllCall("gdi32.dll", "int", "StretchBlt", _
        "int", $hMagDC,  "int", 0,                   "int", 0,                   "int", 100, "int", 100, _
        "int", $hDeskDC, "int", $aMouse_Pos[0] - 10, "int", $aMouse_Pos[1] - 10, "int",  20, "int",  20, _
        "long", $SRCCOPY)

    ; Keep Mag GUI on screen
    If $aMouse_Pos[0] < (@DesktopWidth - 120) Then
        $iX = $aMouse_Pos[0] + 20
        $iX = $aMouse_Pos[0] - 120
    If $aMouse_Pos[1] < (@DesktopHeight - 150) Then
        $iY = $aMouse_Pos[1] + 20
        $iY = $aMouse_Pos[1] - 120
    WinMove($hMag_GUI, "", $iX, $iY, 100, 100)

EndFunc   ;==>Loupe

I hope this gets you on the right track.


P.S. You find the icons by looking at the desktop, which you access via:

$hExplorer_List = ControlGetHandle( "Program Manager", "", "SysListView321")

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...