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.
Screenshot:
Relevanter Quellcode:
DigClock.au3
Spoiler anzeigen
;******************************************************************************************
;* 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"
;;;
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 = ''
; 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
WinMain()
[/autoit] [autoit][/autoit] [autoit]Func WinMain()
Global $hWnd
Global $Msg = DllStructCreate ($tagMSG)
Global $wcx = DllStructCreate ($tagWNDCLASSEX)
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))
$lpMyWndClass = DllStructGetPtr ($wcx)
$lpMsg = DllStructGetPtr ($Msg)
If Not RegisterClassEx ($lpMyWndClass) Then
MsgBox (266256, Default, 'Die Fensterklasse konnte nicht registriert werden !')
Exit
EndIf
$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)
While (GetMessage ($lpMsg, $NULL, 0, 0) > 0)
TranslateMessage ($lpMsg)
DispatchMessage ($lpMsg)
WEnd
Return DllStructGetData ($Msg, 'wParam')
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
GetClientRect ($hWnd, $lprcClient)
$cxClient = DllStructGetData ($rcClient, 'right')
$cyClient = DllStructGetData ($rcClient, 'bottom')
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
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
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
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)
Case Else
Return DefWindowProc ($hWnd, $uMsg, $wParam, $lParam)
EndSwitch
Return 0;
EndFunc
;
DigClock.h.au3
Spoiler anzeigen
#include-once
#include "WinAPI.h.au3"
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] ]
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
;/////////////////////////////////////////////////////////////
;// DigClock Funktionen //
;/////////////////////////////////////////////////////////////
Func DisplayDigit ($hdc, $iNumber)
For $iSeg = 0 To 6
If ($fSevenSegment [$iNumber][$iSeg]) Then
Polygon ($hdc, DllStructGetPtr ($ptSegment [$iSeg]), 6) ;
EndIf
Next
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
OffsetWindowOrgEx ($hdc, -42, 0, $NULL) ;
DisplayDigit ($hdc, Mod ($iNumber, 10)) ;
OffsetWindowOrgEx ($hdc, -42, 0, $NULL) ;
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] ] ;
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
Polygon ($hdc, DllStructGetPtr ($ptColon [0]), 4)
Polygon ($hdc, DllStructGetPtr ($ptColon [1]), 4)
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)
GetLocalTime (DllStructGetPtr ($st))
[/autoit] [autoit][/autoit] [autoit]$wHour = DllStructGetData ($st, 'Hour')
$wMinute = DllStructGetData ($st, 'Minute')
$wSecond = DllStructGetData ($st, 'Second')
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
DisplayColon ($hdc)
DisplayTwoDigits ($hdc, $wMinute, FALSE)
DisplayColon ($hdc)
DisplayTwoDigits ($hdc, $wSecond, FALSE)
EndFunc
[/autoit]Gruß
Greenhorn