Jump to content

Recommended Posts

Posted

Nice work. :thumbsup:

 

You may use _WinAPI_UpdateLayeredWindow() for better display quality.

 

Here an old example:

;Coded by UEZ
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global Const $SC_DRAGMOVE = 0xF012
Global $iW = 300, $iH = 100, $hHBitmap
Global $hGUI = GUICreate("GDI+ Transparent Digital Clock", $iW, $iH, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
GUISetState(@SW_SHOW, $hGUI)

_GDIPlus_Startup()

Global $hBrush = _GDIPlus_BrushCreateSolid(0xD80000A0)
Global $hFormat = _GDIPlus_StringFormatCreate()
Global $hFamily = _GDIPlus_FontFamilyCreate("Impact")
Global $hFont = _GDIPlus_FontCreate($hFamily, 56)
Global $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH)
_GDIPlus_StringFormatSetAlign($hFormat, 0)
Global $hImage = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
Global $hGfx = _GDIPlus_ImageGetGraphicsContext($hImage)
_GDIPlus_GraphicsSetTextRenderingHint($hGfx, 4)
_GDIPlus_GraphicsSetSmoothingMode($hGfx, 4)

GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")

_ShowTime()
AdlibRegister("_ShowTime", 1000)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

AdlibUnRegister("_ShowTime")
_WinAPI_DeleteObject($hHBitmap)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGfx)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
GUIDelete()


Func _ShowTime()
    _GDIPlus_GraphicsClear($hGfx, 0x00000000)
    _GDIPlus_GraphicsDrawStringEx($hGfx, @HOUR & ":" & @MIN & ":" & @SEC, $hFont, $tLayout, $hFormat, $hBrush)
    $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _WinAPI_BitmapDisplayTransparentInGUI($hHBitmap, $hGUI)
    _WinAPI_DeleteObject($hHBitmap)
EndFunc

Func _WinAPI_BitmapDisplayTransparentInGUI(ByRef $hHBitmap, ByRef $hGUI, $iOpacity = 0xFF, $bReleaseGDI = True)
    If Not BitAND(GUIGetStyle($hGUI)[1], $WS_EX_LAYERED) = $WS_EX_LAYERED Then Return SetError(1, 0, 0)
    Local $tDim = DllStructCreate($tagBITMAP)
    If Not _WinAPI_GetObject($hHBitmap, DllStructGetSize($tDim), DllStructGetPtr($tDim)) Then Return SetError(2, 0, 0)
    Local $tSize = DllStructCreate($tagSIZE), $tSource = DllStructCreate($tagPOINT), $tBlend = DllStructCreate($tagBLENDFUNCTION)
    Local Const $hScrDC = _WinAPI_GetDC(0), $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC), $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
    $tSize.X = $tDim.bmWidth
    $tSize.Y = $tDim.bmHeight
    $tBlend.Alpha = $iOpacity
    $tBlend.Format = 1
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, DllStructGetPtr($tSize), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteDC($hMemDC)
    If $bReleaseGDI Then _WinAPI_DeleteObject($hHBitmap)
    Return True
EndFunc

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    Switch $hWnd
        Case $hGUI
            _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
    EndSwitch
EndFunc   ;==>_WM_LBUTTONDOWN

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

off topic but, messing around with @UEZ's code:

Spoiler
Global $sVar = "01"
;~ Global $sVar = "02"
ConsoleWrite( ( Int($sVar) = 0 Or Int($sVar) = 1   ? "TRUE" : "FALSE" ) & @CRLF)
ConsoleWrite(   Int($sVar) = 0 Or Int($sVar) = 1   ? "TRUE" : "FALSE"    & @CRLF)
ConsoleWrite( ( Int($sVar) = 0 Or Int($sVar) = 1 ) ? "TRUE" : "FALSE"    & @CRLF)
Exit




;Coded by UEZ
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3> ;;; https://www.autoitscript.com/forum/topic/213036-%F0%9F%95%91-analog-clock/#findComment-1544846
#include <WinAPI.au3>

Global Const $SC_DRAGMOVE = 0xF012
Global $iW = 400, $iH = 100, $hHBitmap
Global $hGUI = GUICreate("GDI+ Transparent Digital Clock", $iW, $iH, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
GUISetState(@SW_SHOW, $hGUI)

_GDIPlus_Startup()

;~ Global $hBrush = _GDIPlus_BrushCreateSolid(0xD80000A0)
Global $hBrush = _GDIPlus_BrushCreateSolid(0xD800A000)
Global $hBrush2 = _GDIPlus_BrushCreateSolid(0xD8A00000)
Global $hFormat = _GDIPlus_StringFormatCreate()
Global $hFamily = _GDIPlus_FontFamilyCreate("Impact")
Global $hFont = _GDIPlus_FontCreate($hFamily, 56)
Global $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH)
_GDIPlus_StringFormatSetAlign($hFormat, 0)
Global $hImage = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
Global $hGfx = _GDIPlus_ImageGetGraphicsContext($hImage)
_GDIPlus_GraphicsSetTextRenderingHint($hGfx, 4)
_GDIPlus_GraphicsSetSmoothingMode($hGfx, 4)

GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")

_ShowTime()
;~ AdlibRegister("_ShowTime", 100)

Global $now = ""
While GUIGetMsg() <> $GUI_EVENT_CLOSE
    If $now = @SEC Then ContinueLoop
    $now = @SEC
    _ShowTime() ; 10 ms accuracy  =)
WEnd

;~ Do
;~ Until GUIGetMsg() = $GUI_EVENT_CLOSE

AdlibUnRegister("_ShowTime")
_WinAPI_DeleteObject($hHBitmap)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_BrushDispose($hBrush2)
_GDIPlus_GraphicsDispose($hGfx)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
GUIDelete()


Func _ShowTime()
;~  Local Static $now = 66
;~  If $now = @SEC Then Return
;~  $now = @SEC
    _GDIPlus_GraphicsClear($hGfx, 0x00000000)
;~     _GDIPlus_GraphicsDrawStringEx($hGfx, @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC, $hFont, $tLayout, $hFormat, $hBrush)
    _GDIPlus_GraphicsDrawStringEx($hGfx, @HOUR & ":" & @MIN & ":" & @SEC, $hFont, $tLayout, $hFormat, ((Int(@SEC) = 0 Or Int(@SEC) = 1) ? $hBrush2 : $hBrush) )
    _GDIPlus_GraphicsDrawStringEx($hGfx, @HOUR & ":" & @MIN & ":" & @SEC, $hFont, $tLayout, $hFormat, ( Int(@SEC) = 0 Or Int(@SEC) = 1 ? $hBrush2 : $hBrush)  ) ; fails at "00"
;~     _GDIPlus_GraphicsDrawStringEx($hGfx, @HOUR & ":" & @MIN & ":" & @SEC, $hFont, $tLayout, $hFormat, (Int(@SEC) = 0 ? $hBrush2 : $hBrush))
    $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _WinAPI_BitmapDisplayTransparentInGUI($hHBitmap, $hGUI)
    _WinAPI_DeleteObject($hHBitmap)
EndFunc   ;==>_ShowTime

Func _WinAPI_BitmapDisplayTransparentInGUI(ByRef $hHBitmap, ByRef $hGUI, $iOpacity = 0xFF, $bReleaseGDI = True)
    If Not BitAND(GUIGetStyle($hGUI)[1], $WS_EX_LAYERED) = $WS_EX_LAYERED Then Return SetError(1, 0, 0)
    Local $tDim = DllStructCreate($tagBITMAP)
    If Not _WinAPI_GetObject($hHBitmap, DllStructGetSize($tDim), DllStructGetPtr($tDim)) Then Return SetError(2, 0, 0)
    Local $tSize = DllStructCreate($tagSIZE), $tSource = DllStructCreate($tagPOINT), $tBlend = DllStructCreate($tagBLENDFUNCTION)
    Local Const $hScrDC = _WinAPI_GetDC(0), $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC), $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
    $tSize.X = $tDim.bmWidth
    $tSize.Y = $tDim.bmHeight
    $tBlend.Alpha = $iOpacity
    $tBlend.Format = 1
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, DllStructGetPtr($tSize), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteDC($hMemDC)
    If $bReleaseGDI Then _WinAPI_DeleteObject($hHBitmap)
    Return True
EndFunc   ;==>_WinAPI_BitmapDisplayTransparentInGUI

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    Switch $hWnd
        Case $hGUI
            _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
    EndSwitch
EndFunc   ;==>_WM_LBUTTONDOWN

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc   ;==>WM_NCHITTEST

I've found that this:

Global $sVar = "01"
;~ Global $sVar = "02"
ConsoleWrite( ( Int($sVar) = 0 Or Int($sVar) = 1   ? "TRUE" : "FALSE" ) & @CRLF)
ConsoleWrite(   Int($sVar) = 0 Or Int($sVar) = 1   ? "TRUE" : "FALSE"    & @CRLF)
ConsoleWrite( ( Int($sVar) = 0 Or Int($sVar) = 1 ) ? "TRUE" : "FALSE"    & @CRLF)
Exit

don't behave all the same. Am I
(1): doing something wrong or is it a bug ?
(2): if is it a bug that deserves mention ?

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted

0 or 0 = 0

0 or 1 = 1

1 or 0 = 1

1 or 1 = 1

The behavior seems to be normal always to be true because Int($sVar) is 1 -> 0 or 1 = 1

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

  • Solution
Posted (edited)

New release 0.11

Basic changes

      Now the clock is updated with a timer and not in the main loop, or with AdlibRegister, so that it does not freeze with the tray menu or the settings GUIs

      The movement of the hands is done in an analog manner and does not jump from minute to minute or hour to hour.

      Now moving the clock can also be done with a long press on the center of the clock.

      You don't need an additional image because it does it by itself,  but it can also accept an external image.

      I put a settings GUI for selecting clock colors. (if the changes concern the background image, they will be applied after deleting the background image)

      Ability to change the size of the clock, through the ini file

I made it Swiss  :lol:
 

update in the first post

 

Please, every comment is appreciated!
leave your comments and experiences here!
Thank you very much  :)

 

Edited by ioa747

I know that I know nothing

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...