• Moinsen,

    habe ein Beispiel, welches ich in einem Buch gefunden habe, einer digitalen Anzeige in einem Fenster in AutoIt übersetzt.
    Drauf gekommen bin ich beim Lesen des Buches und da fiel mir ein das Oscar da doch irgendwas mit 'ner Digitaluhr geskriptet hatte.
    Vielleicht kann Oscar das ja für seine geniale Digitaluhr gebrauchen. ;)

    Es passiert eigentlich nicht viel, außer dass die Uhrzeit im Anwendungsbereich des Fensters digital angezeigt wird. :rolleyes:
    Screenshot:

    Relevanter Quellcode:
    DigClock.au3

    Spoiler anzeigen
    [autoit]

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

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

    Global Const $WM_SETTINGCHANGE = 0x001A

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

    Global Const $ID_TIMER = 1

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

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

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

    ; Statische Variablen für die Fensterprozedur, müssen wir in AutoIt
    ; global setzen, gibt in AutoIt leider kein 'static'
    Global $f24hour = False, $fSuppress = False
    Global $cxClient, $cyClient, $hBrushRed

    [/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 ($BLACK_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, $szAppName, _
    $WS_OVERLAPPEDWINDOW, _
    $CW_USEDEFAULT, $CW_USEDEFAULT, _
    544, 375, _
    $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 WindowProc ($hWnd, $uMsg, $wParam, $lParam)

    $szBuffer = DllStructCreate ('char szBuffer[2]')
    $lpszBuffer = DllStructGetPtr ($szBuffer)
    $rcClient = DllStructCreate ($tagRECT)
    $lprcClient = DllStructGetPtr ($rcClient)

    Switch $uMsg

    Case $WM_CREATE
    $hBrushRed = CreateSolidBrush (RGB (255, 0, 0)) ; Rotes Füllmuster für die Segmente erzeugen
    SetTimer ($hWnd, $ID_TIMER, 1000, $NULL)
    ContinueCase ; weiter mit WM_SETTINGCHANGE

    Case $WM_SETTINGCHANGE
    GetLocaleInfo ($LOCALE_USER_DEFAULT, $LOCALE_ITIME, $lpszBuffer, 2)
    $f24hour = (DllStructGetData ($szBuffer, 'szBuffer', 1) == '1') ; TRUE wenn 1

    GetLocaleInfo ($LOCALE_USER_DEFAULT, $LOCALE_ITLZERO, $lpszBuffer, 2) ;
    $fSuppress = (DllStructGetData ($szBuffer, 'szBuffer', 1) == '0') ; TRUE wenn 0

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

    GetClientRect ($hWnd, $lprcClient)
    $cxClient = DllStructGetData ($rcClient, 'right')
    $cyClient = DllStructGetData ($rcClient, 'bottom')

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

    InvalidateRect ($hWnd, $NULL, TRUE) ; löst eine WM_PAINT Nachricht aus

    Case $WM_SIZE
    $cxClient = LOWORD ($lParam) ; Bei Größenänderung Breite
    $cyClient = HIWORD ($lParam) ; und Höhe ermitteln

    Case $WM_TIMER
    InvalidateRect ($hWnd, $NULL, TRUE) ; löst eine WM_PAINT Nachricht aus

    Case $WM_PAINT
    $ps = DllStructCreate ($tagPAINTSTRUCT)
    $lpPs = DllStructGetPtr ($ps)

    $hDC = BeginPaint ($hWnd, $lpPs)

    SetMapMode ($hDC, $MM_ISOTROPIC) ; Koordinatensystem auf MM_ISOTROPIC umstellen
    SetWindowExtEx ($hDC, 276, 72, $NULL) ; Ausmaße des Darstellungsfeldes für das Fenster
    SetViewportExtEx ($hDC, $cxClient, $cyClient, $NULL) ; Ausmaße des Darstellungsfeldes für den Gerätekontext

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

    SetWindowOrgEx ($hDC, 138, 36, $NULL) ; Punkt im Fenster, der zum Ursprung des Darstellungsfeldes (0,0) "gemappt" wird
    SetViewportOrgEx ($hDC, $cxClient / 2, $cyClient / 2, $NULL) ; Punkt im Gerätekontext, der zum Ursprung des Fensters "gemappt" wird

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

    SelectObject ($hDC, GetStockObject ($NULL_PEN)) ; "leeren" Zeichenstift in den Gerätekontext einsetzen
    SelectObject ($hDC, $hBrushRed) ; Füllmuster für die Segmente in den Gerätekontext einsetzen

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

    DisplayTime ($hDC, $f24Hour, $fSuppress) ;

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

    EndPaint ($hWnd, $lpPs)

    Case $WM_CLOSE
    DestroyWindow ($hWnd)

    Case $WM_DESTROY
    KillTimer ($hWnd, $ID_TIMER)
    DeleteObject ($hBrushRed) ; Aufräumarbeiten
    PostQuitMessage (0)

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

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

    Return 0;

    EndFunc
    ;

    [/autoit]


    DigClock.h.au3

    Spoiler anzeigen
    [autoit]

    #include-once
    #include "WinAPI.h.au3"

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

    Dim $fSevenSegment [10][7] = [ [1, 1, 1, 0, 1, 1, 1], _ ; // 0
    [0, 0, 1, 0, 0, 1, 0], _ ; // 1
    [1, 0, 1, 1, 1, 0, 1], _ ; // 2
    [1, 0, 1, 1, 0, 1, 1], _ ; // 3
    [0, 1, 1, 1, 0, 1, 0], _ ; // 4
    [1, 1, 0, 1, 0, 1, 1], _ ; // 5
    [1, 1, 0, 1, 1, 1, 1], _ ; // 6
    [1, 0, 1, 0, 0, 1, 0], _ ; // 7
    [1, 1, 1, 1, 1, 1, 1], _ ; // 8
    [1, 1, 1, 1, 0, 1, 1] ] ; // 9
    ; x, y; x, y; x, y; x, y; x, y; x, y
    Dim $aSegment [7][12] = [ [ 7, 6, 11, 2, 31, 2, 35, 6, 31, 10, 11, 10], _
    [ 6, 7, 10, 11, 10, 31, 6, 35, 2, 31, 2, 11], _
    [36, 7, 40, 11, 40, 31, 36, 35, 32, 31, 32, 11], _
    [ 7, 36, 11, 32, 31, 32, 35, 36, 31, 40, 11, 40], _
    [ 6, 37, 10, 41, 10, 61, 6, 65, 2, 61, 2, 41], _
    [36, 37, 40, 41, 40, 61, 36, 65, 32, 61, 32, 41], _
    [ 7, 66, 11, 62, 31, 62, 35, 66, 31, 70, 11, 70] ]

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

    Dim $ptSegment [7]

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

    For $i = 0 To 6
    $ptSegment [$i] = DllStructCreate ('int [12]')
    For $ii = 0 To 11
    DllStructSetData ($ptSegment [$i], 1, $aSegment [$i][$ii], $ii + 1)
    Next
    Next

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

    ;/////////////////////////////////////////////////////////////
    ;// DigClock Funktionen //
    ;/////////////////////////////////////////////////////////////
    Func DisplayDigit ($hdc, $iNumber)

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

    For $iSeg = 0 To 6
    If ($fSevenSegment [$iNumber][$iSeg]) Then
    Polygon ($hdc, DllStructGetPtr ($ptSegment [$iSeg]), 6) ;
    EndIf
    Next

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

    EndFunc

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

    Func DisplayTwoDigits ($hdc, $iNumber, $fSuppress)

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

    If (Not $fSuppress Or ($iNumber / 10 <> 0)) Then
    DisplayDigit ($hdc, $iNumber / 10) ;
    EndIf

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

    OffsetWindowOrgEx ($hdc, -42, 0, $NULL) ;
    DisplayDigit ($hdc, Mod ($iNumber, 10)) ;
    OffsetWindowOrgEx ($hdc, -42, 0, $NULL) ;

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

    EndFunc

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

    Func DisplayColon ($hdc)

    Local $ptColon [2]
    ; x, y; x, y; x, y; x, y
    Local $aColon [2][8] = [ [ 2, 21, 6, 17, 10, 21, 6, 25] , _
    [ 2, 51, 6, 47, 10, 51, 6, 55] ] ;

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

    For $i = 0 To 1
    $ptColon [$i] = DllStructCreate ('int [8]')
    For $ii = 0 To 7
    DllStructSetData ($ptColon [$i], 1, $aColon [$i][$ii], $ii + 1)
    Next
    Next

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

    Polygon ($hdc, DllStructGetPtr ($ptColon [0]), 4)
    Polygon ($hdc, DllStructGetPtr ($ptColon [1]), 4)

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

    OffsetWindowOrgEx ($hdc, -12, 0, $NULL)

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

    EndFunc

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

    Func DisplayTime ($hdc, $f24Hour, $fSuppress)

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

    Local $wHour, $wMinute, $wSecond
    Local $st = DllStructCreate ($tagSYSTEMTIME)

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

    GetLocalTime (DllStructGetPtr ($st))

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

    $wHour = DllStructGetData ($st, 'Hour')
    $wMinute = DllStructGetData ($st, 'Minute')
    $wSecond = DllStructGetData ($st, 'Second')

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

    If ($f24Hour) Then
    DisplayTwoDigits ($hdc, $wHour, $fSuppress) ;
    Else
    If ($wHour = Mod ($wHour, 12)) Then
    DisplayTwoDigits ($hdc, $wHour, $fSuppress)
    Else
    DisplayTwoDigits ($hdc, 12, $fSuppress)
    EndIf
    EndIf

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

    DisplayColon ($hdc)
    DisplayTwoDigits ($hdc, $wMinute, FALSE)
    DisplayColon ($hdc)
    DisplayTwoDigits ($hdc, $wSecond, FALSE)

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

    EndFunc

    [/autoit]


    Gruß
    Greenhorn


    Einmal editiert, zuletzt von Greenhorn (12. Oktober 2008 um 21:50)