- Offizieller Beitrag
Ich kann euch nun mein neuestes Werk präsentieren: ein Bildschirm-Lineal mit mm/cm Einteilung.
Das Script:
Spoiler anzeigen
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=Bildschirm-Lineal.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Description=Bildschirm-Lineal (mm/cm)
#AutoIt3Wrapper_Res_Fileversion=1.5.0.0
#AutoIt3Wrapper_Res_LegalCopyright=by Oscar (http://www.autoit.de)
#AutoIt3Wrapper_Res_Language=1031
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#NoTrayIcon
#include<ButtonConstants.au3>
#include<EditConstants.au3>
#include<Misc.au3>
#include<WindowsConstants.au3>
#include<SliderConstants.au3>
#include<StaticConstants.au3>
#include<GUIConstantsEx.au3>
Opt('GUIOnEventMode', 1)
[/autoit] [autoit][/autoit] [autoit]Global $sTitle = 'Bildschirm-Lineal v1.5', $bStart = False, $hLenght
Global $ppcm = IniRead(@ScriptDir & '\Bildschirm-Lineal.ini', 'PixelPerZentimeter', @DesktopWidth & 'x' & @DesktopHeight, -1)
Global $cm = IniRead(@ScriptDir & '\Bildschirm-Lineal.ini', 'Länge', 'cm', 20)
Global $PosX = IniRead(@ScriptDir & '\Bildschirm-Lineal.ini', 'Position', 'X', -1)
Global $PosY = IniRead(@ScriptDir & '\Bildschirm-Lineal.ini', 'Position', 'Y', -1)
Global $Trans = IniRead(@ScriptDir & '\Bildschirm-Lineal.ini', 'Transparenz', 'Wert', 100)
Global $bInfo = Execute(IniRead(@ScriptDir & '\Bildschirm-Lineal.ini', 'Mausposition', 'anzeigen', False))
If $ppcm = -1 Then _PPCMSetup()
If $cm < 10 Then $cm = 10
Global $width = $ppcm * $cm + 30
Global $height = 170
Global $max = Int((@DesktopWidth - 40) / $ppcm)
GUICreate($sTitle, $width, $height, $PosX, $PosY, $WS_POPUPWINDOW, $WS_EX_DLGMODALFRAME)
GUISetBkColor(0xEEEEEE) ; Hintergrundfarbe
Global $hLabel = GUICtrlCreateLabel('', 0, 0, $width, $height, Default, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
Global $hContext = GUICtrlCreateContextMenu($hLabel)
Global $hMInfo = GUICtrlCreateMenuItem('Mausposition anzeigen', $hContext)
GUICtrlSetOnEvent(-1, '_Mausinfo')
GUICtrlCreateMenuItem('PPCM-Einstellung', $hContext)
GUICtrlSetOnEvent(-1, '_PPCMSetup')
GUICtrlCreateMenuItem('', $hContext)
GUICtrlCreateMenuItem('Programm beenden', $hContext)
GUICtrlSetOnEvent(-1, '_End')
Switch $bInfo
Case True
GUICtrlSetState($hMInfo, $GUI_CHECKED)
Case False
GUICtrlSetState($hMInfo, $GUI_UNCHECKED)
EndSwitch
Global $hLenght = GUICtrlCreateInput($cm, 16, 80, 30, 26, $ES_Center)
GUICtrlSetFont(-1, 12, 600, 0, 'Times New Roman')
GUICtrlSetBkColor(-1, 0xEEEEEE)
GUICtrlSetOnEvent(-1, '_EnterInput')
GUICtrlSetState(-1, $GUI_ONTOP)
GUICtrlCreateLabel('cm', 50, 80, 28, 24, Default, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 16, 400, 0, 'Times New Roman')
Global $hSlider = GUICtrlCreateSlider($width / 2 - 110, 80, 255, 30, $TBS_AUTOTICKS)
GUICtrlSetData(-1, $Trans)
GUICtrlSetBkColor(-1, 0xEEEEEE)
GUICtrlSetState(-1, $GUI_ONTOP)
GUICtrlSetOnEvent(-1, '_SetTrans')
GUICtrlCreateLabel('Transparenz-Einstellung', $width / 2 - 110, 110, 260, 30, $SS_CENTER, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 12, 400, 0, 'Times New Roman')
GUICtrlCreateLabel($sTitle, $width / 2 - 110, 50, 260, 30, $SS_CENTER, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 18, 400, 0, 'Times New Roman')
GUICtrlCreateLabel('mm/cm', 8, 44, 60, 30, Default, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 12, 400, 0, 'Times New Roman')
GUICtrlCreateLabel('Pixel', 8, $height - 50, 60, 30, Default, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 12, 400, 0, 'Times New Roman')
Global $hGraph = GUICtrlCreateGraphic(14, 0, $width - 26, $height)
For $i = 0 To $cm
GUICtrlSetGraphic($hGraph, $GUI_GR_MOVE, 3 + $i * $ppcm, 0)
GUICtrlSetGraphic($hGraph, $GUI_GR_LINE, 3 + $i * $ppcm, 40)
GUICtrlCreateLabel($i, $i * $ppcm, 28, 12, 16, $SS_RIGHT)
Next
For $i = 0 To $cm * 10
GUICtrlSetGraphic($hGraph, $GUI_GR_MOVE, 3 + $i * $ppcm / 10, 0)
GUICtrlSetGraphic($hGraph, $GUI_GR_LINE, 3 + $i * $ppcm / 10, 15 + 6 * ($i / 5 = Int($i / 5)))
Next
For $i = 0 To $width - 26 Step 10
GUICtrlSetGraphic($hGraph, $GUI_GR_MOVE, 3 + $i, $height - 8 - 22 * ($i / 100 = Int($i / 100)))
GUICtrlSetGraphic($hGraph, $GUI_GR_LINE, 3 + $i, $height)
If ($i / 100 = Int($i / 100)) Then GUICtrlCreateLabel($i, $i - 18, $height - 30, 30, 16, $SS_RIGHT)
Next
Global $hEnd = GUICtrlCreateButton('X', $width - 38, 80, 26, 26, $BS_CENTER)
GUICtrlSetFont(-1, 14, 600, 0, 'Arial')
GUICtrlSetState(-1, $GUI_ONTOP)
GUICtrlSetOnEvent(-1, '_End')
GUICtrlSetState($hLenght, $GUI_FOCUS)
GUISetState()
WinSetTrans($sTitle, '', 215 / 100 * $Trans + 40)
[/autoit] [autoit][/autoit] [autoit]Global $aWPos, $sMsg, $oldDisplayMode = @DesktopWidth & 'x' & @DesktopHeight
While True
Sleep(20)
If $bInfo Then
GUISetCursor(3, 1)
$aWPos = WinGetPos($sTitle)
$sMsg = 'rel. Maus-Position (Bezugspunkt: 0 cm): ' & @CRLF & @CRLF
$sMsg &= @TAB & ' X' & @TAB & ' Y' & @CRLF
$sMsg &= 'Pixel:' & @TAB & MouseGetPos(0) - $aWPos[0] - 20 & @TAB & MouseGetPos(1) - $aWPos[1] - 3 & @CRLF
$sMsg &= 'cm: ' & @TAB & StringFormat('%.1f', (MouseGetPos(0) - $aWPos[0] - 20) / $ppcm) & @TAB & StringFormat('%.1f', (MouseGetPos(1) - $aWPos[1] - 3) / $ppcm)
Else
GUISetCursor(2, 1)
$sMsg = ''
EndIf
ToolTip($sMsg, Default, Default, $sTitle, 1)
If @DesktopWidth & 'x' & @DesktopHeight <> $oldDisplayMode Then
_ReadPPCM()
$oldDisplayMode = @DesktopWidth & 'x' & @DesktopHeight
EndIf
WEnd
Func _End()
If WinActive($sTitle) Then
Local $aPos = WinGetPos($sTitle)
IniWrite(@ScriptDir & '\Bildschirm-Lineal.ini', 'Länge', 'cm', GUICtrlRead($hLenght))
IniWrite(@ScriptDir & '\Bildschirm-Lineal.ini', 'Position', 'X', $aPos[0])
IniWrite(@ScriptDir & '\Bildschirm-Lineal.ini', 'Position', 'Y', $aPos[1])
EndIf
IniWrite(@ScriptDir & '\Bildschirm-Lineal.ini', 'PixelPerZentimeter', @DesktopWidth & 'x' & @DesktopHeight, $ppcm)
If $bStart Then
If @Compiled Then
Run(@AutoItExe)
Else
Run('"' & @AutoItExe & '" /ErrorStdOut "' & @ScriptFullPath & '"')
EndIf
EndIf
Exit
EndFunc ;==>_End
Func _ReadPPCM()
$ppcm = IniRead(@ScriptDir & '\Bildschirm-Lineal.ini', 'PixelPerZentimeter', @DesktopWidth & 'x' & @DesktopHeight, -1)
If $ppcm = -1 Then _PPCMSetup()
$bStart = True
_End()
EndFunc
Func _SetTrans()
$Trans = GUICtrlRead($hSlider)
WinSetTrans($sTitle, '', 215 / 100 * $Trans + 40)
IniWrite(@ScriptDir & '\Bildschirm-Lineal.ini', 'Transparenz', 'Wert', $Trans)
GUICtrlSetState($hLenght, $GUI_FOCUS)
EndFunc ;==>_SetTrans
Func _Mausinfo()
$bInfo = Not $bInfo
Switch $bInfo
Case True
GUICtrlSetState($hMInfo, $GUI_CHECKED)
Case False
GUICtrlSetState($hMInfo, $GUI_UNCHECKED)
EndSwitch
IniWrite(@ScriptDir & '\Bildschirm-Lineal.ini', 'Mausposition', 'anzeigen', $bInfo)
EndFunc ;==>_Mausinfo
Func _EnterInput()
If GUICtrlRead($hLenght) < 10 Then GUICtrlSetData($hLenght, 10)
If GUICtrlRead($hLenght) > $max Then GUICtrlSetData($hLenght, $max)
$bStart = True
_End()
EndFunc ;==>_EnterInput
Func _PPCMSetup()
Opt('GUIOnEventMode', 0)
Local $dll = DllOpen('user32.dll')
GUICreate('PPCM-Einstellung', 620, 180, -1, -1, $WS_POPUPWINDOW, $WS_EX_DLGMODALFRAME)
Local $msg = '"Pixel pro Zentimeter" - Einstellung' & @CRLF & @CRLF
$msg &= 'Legen Sie ein Lineal an den Startpunkt und klicken Sie exakt bei 10 cm auf die grüne Linie.'
GUICtrlCreateLabel($msg, 10, 10, 600, 40)
$End = GUICtrlCreateLabel('', 10, 73, 600, 3)
GUICtrlSetBkColor(-1, 0x00FF00)
GUICtrlCreateLabel('', 10, 66, 1, 17)
GUICtrlSetBkColor(-1, 0x000000)
$Start = GUICtrlCreateLabel('', 2, 74, 18, 1)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlCreateLabel('Startpunkt', 15, 80, 120, 16)
GUICtrlCreateLabel('Mit den Pfeiltasten können Sie den Mauszeiger um einen Pixel nach links bzw. rechts bewegen.', 10, 110, 600, 16)
GUICtrlCreateLabel('Die [Return]-Taste ist mit einem Mausklick identisch', 10, 130, 600, 16)
GUICtrlCreateLabel('und die [ESC]-Taste schließt dieses Fenster ohne eine Änderung vorzunehmen.', 10, 150, 600, 16)
$pos = WinGetPos(GUICtrlGetHandle($Start))
$pos[0] += Floor($pos[2] / 2)
GUISetState()
GUISetCursor(3, 1)
_MouseTrap($pos[0], $pos[1], $pos[0] + 600, $pos[1] + 1)
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then
GUIDelete()
GUISetCursor(2, 1)
_MouseTrap()
Opt('GUIOnEventMode', 1)
DllClose($dll)
ToolTip('')
Return
EndIf
If _IsPressed('25', $dll) Then
MouseMove(MouseGetPos(0) - 1, MouseGetPos(1))
While _IsPressed('25', $dll)
Sleep(5)
WEnd
EndIf
If _IsPressed('27', $dll) Then
MouseMove(MouseGetPos(0) + 1, MouseGetPos(1))
While _IsPressed('27', $dll)
Sleep(5)
WEnd
EndIf
If _IsPressed('0D', $dll) Or $msg = $End Then
$pixels = MouseGetPos(0) - $pos[0]
_MouseTrap()
ToolTip('')
ExitLoop
EndIf
ToolTip((MouseGetPos(0) - $pos[0]) / 10)
WEnd
GUIDelete()
$ppcm = $pixels / 10
$bStart = True
DllClose($dll)
_End()
EndFunc ;==>_PPCMSetup
Edit ( 26.10.08 Version 1.5
- Die Länge des Lineals kann man durch Eingabe einer Zentimeter-Zahl bestimmen.
- Die Einstellungen ("PixelProZentimeter", Länge des Lineals und die letzte Position) werden in einer Inidatei gespeichert.
- Beim ersten Start wird ein Einstellungsfenster geöffnet, indem man die "Pixel pro Zentimeter" einstellen kann. Dieses kann man später auch per Kontextmenü aufrufen.
- Die Transparenz des Fensters ist nun einstellbar.
- Zusätzliche Skala mit Pixelanzeige.
- Im Kontextmenü kann man nun die "rel. Mausposition" als Tooltip aktivieren.
- Die "Pixel pro Zentimeter"-Werte werden nun für jede Auflösung extra gespeichert und beim Auflösungs-Wechsel automatisch eingelesen.