Sign in to follow this  
Followers 0
CodeMaster Rapture

Au3 Zoom!

24 posts in this topic

Hey all,

I got really bored and decided to try something a little different. I made this script as an example of a neat feature you can add to your scripts in the future, a built-in magnifying glass! It's a pretty simple script, but I've never seen anyone else use au3 this way. I'm sure there are plenty of other better methods (DLL calls), but I thought this was quite cool when I got it working. So, without further adue:

; ------------------------------------------------------------------------------
;
; AutoIt Version:   3.1.1 Beta
; Author:           CodeMaster Rapture <Rapture2k4@Netscape.net>
; Language:         English
; Script Function:  A little application that magnifies a 20x20 area under the
;                   mouse. This is just an example of what CAN be done in Au3.
;
; ------------------------------------------------------------------------------

#include <GUIConstants.au3>

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

;Magnifying a 20x20 area of the screen
Global $GUI_Pixel[400]
Global $GUI = GUICreate("Zoom x2 Au3",80,80,0,0,$WS_POPUP+$WS_BORDER,$WS_EX_TOPMOST)

$count = 0
;Let's create a bunch of labels and make them 4x4 pixels in size.
For $iterX = 0 To 79 Step 4
    For $iterY = 0 To 79 Step 4
        $GUI_Pixel[$count] = GUICtrlCreateLabel("",$iterX,$iterY,4,4)
        $count += 1
    Next
Next
GUISetState(@SW_SHOW)

Global $LastPos[2] = [0,0]

While 1
    $count = 0
    $MousePos = MouseGetPos()
    
;Got creative here, since we want to magnify a 20x20 area around the mouse,
;I just start with a negative number for each loop. It still counts 20x20, merely
;starts at a strange index. :)
    For $iterX = -10 To 9
        For $iterY = -10 To 9
            GUICtrlSetBkColor($GUI_Pixel[$count],PixelGetColor($MousePos[0]+$iterX,$MousePos[1]+$iterY))
            $count += 1;Loop thru our Pixel Array (20 * 20 == 400 elements)
        Next
    Next
    
;I placed this in to remove some choppiness. One less API call == good.
;This also allows for animation over an area of the screen.
    If ($LastPos[0] <> $MousePos[0] Or $LastPos[1] <> $MousePos[1]) Then
        WinMove("Zoom x2 Au3","",$MousePos[0]+15,$MousePos[1])
        $LastPos[0] = $MousePos[0]
        $LastPos[1] = $MousePos[1]
    EndIf
    
;Sleeping 1-10 ms takes 70-60% (respectively) CPU usage on my machine
    Sleep(10)
WEnd

Func Quit()
    Exit
EndFunc

Tell me whatcha think :),

CMR

Share this post


Link to post
Share on other sites



Wow, that's actually quite cool. Nice work.

Share this post


Link to post
Share on other sites

Thanx.

I need to add in some collision detection for the edges of the screen, zoom level, zoom box size, and so on.

-CMR

Share this post


Link to post
Share on other sites

Love it!! Now you just need the Cross hairs :)


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Customized a bit by using a DllCall that I found earlier today on the forum.

#include <GUIConstants.au3>

$MagWidth = InputBox ("Magnify Area", "What should the WIDTH of the magnified area be?")
$MagHeight = InputBox ("Magnify Area", "What should the HEIGHT of the magnified area be?")
$MagZoom = InputBox ("Magnify Area", "What should the ZOOM of the magnified area be?", 2)

Global $SRCCOPY = 0x00CC0020
Global $dll[3], $DeskHDC, $GUIHDC

$dll[1] = DllOpen ( "user32.dll")
$dll[2] = DllOpen ( "gdi32.dll")

Global $GUI = GUICreate ("Zoom x2 Au3", $MagWidth * $MagZoom, $MagHeight * $MagZoom, _ 
    MouseGetPos (0), MouseGetPos (1), $WS_POPUP+$WS_BORDER, $WS_EX_TOPMOST)

GUISetState(@SW_SHOW)

Global $LastPos[2] = [0,0]

While 1
    MAG()
    $MousePos = MouseGetPos()
    If ($LastPos[0] <> $MousePos[0] Or $LastPos[1] <> $MousePos[1]) Then
        WinMove("Zoom x2 Au3", "", $MousePos[0] + $MagWidth/2 + 5, $MousePos[1])
        $LastPos[0] = $MousePos[0]
        $LastPos[1] = $MousePos[1]
    EndIf
    
    Sleep(10)
WEnd

Func MAG()
    $DeskHDC = DLLCall("user32.dll","int","GetDC","hwnd",0)
    $GUIHDC = DLLCall("user32.dll","int","GetDC","hwnd",$GUI)
    If Not @error Then
        DLLCall("gdi32.dll", "int", "StretchBlt", "int", $GUIHDC[0], "int", _
            0, "int", 0, "int", $MagWidth * $MagZoom, "int", $MagHeight * $MagZoom, "int", $DeskHDC[0], "int", _
            MouseGetPos (0) - $MagWidth/2, "int", MouseGetPos (1) - $MagHeight/2, "int", $MagWidth ,"int", $MagHeight, _
            "long", $SRCCOPY)
        DLLCall("user32.dll","int","ReleaseDC","int",$DeskHDC[0],"hwnd",0)
        DLLCall("user32.dll","int","ReleaseDC","int",$GUIHDC[0],"hwnd",$GUI)
    EndIf
EndFunc

Func OnAutoItExit()
    DllClose ( $dll[1] )
    DllClose ( $dll[2] )
EndFunc

Share this post


Link to post
Share on other sites

Ha... Very Nice!


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

very good i like it


My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

Share this post


Link to post
Share on other sites

This is pretty cool, nice work.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

very cool, I like how the gui is small and simple

Edited by zerocool60544

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Share this post


Link to post
Share on other sites

I believe if you search hard enough you'll find it's been done a few times before, but nothing wrong with learning how to do it on your own.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Please help !

I am trying to run the two script in this topic but get error messages.

If I compile them with Beta I get errors.

What am I doing wrong ?

Thank you

Tuk

Share this post


Link to post
Share on other sites

Please help !

I am trying to run the two script in this topic but get error messages.

If I compile them with Beta I get errors.

What am I doing wrong ?

Thank you

Tuk

You're not being descriptive enough - that's what you're doing wrong.

Share this post


Link to post
Share on other sites

You're not being descriptive enough - that's what you're doing wrong.

My question is simple: How do I run or compile the above scripts ?

Do I have to include them in existing project or they are stand-alone ?

Running the first script I get error on line 23:

$count += 1

Error: Expected a "=" operator is assignment statement.

If run compiled (Beta) I get same error in line 0.

Running the second script I get three times InputBox, but after entering the third box I get error on line 13 saying " Incorrect number of paramerers in function call", then a second error on line 13 sayin "Error in expression"

If I compile the second script I get: "Unable to open the script file".

Thank you for helping

Tuk

Share this post


Link to post
Share on other sites

My question is simple: How do I run or compile the above scripts ?

Do I have to include them in existing project or they are stand-alone ?

Running the first script I get error on line 23:

$count += 1

Error: Expected a "=" operator is assignment statement.

If run compiled (Beta) I get same error in line 0.

Running the second script I get three times InputBox, but after entering the third box I get error on line 13 saying " Incorrect number of paramerers in function call", then a second error on line 13 sayin "Error in expression"

If I compile the second script I get: "Unable to open the script file".

Thank you for helping

Tuk

Well it works fine when I use it. Are you using Scite? If so, make sure you run scripts with Alt+F5 and compile with Alt+F7. Also, make sure that you answer each of the input prompts, because I didn't declare the vars beforehand (as I should have, but it was late).

Share this post


Link to post
Share on other sites

I will try it with Counter Strike, it's a headshot powertool :)

Apzo.

Good idea, did it work?

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Share this post


Link to post
Share on other sites

Are you using Scite?

No.

Thank you

Tuk

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Good idea, did it work?

I couldn't get it to work. I actually designed this to see if I could make a zoom application for fullscreen satallite imaging software (DirectX 9). The only thing I can get to work is a flickering tooltip :/. I'm working on a DLL in VC++ that will solve this problem tho. It will also have a bunch of other neat things like Onscreen Display text boxes, shapes, scrolling banners, etc (think xFire for Au3). I'm just torn between using OpenGL or DirectX for this.

-CMR

Edited by CodeMaster Rapture

Share this post


Link to post
Share on other sites

Great Job!

Has anyone done a tutorial for calling and using these wonderfull gdi32.dll functions?? :)


2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
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
Sign in to follow this  
Followers 0