A toy for old eyes

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

A toy for old eyes

Post by JRL » Mon Mar 08, 2010 5:29 am

Yes... Microsoft has one of these built in but their's screws up my desktop icons. Besides, their's doesn't give you code you might find another use for.

Code: Select all

Dialog>Dialog1
   Caption=5X Magnify
   Width=800
   Height=500
   Top=500
   Left=48
EndDialog>Dialog1
Show>Dialog1
  LibFunc>user32,GetDC,HDC1,Dialog1.handle
  LibFunc>user32,GetDC,HDC3,0

Label>Loop
  GetDialogAction>Dialog1,res1
  If>res1=2
    Exit>0
  EndIf
  GetCursorPos>CurX,CurY
  Sub>CurX,80
  Sub>CurY,50
  Wait>0.01
  LibFunc>Gdi32,StretchBlt,SBres,HDC1,0,0,800,500,HDC3,CURX,CURY,160,100,13369376
  GoSub>DrawLine,Dialog1.handle,1,0,390,250,410,250
  GoSub>DrawLine,Dialog1.handle,1,0,400,240,400,260
Goto>Loop

//GoSub>DrawLine,WindowHandle,PenSize,PenColor,XStart,YStart,XEnd,YEnd

SRT>DrawLine
  LibFunc>user32,GetDC,HDC,%DrawLine_var_1%
  LibFunc>gdi32,CreatePen,Penres,0,%DrawLine_var_2%,%DrawLine_var_3%
  LibFunc>gdi32,SelectObject,SOPres,hdc,Penres
  Libfunc>gdi32,MoveToEx,mtres,HDC,%DrawLine_var_4%,%DrawLine_var_5%,0
  LibFunc>gdi32,LineTo,ltres,hdc,%DrawLine_var_6%,%DrawLine_var_7%
  LibFunc>gdi32,DeleteObject,DOres,Penres
  LibFunc>user32,ReleaseDC,RDCres,HDC_1,HDC
END>DrawLine

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Mar 08, 2010 9:39 am

Very nice! :-)
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Mar 09, 2010 4:30 am

Great job Dick! Really cool use of Macro Scheduler.




--------------------------------------------------
If you cannot read the comments above, use his script and it will look like this:

Great job Dick! Really cool use of Macro Scheduler.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Wed Mar 10, 2010 3:48 pm

Superb!

Out of interest... Which are the parms for changing the amount of mag?

:D
Phil Pendlebury - Linktree

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Mar 11, 2010 6:03 am

Glad this seems to be appreciated.
Out of interest... Which are the parms for changing the amount of mag?
In the line:
LibFunc>Gdi32,StretchBlt,SBres,HDC1,0,0,800,500,HDC3,CURX,CURY,160,100,13369376

800 is five times 160 and 500 is five times 100.

800 and 500 match the size of the dialog.

The lines:
GoSub>DrawLine,Dialog1.handle,1,0,390,250,410,250
GoSub>DrawLine,Dialog1.handle,1,0,400,240,400,260

Use the DrawLine subroutine to draw a crosshair at the center of the dialog which should match the location of the cursor. Notice that 400 is half of 800 and 250 is half of 500.

I considered making this sample more flexible by adding variables that would allow someone to easily alter sizes and magnifications. I decided to keep the sample simple but less flexible.

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Thu Mar 11, 2010 10:10 am

Thanks JRL. All awesome and you are right of course - simple. Which is part of the awesomeness.

:-)
Phil Pendlebury - Linktree

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Mar 11, 2010 2:50 pm

Here's the same thing with user definable variables.

Other possibilities to complicate the code.
- Account for the distortion you get when you move the mouse too close to the edge of the desktop.
- Let a user run this with command line parameters.
- Let the magnification float based on the size of the dialog. i.e. as the dialog gets bigger the magnification is reduced, or vice versa.
- Add a row of buttons with magnification factors or perhaps add a magnification slider.
- Make the dialog run away from the mouse cursor (would need a hotkey to close the script).

In answer to a jpuziano off forum question. This is 100% original to the extent that I did not find code elsewhere and modify it. All of the library functions used have been previously posted to the forum.

Code: Select all

////////////// Programmer definable variables ///////////////
//Dialog size
Let>Wide=800
Let>High=500
//Magnification factor
Let>Magnification=2
/////////////////////////////////////////////////////////////



//////////////// Calculated variables //////////////////
Let>AreaX={round(%Wide%/%Magnification%)}
Let>AreaY={round(%High%/%Magnification%)}
Let>UpperLeftAreaX={round(%AreaX%/2)}
Let>UpperLeftAreaY={round(%AreaY%/2)}
Let>CrossHairX={round(%Wide%/2)}
Let>CrossHairY={round(%High%/2)}
Let>CrossHairUp=%CrossHairX%+10
Let>CrossHairDown=%CrossHairX%-10
Let>CrossHairRight=%CrossHairY%+10
Let>CrossHairLeft=%CrossHairY%-10

//////////////// The rest of the program /////////////////
Dialog>Dialog1
   Caption=%Magnification%X Magnify
   Width=%Wide%
   Height=%High%
   Top=500
   Left=48
EndDialog>Dialog1
Show>Dialog1
  LibFunc>user32,GetDC,HDC1,Dialog1.handle
  LibFunc>user32,GetDC,HDC3,0

Label>Loop
  GetDialogAction>Dialog1,res1
  If>res1=2
    Exit>0
  EndIf
  GetCursorPos>CurX,CurY
  Sub>CurX,%UpperLeftAreaX%
  Sub>CurY,%UpperLeftAreaY%
  Wait>0.01
  LibFunc>Gdi32,StretchBlt,SBres,HDC1,0,0,%Wide%,%High%,HDC3,CURX,CURY,%AreaX%,%AreaY%,13369376
  GoSub>DrawLine,Dialog1.handle,1,0,%CrossHairDown%,%CrossHairY%,%CrossHairUp%,%CrossHairY%
  GoSub>DrawLine,Dialog1.handle,1,0,%CrossHairX%,%CrossHairLeft%,%CrossHairX%,%CrossHairRight%
Goto>Loop

//GoSub>DrawLine,WindowHandle,PenSize,PenColor,XStart,YStart,XEnd,YEnd
SRT>DrawLine
  LibFunc>user32,GetDC,HDC,%DrawLine_var_1%
  LibFunc>gdi32,CreatePen,Penres,0,%DrawLine_var_2%,%DrawLine_var_3%
  LibFunc>gdi32,SelectObject,SOPres,hdc,Penres
  Libfunc>gdi32,MoveToEx,mtres,HDC,%DrawLine_var_4%,%DrawLine_var_5%,0
  LibFunc>gdi32,LineTo,ltres,hdc,%DrawLine_var_6%,%DrawLine_var_7%
  LibFunc>gdi32,DeleteObject,DOres,Penres
  LibFunc>user32,ReleaseDC,RDCres,HDC_1,HDC
END>DrawLine

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Thu Mar 11, 2010 4:09 pm

SUPER-MEGA LARGE!
Phil Pendlebury - Linktree

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Mar 15, 2010 4:19 am

Added:

The user can change the magnification

The user can change the size of the dialog

Code: Select all

////////////// Programmer predefined variables //////////////
//Dialog size
Let>Wide=800
Let>High=200
//Magnification factor
Let>Magnification=2
/////////////////////////////////////////////////////////////


//////////////// Calculated variables ///////////////////////
GoSub>SetUp

//////////////// The rest of the program ////////////////////

/////////////// A dialog for custom magnification ///////////
Dialog>Dialog7
   Caption=Custom
   Width=150
   Height=110
   Top=CENTER
   Left=CENTER
   Edit=msEdit1,50,25,44,
   Label= Magnification,40,8,true
   Button=Ok,35,50,75,25,3
   Default=Ok
EndDialog>Dialog7

/////////// Dialog to display the magnified area ////////////
Dialog>Dialog1
   Caption=%Magnification%X Magnify
   Width=%Wide%
   Height=%High%
   Top=200
   Left=48
   Button=1X,0,0,20,20,11
   Button=2X,20,0,20,20,12
   Button=3X,40,0,20,20,13
   Button=4X,60,0,20,20,14
   Button=5X,80,0,20,20,15
   Button=6X,100,0,20,20,16
   Button=7X,120,0,20,20,17
   Button=8X,140,0,20,20,18
   Button=9X,160,0,20,20,19
   Button=10X,180,0,20,20,20
   Button=Other,200,0,30,20,21
EndDialog>Dialog1
Show>Dialog1
//////////// Acquire the needed "Device Context" /////////////
// For more on "Device Context", see the Microsoft MSDN web site.
  LibFunc>user32,GetDC,HDC1,Dialog1.handle
  LibFunc>user32,GetDC,HDC3,0

Label>Loop
  GetDialogAction>Dialog1,res1

// Added the following to set the dialog title to reflect current magnification
  LibFunc>user32,SetWindowTextA,res,dialog1.handle,%Magnification%X Magnify
  If>res1=2
    Exit>0
  EndIf
  If>res1=21
    Label>Redo_Custom
    Show>Dialog7,res7
    ResetDialogAction>Dialog1
    ResetDialogAction>Dialog7
    GetDialogAction>Dialog1,res1
    GetDialogAction>Dialog7,res7

// User me_again's simple method to test for numeric input
    Let>test=%Dialog7.msEdit1%+1
    Separate>test,+,test

    If>%test_count%<2
      Let>Magnification=Dialog7.msEdit1
      GoSub>SetUp
    Else
      Goto>Redo_Custom
    EndIf
  EndIf
  If>res1<>0
    Let>Magnification=%res1%-10
    ResetDialogAction>Dialog1
    GoSub>SetUp
  EndIf
  Let>WIN_USEHANDLE=1
    GetWindowSize>dialog1.handle,WinW,WinH
  Let>WIN_USEHANDLE=0
    If>{(%WinW%<>%Wide%)or(%WinH%<>%High%)}
      Let>Wide=%WinW%
      Let>High=%WinH%
      GoSub>SetUp
    EndIf
  GetCursorPos>CurX,CurY
  Sub>CurX,%UpperLeftAreaX%
  Sub>CurY,%UpperLeftAreaY%
  Wait>0.01
  /////// The function that's doing the display
  LibFunc>Gdi32,StretchBlt,SBres,HDC1,0,0,%Wide%,%High%,HDC3,CURX,CURY,%AreaX%,%AreaY%,13369376
  GoSub>DrawLine,Dialog1.handle,1,0,%CrossHairDown%,%CrossHairY%,%CrossHairUp%,%CrossHairY%
  GoSub>DrawLine,Dialog1.handle,1,0,%CrossHairX%,%CrossHairLeft%,%CrossHairX%,%CrossHairRight%
Goto>Loop

//GoSub>DrawLine,WindowHandle,PenSize,PenColor,XStart,YStart,XEnd,YEnd
SRT>DrawLine
  LibFunc>user32,GetDC,HDC,%DrawLine_var_1%
  LibFunc>gdi32,CreatePen,Penres,0,%DrawLine_var_2%,%DrawLine_var_3%
  LibFunc>gdi32,SelectObject,SOPres,hdc,Penres
  Libfunc>gdi32,MoveToEx,mtres,HDC,%DrawLine_var_4%,%DrawLine_var_5%,0
  LibFunc>gdi32,LineTo,ltres,hdc,%DrawLine_var_6%,%DrawLine_var_7%
  LibFunc>gdi32,DeleteObject,DOres,Penres
  LibFunc>user32,ReleaseDC,RDCres,HDC_1,HDC
END>DrawLine

SRT>SetUp
  Let>AreaX={round(%Wide%/%Magnification%)}
  Let>AreaY={round(%High%/%Magnification%)}
  Let>UpperLeftAreaX={round(%AreaX%/2)}
  Let>UpperLeftAreaY={round(%AreaY%/2)}
  Let>CrossHairX={round(%Wide%/2)}
  Let>CrossHairY={round(%High%/2)}
  Let>CrossHairUp=%CrossHairX%+10
  Let>CrossHairDown=%CrossHairX%-10
  Let>CrossHairRight=%CrossHairY%+10
  Let>CrossHairLeft=%CrossHairY%-10
END>SetUp

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Apr 01, 2010 9:12 pm

Another variation

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1
////User definable
//Magnification factor
Let>Factor=3
//Magnifier area width
Let>Wide=400
//Magnifier area height
Let>High=200

//////////////////////////////////////////////////////////////////////
OnEvent>Key_down,VK1,0,LeftClick

Dialog>TitleBarSizeCalculation
Top=0
Left=0
Button=1,0,0,75,25,0
EndDialog>TitleBarSizeCalculation
Let>WIN_USEHANDLE=1
GetWindowPos>TitleBarSizeCalculation.msButton1.handle,OffSetX,OffSetY
Let>WIN_USEHANDLE=0

Let>XSpan={round(%Wide%/%factor%)}
Let>Yspan={round(%High%/%factor%)}
Let>Height=%High%+%OffSetY%

Dialog>Dialog1
   Caption=%factor%X Magnify
   Width=%Wide%
   Height=%Height%
   Top=0
   Left=0
   Close=0
EndDialog>Dialog1
Show>Dialog1

GoSub>MakeOpaque,%factor%X Magnify,255

LibFunc>user32,GetDC,HDC1,Dialog1.handle
LibFunc>user32,GetDC,HDC3,0

Label>Loop
  GetDialogAction>Dialog1,res1
  If>res1=2
    Exit>0
  EndIf
  GetCursorPos>CurX,CurY
  Let>CurWX={%CurX%-(round(%Wide%/2))-%offsetX%}
  Let>CurWY={%curY%-(round(%High%/2))-%offsetY%}
  Let>CY={%curY%-(round(%Yspan%/2))}
  Let>CX={%curX%-(round(%Xspan%/2))}
  Wait>0.01
  LibFunc>Gdi32,StretchBlt,SBres,HDC1,-0,-0,%wide%,%high%,HDC3,CX,CY,Xspan,Yspan,13369376
  MoveWindow>%factor%X Magnify,CurWx,CurWY
Goto>Loop

SRT>MakeOpaque
  If>%MakeOpaque_var_2%=
    Let>MakeOpaque_var_2=255
  EndIf
  If>MakeOpaque_var_1<>
    GetWindowHandle>%MakeOpaque_var_1%,HndWin
    //constants
    Let>GWL_EXSTYLE=-20
    Let>WS_EX_LAYERED=524288
    Let>LWA_ALPHA=2
    //get style attributes of window
    LibFunc>user32,GetWindowLongA,attribs,%HndWin%,GWL_EXSTYLE
    Let>attribs={%attribs% OR %WS_EX_LAYERED%}
    //make window transparent
    LibFunc>user32,SetWindowLongA,swl,%HndWin%,GWL_EXSTYLE,attribs
    LibFunc>user32,SetLayeredWindowAttributes,res,%HndWin%,0,%MakeOpaque_var_2%,LWA_ALPHA
  EndIf
END>MakeOpaque

SRT>LeftClick
  GetActiveWindow>title,Winx,WinY
  If>title=%factor%X Magnify
    GetCursorPos>ClickX,ClickY
    CloseDialog>Dialog1
    Wait>0.1
      LDBLClick
    Wait>0.1
    Show>Dialog1
  EndIf
END>LeftClick

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts