• Moin,

    dieses Skript zeigt die Größe des Anwendungsbereichs in Pixeln, Millimetern, Zoll und Twips an, also den metrischen Koordinatensystemen.

    Nicht mehr, aber auch nicht weniger ...

    Der Inhalt kann nicht angezeigt werden, da er nicht mehr verfügbar ist.

    Spoiler anzeigen
    [autoit]

    ;******************************************************************************************
    ;* WhatSize Demo von C.Petzold
    ;* Übersetzt in AutoIt von Greenhorn
    ;*
    #NoTrayIcon
    #include-once
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include "WinAPI.h.au3"

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Global $hWindowProc = DllCallbackRegister ('WindowProc', 'long', 'hwnd;uint;wparam;lparam')
    Global $stAppName = DllStructCreate ('char szAppName[128]')
    Global $szAppName = DllStructSetData ($stAppName, 'szAppName', 'WhatSize')
    Global $hInst = GetModuleHandle ($NULL)

    [/autoit] [autoit][/autoit] [autoit]

    ; Statische Variablen für die Fensterprozedur, müssen wir in AutoIt
    ; global setzen, gibt in AutoIt leider kein 'static'
    Global $cxChar, $cyChar
    Global $szHeading = "Koordinatensystem Left Right Top Bottom"
    Global $szUndLine = "----------------- ---- ----- --- ------"

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    WinMain ()

    [/autoit] [autoit][/autoit] [autoit]

    Func WinMain ()

    Global $hWnd
    Global $Msg = DllStructCreate ($tagMSG)
    Global $wcx = DllStructCreate ($tagWNDCLASSEX)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    DllStructSetData ($wcx,'cbSize', DllStructGetSize ($wcx))
    DllStructSetData ($wcx,'style', BitOR ($CS_HREDRAW, $CS_VREDRAW))
    DllStructSetData ($wcx,'lpfnWndProc', DllCallbackGetPtr ($hWindowProc))
    DllStructSetData ($wcx,'cbClsExtra', 0)
    DllStructSetData ($wcx,'cbWndExtra', 0)
    DllStructSetData ($wcx,'hInstance', $hInst)
    DllStructSetData ($wcx,'hIcon', LoadIcon ($NULL, $IDI_APPLICATION))
    DllStructSetData ($wcx,'hCursor', LoadCursor ($NULL, $IDC_ARROW))
    DllStructSetData ($wcx,'hbrBackground', GetStockObject ($WHITE_BRUSH))
    DllStructSetData ($wcx,'lpszMenuName', $NULL)
    DllStructSetData ($wcx,'lpszClassName', DllStructGetPtr ($stAppName))
    DllStructSetData ($wcx,'hIconSm', LoadIcon ($NULL, $IDI_APPLICATION))

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $lpMyWndClass = DllStructGetPtr ($wcx)
    $lpMsg = DllStructGetPtr ($Msg)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    If Not RegisterClassEx ($lpMyWndClass) Then
    MsgBox (266256, Default, 'Die Fensterklasse konnte nicht registriert werden !')
    Exit
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $hWnd = CreateWindowEx ($WS_EX_COMPOSITED, _ ; verhindert "Flickern"
    $szAppName, 'Wie groß ist das Fenster?', _
    $WS_OVERLAPPEDWINDOW, _
    $CW_USEDEFAULT, $CW_USEDEFAULT, _
    $CW_USEDEFAULT, $CW_USEDEFAULT, _
    $NULL, $NULL, $hInst, $NULL)

    ShowWindow ($hWnd, 5)
    UpdateWindow ($hWnd)

    [/autoit] [autoit][/autoit] [autoit]

    While (GetMessage ($lpMsg, $NULL, 0, 0) > 0)

    TranslateMessage ($lpMsg)
    DispatchMessage ($lpMsg)

    WEnd

    Return DllStructGetData ($Msg, 'wParam')

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func Show ($hwnd, $hdc, $xText, $yText, $iMapMode, $szMapMode)

    [/autoit] [autoit][/autoit] [autoit]

    Local $szBuffer
    $rcClient = DllStructCreate ($tagRECT)
    $lprcClient = DllStructGetPtr ($rcClient)
    SaveDC ($hdc)

    SetMapMode ($hdc, $iMapMode)
    GetClientRect ($hwnd, $lprcClient)
    DPtoLP ($hdc, $lprcClient, 2)

    RestoreDC ($hdc, -1)

    $left = DllStructGetData($rcClient, "Left")
    $top = DllStructGetData($rcClient, "Top")
    $right = DllStructGetData($rcClient, "Right")
    $bottom = DllStructGetData($rcClient, "Bottom")

    $szBuffer = StringFormat("%-20s %7d %7d %7d %7d", $szMapMode, _
    $left, $right, $top, $bottom)

    TextOut ($hdc, $xText, $yText, _
    $szBuffer, _
    StringLen ($szBuffer))

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func WindowProc ($hWnd, $uMsg, $wParam, $lParam)

    $rcClient = DllStructCreate ($tagRECT)
    $lprcClient = DllStructGetPtr ($rcClient)
    $ps = DllStructCreate ($tagPAINTSTRUCT)
    $lpPs = DllStructGetPtr ($ps)
    $tm = DllStructCreate ($tagTEXTMETRIC)
    $lptm = DllStructGetPtr ($tm)

    Switch $uMsg

    Case $WM_CREATE
    $hdc = GetDC ($hWnd) ;
    SelectObject ($hdc, GetStockObject ($SYSTEM_FIXED_FONT)) ;

    GetTextMetrics ($hdc, DllStructGetPtr ($tm)) ;
    $cxChar = DllStructGetData ($tm, 'tmAveCharWidth') ;
    $cyChar = DllStructGetData ($tm, 'tmHeight') + DllStructGetData ($tm, 'tmExternalLeading') ;

    ReleaseDC ($hWnd, $hdc) ;

    Case $WM_PAINT
    $hDC = BeginPaint ($hWnd, $lpPs)

    SelectObject ($hDC, GetStockObject ($SYSTEM_FIXED_FONT)) ;
    SetMapMode ($hDC, $MM_ANISOTROPIC) ; Koordinatensystem auf MM_ANISOTROPIC umstellen
    SetWindowExtEx ($hDC, 1, 1, $NULL) ; Ausmaße des Darstellungsfeldes für das Fenster
    SetViewportExtEx ($hDC, $cxChar, $cyChar, $NULL) ; Ausmaße des Darstellungsfeldes für den Gerätekontext

    [/autoit] [autoit][/autoit] [autoit]

    TextOut ($hDC, 1, 1, $szHeading, StringLen ($szHeading)) ;
    TextOut ($hDC, 1, 2, $szUndLine, StringLen ($szUndLine)) ;

    Show ($hWnd, $hDC, 1, 3, $MM_TEXT, "TEXT (pixels)") ;
    Show ($hWnd, $hDC, 1, 4, $MM_LOMETRIC, "LOMETRIC (.1 mm)") ;
    Show ($hWnd, $hDC, 1, 5, $MM_HIMETRIC, "HIMETRIC (.01 mm)") ;
    Show ($hWnd, $hDC, 1, 6, $MM_LOENGLISH, "LOENGLISH (.01 in)") ;
    Show ($hWnd, $hDC, 1, 7, $MM_HIENGLISH, "HIENGLISH (.001 in)") ;
    Show ($hWnd, $hDC, 1, 8, $MM_TWIPS, "TWIPS (1/1440 in)") ;

    EndPaint ($hWnd, $lpPs)

    Case $WM_DESTROY
    PostQuitMessage (0)

    [/autoit] [autoit][/autoit] [autoit]

    Case Else
    Return DefWindowProc ($hWnd, $uMsg, $wParam, $lParam)
    EndSwitch

    Return 0;

    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit]


    Gruß
    Greenhorn