Func _Popup1()
Local $hGraphic, $hArea, $hBitmap, $hFamily, $hFont, $hFormat, $hBrush, $tLayout, $aData
Local $Text = StringFormat('%01d:%02d', @HOUR, @MIN)
; Draw current time (xx:xx) on "Image1.png" and create bitmap
$hArea = _GDIPlus_BitmapCloneArea($hImage1, 0, 0, 133, 133, $GDIP_PXF32ARGB)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hArea)
$hFamily = _GDIPlus_FontFamilyCreate('Garamond')
$hFont = _GDIPlus_FontCreate($hFamily, 20, 0, 2)
$tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
$hFormat = _GDIPlus_StringFormatCreate()
$hBrush = _GDIPlus_BrushCreateSolid(0xC000FF00)
_GDIPlus_GraphicsSetTextRenderingHint($hGraphic, 3)
$aData = _GDIPlus_GraphicsMeasureString($hGraphic, $Text, $hFont, $tLayout, $hFormat)
$tLayout = $aData[0]
DllStructSetData($tLayout, 1, (133 - DllStructGetData($tLayout, 3)) / 2)
DllStructSetData($tLayout, 2, (133 - DllStructGetData($tLayout, 4)) / 2)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $Text, $hFont, $aData[0], $hFormat, $hBrush)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hArea)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_FontDispose($hFont)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_ImageDispose($hArea)
; Show pop-up image
_Popup_Show($hPopup1, $hBitmap, 1, @DesktopWidth - 90, @DesktopHeight - 110, -1)
EndFunc ;==>_Popup1
Не могли бы вы, пожалуйста, построчно прокомментировать и объяснить какие действия выполняются в функции _Popup1.
; ====================================================================================================================
; Инициализация OSD.
; ====================================================================================================================
Func _InitOSD()
; Запуск ядра для работы с графикой.
_GDIPlus_Startup()
; Создание PrivateFont Collection объекта.
Local $fCollection = _GDIPlus_FontPrivateCreateCollection()
; Добавить шрифт.
_GDIPlus_FontPrivateAddFont($fCollection, "Source\FontOSD.ttf")
; Создать FontFamily объект. Сдесь задается шрифт для OSD.
;$hFamily = _GDIPlus_FontFamilyCreate("Tahoma")
$hFamily = _GDIPlus_FontFamilyCreateFromCollection(_WinAPI_GetFontResourceInfo("Source\FontOSD.ttf", Default, 1), $fCollection)
; Загрузка подложек для OSD меню.
; Свои функции:
$hImageVol = _GDIPlus_ImageLoadFromFile("Source\pd_img.png")
; Общая функция _ViewIcon():
$ImageAKB = _GDIPlus_ImageLoadFromFile("Source\akb_img.png")
$ImageHMT = _GDIPlus_ImageLoadFromFile("Source\hmat_img.png")
$ImageHST = _GDIPlus_ImageLoadFromFile("Source\hseat_img.png")
; Регистрация PopUp.
; Свои функции:
$POPUP_Vol = _Popup_Register()
; Общая функция _ViewIcon():
$OSD_AKB = _Popup_Register()
$OSD_HMT = _Popup_Register()
$OSD_HST = _Popup_Register()
EndFunc
; ====================================================================================================================
; Функция вывода громкости.
; ====================================================================================================================
Func _OSD_Vol($Text)
Local $hBitmapResize, $hGraphic, $hFont, $hBrush, $hFormat, $tLayout, $aData, $hBitmap
Local $RamkaW = Int(@DesktopWidth / IniRead("CFGTitanCar.ini", "OSD", "IMG_W_REM", "1.7"), 0)
Local $RamkaH = Int(@DesktopHeight / IniRead("CFGTitanCar.ini", "OSD", "IMG_H_REM", "5"), 0)
Local $FontH = Int($RamkaW / IniRead("CFGTitanCar.ini", "OSD", "FONT_REM", "12"), 0)
$Text = "Volume " & $Text & "%"
; Рисуем текст из переменной $Text на изображении.
; Ремаштабируем рисунок подложки.
$hBitmapResize = _GDIPlus_ImageResize($hImageVol, $RamkaW, $RamkaH)
; Создать Graphic объект из изобраджения.
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmapResize)
; Создать Font объект. Сдесь задается размер и стиль шрифта.
$hFont = _GDIPlus_FontCreate($hFamily, $FontH, 3, 2)
; Создать Brush объект. Сдесь задаются параметры текста: Alpha, Red, Green, Blue.
$hBrush = _GDIPlus_BrushCreateSolid(0xFF00CCFF)
; Задать способ наложения текста.
_GDIPlus_GraphicsSetTextRenderingHint($hGraphic, 4)
; Создать String объект.
$hFormat = _GDIPlus_StringFormatCreate()
; Создать $tagGDIPRECTF структуру.
$tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
; Измерить размер строки (Array[0] - $tagGDIPRECTF структура).
$aData = _GDIPlus_GraphicsMeasureString($hGraphic, $Text, $hFont, $tLayout, $hFormat)
; Сохранить измеренную строку в $tagGDIPRECTF структуру.
$tLayout = $aData[0]
; Задать координаты рисования строки ($tagGDIPRECTF = X, Y, W, H).
DllStructSetData($tLayout, 1, ($RamkaW - DllStructGetData($tLayout, 3)) / 2)
DllStructSetData($tLayout, 2, ($RamkaH - DllStructGetData($tLayout, 4)) / 2)
; Нарисовать строку.
_GDIPlus_GraphicsDrawStringEx($hGraphic, $Text, $hFont, $aData[0], $hFormat, $hBrush)
; Создать Bitmap.
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmapResize)
; Показать созданное изображение с таймером, после удалить ресурс.
_Popup_Show($POPUP_Vol, $hBitmap, True, -1, -1, IniRead("CFGTitanCar.ini", "OSD", "WAIT", "1000"))
; Высвобождение ресурсов.
If Not _GDIPlus_BitmapDispose($hBitmapResize) Then MsgBox($MB_ICONERROR+$MB_OK, "Error", "Ошибка удаления ресурсов GDI+! _OSD_Vol #1")
If Not _GDIPlus_GraphicsDispose($hGraphic) Then MsgBox($MB_ICONERROR+$MB_OK, "Error", "Ошибка удаления ресурсов GDI+! _OSD_Vol #2")
If Not _GDIPlus_FontDispose($hFont) Then MsgBox($MB_ICONERROR+$MB_OK, "Error", "Ошибка удаления ресурсов GDI+! _OSD_Vol #3")
If Not _GDIPlus_BrushDispose($hBrush) Then MsgBox($MB_ICONERROR+$MB_OK, "Error", "Ошибка удаления ресурсов GDI+! _OSD_Vol #4")
If Not _GDIPlus_StringFormatDispose($hFormat) Then MsgBox($MB_ICONERROR+$MB_OK, "Error", "Ошибка удаления ресурсов GDI+! _OSD_Vol #5")
; Удалять ресурс не требутся, т.к. _Popup_Show -> $fDelete = True.
;If Not _WinAPI_DeleteObject($hBitmap) Then MsgBox($MB_ICONERROR+$MB_OK, "Error", "Ошибка удаления ресурсов GDI+! _OSD_Vol #6")
EndFunc
Если имеется ввиду клик мышью, то примерно так:Есть вопрос, каким образом можно отслеживать нажатия на эти созданные картинки?
#include <GUIConstantsEx.au3>
; ...
WinSetState($hPopup1, '', @SW_ENABLE) ; без этого не работает
WinSetState($hPopup2, '', @SW_ENABLE)
Local $nMsg
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_PRIMARYUP ; событие клика левой кнопкой мыши
If GetHoveredHwnd() = $hPopup1 Then ; проверяем находится ли мышь над первым объектом
ConsoleWrite('Клик левой по первому объекту' & @CRLF)
EndIf
If GetHoveredHwnd() = $hPopup2 Then ; проверяем находится ли мышь над вторым объектом
ConsoleWrite('Клик левой по второму объекту' & @CRLF)
EndIf
EndSwitch
Sleep(10)
WEnd
; ...
Func GetHoveredHwnd()
Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
If $iRet[0] Then Return HWnd($iRet[0])
Return SetError(1, 0, 0)
EndFunc
#include <GUIConstantsEx.au3>
#Include <GDIPlus.au3>
#Include <Pop-ups.au3>
Opt('MustDeclareVars', 1)
Opt('TrayAutoPause', 0)
_GDIPlus_Startup()
Global $hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Image1.png'), $hImage2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Image2.png')
Global $hPopup1 = _Popup_Register(), $hPopup2 = _Popup_Register()
HotKeySet('+1', '_Popup1') ; SHIFT+1
HotKeySet('+2', '_Popup2') ; SHIFT+2
WinSetState($hPopup1, '', @SW_ENABLE) ; без этого не работает
WinSetState($hPopup2, '', @SW_ENABLE)
Local $nMsg
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_PRIMARYUP ; событие клика левой кнопкой мыши
If GetHoveredHwnd() = $hPopup1 Then ; проверяем находится ли мышь над первым объектом
ConsoleWrite('Клик левой по первому объекту' & @CRLF)
EndIf
If GetHoveredHwnd() = $hPopup2 Then ; проверяем находится ли мышь над вторым объектом
ConsoleWrite('Клик левой по второму объекту' & @CRLF)
EndIf
EndSwitch
Sleep(10)
WEnd
_GDIPlus_Shutdown()
Func GetHoveredHwnd()
Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
If $iRet[0] Then Return HWnd($iRet[0])
Return SetError(1, 0, 0)
EndFunc
Func _Popup1()
Local $hGraphic, $hArea, $hBitmap, $hFamily, $hFont, $hFormat, $hBrush, $tLayout, $aData
Local $Text = StringFormat('%01d:%02d', @HOUR, @MIN)
; Draw current time (xx:xx) on "Image1.png" and create bitmap
$hArea = _GDIPlus_BitmapCloneArea($hImage1, 0, 0, 133, 133, $GDIP_PXF32ARGB)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hArea)
$hFamily = _GDIPlus_FontFamilyCreate('Tahoma')
$hFont = _GDIPlus_FontCreate($hFamily, 38, 0, 2)
$tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
$hFormat = _GDIPlus_StringFormatCreate()
$hBrush = _GDIPlus_BrushCreateSolid(0xC0FFFFFF)
_GDIPlus_GraphicsSetTextRenderingHint($hGraphic, 3)
$aData = _GDIPlus_GraphicsMeasureString($hGraphic, $Text, $hFont, $tLayout, $hFormat)
$tLayout = $aData[0]
DllStructSetData($tLayout, 1, (133 - DllStructGetData($tLayout, 3)) / 2)
DllStructSetData($tLayout, 2, (133 - DllStructGetData($tLayout, 4)) / 2)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $Text, $hFont, $aData[0], $hFormat, $hBrush)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hArea)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_FontDispose($hFont)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_ImageDispose($hArea)
; Show pop-up image
_Popup_Show($hPopup1, $hBitmap, 1)
EndFunc ;==>_Popup1
Func _Popup2()
; Show or hide pop-up image ("Image2.png")
If Not _Popup_IsActive($hPopup2) Then
_Popup_Show($hPopup2, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage2), 1, @DesktopWidth - 90, @DesktopHeight - 110, -1)
Else
_Popup_Hide($hPopup2)
EndIf
EndFunc ;==>_Popup2
;~ #Region GDI+ Functions
;~ Func _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, $iTextRenderingHint)
;~ Local $aResult = DllCall($ghGDIPDll, 'uint', 'GdipSetTextRenderingHint', 'ptr', $hGraphics, 'int', $iTextRenderingHint)
;~ If @error Then
;~ Return SetError(1, 0, 0)
;~ Else
;~ If $aResult[0] Then
;~ Return SetError($aResult[0], 0, 0)
;~ EndIf
;~ EndIf
;~ Return 1
;~ EndFunc ;==>_GDIPlus_GraphicsSetTextRenderingHint
;~ #EndRegion GDI+ Functions
Если имеется ввиду клик мышью, то примерно так:
#include <GUIConstantsEx.au3>
#Include <GDIPlus.au3>
#Include <Pop-ups.au3>
Opt('MustDeclareVars', 1)
Opt('TrayAutoPause', 0)
Opt("GUIOnEventMode", 1) ; Включить режим OnEventMode.
_GDIPlus_Startup()
Global $hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Image1.png'), $hImage2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Image2.png')
Global $hPopup1 = _Popup_Register(), $hPopup2 = _Popup_Register()
HotKeySet('+1', '_Popup1') ; SHIFT+1
HotKeySet('+2', '_Popup2') ; SHIFT+2
WinSetState($hPopup1, '', @SW_ENABLE) ; без этого не работает
WinSetState($hPopup2, '', @SW_ENABLE)
GUISwitch($hPopup1)
GUISetOnEvent($GUI_EVENT_PRIMARYUP, "_EventPopUp")
GUISwitch($hPopup2)
GUISetOnEvent($GUI_EVENT_PRIMARYUP, "_EventPopUp")
While 1
Sleep(10)
WEnd
Func _EventPopUp()
If GetHoveredHwnd() = $hPopup1 Then ; проверяем находится ли мышь над первым объектом
ConsoleWrite('Клик левой по 1 объекту' & @CRLF)
EndIf
If GetHoveredHwnd() = $hPopup2 Then ; проверяем находится ли мышь над вторым объектом
ConsoleWrite('Клик левой по 2 объекту' & @CRLF)
EndIf
EndFunc
_GDIPlus_Shutdown()
Func GetHoveredHwnd()
Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
If $iRet[0] Then Return HWnd($iRet[0])
Return SetError(1, 0, 0)
EndFunc
Func _Popup1()
Local $hGraphic, $hArea, $hBitmap, $hFamily, $hFont, $hFormat, $hBrush, $tLayout, $aData
Local $Text = StringFormat('%01d:%02d', @HOUR, @MIN)
; Draw current time (xx:xx) on "Image1.png" and create bitmap
$hArea = _GDIPlus_BitmapCloneArea($hImage1, 0, 0, 133, 133, $GDIP_PXF32ARGB)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hArea)
$hFamily = _GDIPlus_FontFamilyCreate('Tahoma')
$hFont = _GDIPlus_FontCreate($hFamily, 38, 0, 2)
$tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
$hFormat = _GDIPlus_StringFormatCreate()
$hBrush = _GDIPlus_BrushCreateSolid(0xC0FFFFFF)
_GDIPlus_GraphicsSetTextRenderingHint($hGraphic, 3)
$aData = _GDIPlus_GraphicsMeasureString($hGraphic, $Text, $hFont, $tLayout, $hFormat)
$tLayout = $aData[0]
DllStructSetData($tLayout, 1, (133 - DllStructGetData($tLayout, 3)) / 2)
DllStructSetData($tLayout, 2, (133 - DllStructGetData($tLayout, 4)) / 2)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $Text, $hFont, $aData[0], $hFormat, $hBrush)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hArea)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_FontDispose($hFont)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_ImageDispose($hArea)
; Show pop-up image
_Popup_Show($hPopup1, $hBitmap, 1)
EndFunc ;==>_Popup1
Func _Popup2()
; Show or hide pop-up image ("Image2.png")
If Not _Popup_IsActive($hPopup2) Then
_Popup_Show($hPopup2, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage2), 1, @DesktopWidth - 90, @DesktopHeight - 110, -1)
Else
_Popup_Hide($hPopup2)
EndIf
EndFunc ;==>_Popup2
;~ #Region GDI+ Functions
;~ Func _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, $iTextRenderingHint)
;~ Local $aResult = DllCall($ghGDIPDll, 'uint', 'GdipSetTextRenderingHint', 'ptr', $hGraphics, 'int', $iTextRenderingHint)
;~ If @error Then
;~ Return SetError(1, 0, 0)
;~ Else
;~ If $aResult[0] Then
;~ Return SetError($aResult[0], 0, 0)
;~ EndIf
;~ EndIf
;~ Return 1
;~ EndFunc ;==>_GDIPlus_GraphicsSetTextRenderingHint
;~ #EndRegion GDI+ Functions
#include <GUIConstantsEx.au3>
#Include <GDIPlus.au3>
#Include <Pop-ups.au3>
Opt('MustDeclareVars', 1)
Opt('TrayAutoPause', 0)
Opt("GUIOnEventMode", 1) ; Включить режим OnEventMode.
_GDIPlus_Startup()
Global $hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Image1.png'), $hImage2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Image2.png')
Global $hPopup1 = _Popup_Register(), $hPopup2 = _Popup_Register()
HotKeySet('+1', '_Popup1') ; SHIFT+1
HotKeySet('+2', '_Popup2') ; SHIFT+2
WinSetState($hPopup1, '', @SW_ENABLE) ; без этого не работает
WinSetState($hPopup2, '', @SW_ENABLE)
GUISwitch($hPopup1)
GUISetOnEvent($GUI_EVENT_PRIMARYUP, "_ClickPopUp1")
GUISwitch($hPopup2)
GUISetOnEvent($GUI_EVENT_PRIMARYUP, "_ClickPopUp2")
While 1
Sleep(10)
WEnd
_GDIPlus_Shutdown()
Func _ClickPopUp1()
ConsoleWrite('Клик левой по 1 объекту' & @CRLF)
EndFunc
Func _ClickPopUp2()
ConsoleWrite('Клик левой по 2 объекту' & @CRLF)
EndFunc
Func _Popup1()
Local $hGraphic, $hArea, $hBitmap, $hFamily, $hFont, $hFormat, $hBrush, $tLayout, $aData
Local $Text = StringFormat('%01d:%02d', @HOUR, @MIN)
; Draw current time (xx:xx) on "Image1.png" and create bitmap
$hArea = _GDIPlus_BitmapCloneArea($hImage1, 0, 0, 133, 133, $GDIP_PXF32ARGB)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hArea)
$hFamily = _GDIPlus_FontFamilyCreate('Tahoma')
$hFont = _GDIPlus_FontCreate($hFamily, 38, 0, 2)
$tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
$hFormat = _GDIPlus_StringFormatCreate()
$hBrush = _GDIPlus_BrushCreateSolid(0xC0FFFFFF)
_GDIPlus_GraphicsSetTextRenderingHint($hGraphic, 3)
$aData = _GDIPlus_GraphicsMeasureString($hGraphic, $Text, $hFont, $tLayout, $hFormat)
$tLayout = $aData[0]
DllStructSetData($tLayout, 1, (133 - DllStructGetData($tLayout, 3)) / 2)
DllStructSetData($tLayout, 2, (133 - DllStructGetData($tLayout, 4)) / 2)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $Text, $hFont, $aData[0], $hFormat, $hBrush)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hArea)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_FontDispose($hFont)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_ImageDispose($hArea)
; Show pop-up image
_Popup_Show($hPopup1, $hBitmap, 1)
EndFunc ;==>_Popup1
Func _Popup2()
; Show or hide pop-up image ("Image2.png")
If Not _Popup_IsActive($hPopup2) Then
_Popup_Show($hPopup2, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage2), 1, @DesktopWidth - 90, @DesktopHeight - 110, -1)
Else
_Popup_Hide($hPopup2)
EndIf
EndFunc ;==>_Popup2
;~ #Region GDI+ Functions
;~ Func _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, $iTextRenderingHint)
;~ Local $aResult = DllCall($ghGDIPDll, 'uint', 'GdipSetTextRenderingHint', 'ptr', $hGraphics, 'int', $iTextRenderingHint)
;~ If @error Then
;~ Return SetError(1, 0, 0)
;~ Else
;~ If $aResult[0] Then
;~ Return SetError($aResult[0], 0, 0)
;~ EndIf
;~ EndIf
;~ Return 1
;~ EndFunc ;==>_GDIPlus_GraphicsSetTextRenderingHint
;~ #EndRegion GDI+ Functions