[Ex] - DigClock
Posté : dim. 12 oct. 2008 07:08
par Greenhorn
Moin et Bonjour community,
here is an example I translated from C code to AutoIt.
The source is, like in my last sample "Hello AutoIt" from C. Petzold.
It is just another useless application, but funny ...
The full code is attached ...
Salut
Greenhorn
here is an example I translated from C code to AutoIt.
The source is, like in my last sample "Hello AutoIt" from C. Petzold.
It is just another useless application, but funny ...
► Afficher le textecode
Code : Tout sélectionner
;******************************************************************************************
;* 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
Global Const $ID_TIMER = 1
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()
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
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) ;
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
Salut
Greenhorn
- DigClock.zip
- (5.95 Kio) Téléchargé 453 fois