#SingleInstance, Force
#NoEnv
#NoTrayIcon
SetBatchLines, -1
SetWinDelay, 0
;#Include, Gdip.ahk
If !pToken := Gdip_Startup()
{
MsgBox, 48, Ошибка GDI+, Убедитесь в наличии gdiplus.dll в вашей системе!
ExitApp
}
Width := 400
Height := 200 ; размеры картинки
DllCall("Winmm\timeBeginPeriod", UInt, 3)
SleepDuration := 4
Gui, Add, Pic, x10 y10 w%Width% h%Height% hwndhPic gRepaint
Gui, Add, Pic, x10 y10 w%Width% h%Height% hwndhPic2 BackgroundTrans
GUI,show,,DualLayer
gosub StartDraw
WinGet,MyWindow,ID,DualLayer
ControlGetPos,Xpic, Ypic,,,Static1,ahk_id %MyWindow%
OnMessage(0xF, "WM_PAINT") ; поддержка изображения при перерисовке окна
Settimer, SetTime, 1000
return
StartDraw:
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 2) ;задаем режим сглаживания
pBlackPen := Gdip_CreatePen(0xff000000, 1)
pBluePen := Gdip_CreatePen(0xff0000ff, 1) ; карандаш для графика
pWhiteBrush := Gdip_BrushCreateSolid(0xffffffff) ; кисть для заливки
Gdip_FillRoundedRectangle(G, pWhiteBrush, 0, 0, Width, Height, 2) ;рисуем белый фон
hPicDC := GetDC(hPic) ; получаем контекст контрола, чтобы переносить в него изображение
BitBlt(hPicDC, 0, 0, Width, Height, hdc, 0, 0) ; переносим рисунок в контекст контрола
hbm2 := CreateDIBSection(Width, Height)
hdc2 := CreateCompatibleDC()
obm2 := SelectObject(hdc2, hbm2)
G2 := Gdip_GraphicsFromHDC(hdc2)
Gdip_SetSmoothingMode(G2, 4)
Gdip_FillRectangle(G2, pWhiteBrush, -1, -1, Width, Height)
hPicDC2 := GetDC(hPic2)
BitBlt(hPicDC2, 0, 0, Width, Height, hdc2, 0, 0, 0x008800C6 ) ; SRCAND = 0x008800C6
return
GuiClose:
ReleaseDC(hPicDC2, hPic2), SelectObject(hdc2, obm2), DeleteObject(hbm2)
DeleteDC(hdc2), Gdip_DeleteGraphics(G2)
Gdip_DeleteBrush(pWhiteBrush)
Gdip_DeletePen(pBlackPen)
Gdip_DeletePen(pBluePen)
ReleaseDC(hPicDC, hPic)
SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
DllCall("Winmm\timeEndPeriod", UInt, 3)
ExitApp
SetTime:
FormatTime, TimeString,, HH:mm:ss
Gdip_FillRectangle(G2, pWhiteBrush, 2, 2, 350, 100)
DrawText(G2, TimeString, "Arial", 0xff000000, 50, 2, 2, 350, 100)
BitBlt(hPicDC, 0, 0, Width, Height, hdc, 0, 0)
BitBlt(hPicDC2, 0, 0, Width, Height, hdc2, 0, 0, 0x008800C6 ) ; SRCAND = 0x008800C6
return
Repaint:
if A_GuiControlEvent = Normal
{
CoordMode,Mouse,Window
MouseGetPos,mX, mY
Ydm := mY - Ypic
Xdm := mX - Xpic
Settimer, Drawing, 100
KeyWait,LButton
MouseGetPos,mX, mY
Yum := mY - Ypic
Xum := mX - Xpic
Settimer, Drawing, off
}
Return
Drawing:
CoordMode,Mouse,Window
MouseGetPos,msX, msY
Ydraw := msY - Ypic
Xdraw := msX - Xpic
MyLine := Gdip_DrawLine(G, pBluePen, Xdm, Ydm, Xdraw, Ydraw) ;рисуем
Xdm := Xdraw
Ydm := Ydraw
BitBlt(hPicDC2, 0, 0, Width, Height, hdc2, 0, 0, 0x008800C6 ) ; SRCAND = 0x008800C6
return
WM_PAINT() ; поддержка изображения при перерисовке окна
{
global
SetTimer, Timer, -10
Return
Timer:
BitBlt(hPicDC, 0, 0, Width, Height, hdc, 0, 0)
BitBlt(hPicDC2, 0, 0, Width, Height, hdc2, 0, 0, 0x008800C6 ) ; SRCAND = 0x008800C6
Return
}
DrawText(workG, MyText, Font, TextColor=0xff000000, SizeFont=10, Xt=0, Yt=0, Wt=100, Ht=50, Underline=0, Italic=0, Strike=0, Bold=0, Outlined=0)
{
global
if !Font
Font = Arial
If !hFamily := Gdip_FontFamilyCreate(Font)
{
MsgBox, 48, Font error!, The font you have specified does not exist on the system
ExitApp
}
Gdip_DeleteFontFamily(hFamily)
Options := "x" . Xt . " y" . Yt . " w" . Wt . " h" . Ht . " cFF00ff00 r4 center s" . SizeFont . ""
if Underline = 1
Options := Options . " Underline"
if Italic = 1
Options := Options . " Italic"
if Strike = 1
Options := Options . " Strikeout"
if Bold = 1
Options := Options . " Bold"
if !pPath := Gdip_CreatePath(0)
Return errorlevel
Gdip_AddString(pPath, MyText, Font, Options)
if !pTextBrush := Gdip_BrushCreateSolid(TextColor)
Return errorlevel
Gdip_FillPath(workG, pTextBrush, pPath)
Gdip_DeleteBrush(pTextBrush)
Gdip_DeletePath(pPath)
}
Gdip_AddString(Path, sString,fontName, options,stringFormat=0x4000)
{
nSize := DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &sString, "Int", -1, "UInt", 0, "Int", 0)
VarSetCapacity(wString, nSize*2)
DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &sString, "Int", -1, "UInt", &wString, "Int", nSize)
hFamily := Gdip_FontFamilyCreate(fontName)
RegExMatch(Options, "i)X([\-0-9]+)", xpos)
RegExMatch(Options, "i)Y([\-0-9]+)", ypos)
RegExMatch(Options, "i)W([0-9]+)", Width)
RegExMatch(Options, "i)H([0-9]+)", Height)
RegExMatch(Options, "i)R([0-9])", Rendering)
Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
Loop, Parse, Styles, |
{
If RegExMatch(Options, "i)\b" A_loopField)
Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8
}
RegExMatch(Options, "i)S([0-9]+)", fontSize)
Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right"
Loop, Parse, Alignments, |
{
If RegExMatch(Options, "i)\b" A_loopField)
Align |= A_Index//2.1 ; 0|0|1|1|2|2
}
hFormat := Gdip_StringFormatCreate(stringFormat)
Gdip_SetStringFormatAlign(hFormat, Align)
Gdip_SetTextRenderingHint(pGraphics, Rendering)
CreateRectF(textbox, xpos1, ypos1, Width1, Height1)
iRet := DllCall("gdiplus\GdipAddPathString", "UInt", Path, "UInt", &wString, "Int", -1, "Uint",hFamily, "Int", Style, "Float", fontSize1,"UInt", &textbox, "UInt", hFormat)
Gdip_DeleteFontFamily(hFamily)
Gdip_DeleteStringFormat(hFormat)
return iRet
}
Gdip_DrawPath(pGraphics, pPen, Path)
{
return DllCall("gdiplus\GdipDrawPath", "UInt", pGraphics, "UInt", pPen, "UInt", Path)
}
Каждую секунду на верхнем слое перерисовывается отображаемое время, т.е. сначала белым прямоугольником стирается старое, потом пишется новое.
При этом с помощью мыши можно рисовать ломаные линии на нижнем слое. Если их нарисовать "под" текстом, то они все равно будут видны, несмотря на ежесекундно рисуемый поверх них белый прямоугольник.
Дык, никто не спорит, что там все надо перерисовывать, вопрос в том, как удобнее для кодера организовать хранение этих данных и управление объектами. Мне кажется, что если АНК теперь позволяет работать с объектами, то можно все реализовать через объектную модель. Или написанную собственноручно, или взятую оттуда, где она уже реализована. Как эти данные были организованы у вас?