I suppose you were too lazy to read the whole thread?
http://www.autohotkey.com/forum/viewtop ... ht=#287985
I've improved it slightly from then. See
here for the full EXE. And here for the (cutdown) code:
Code:
; See Here http://www.autohotkey.com/forum/viewtopic.php?p=287985#287985
; Don't forget to change the GDIP.AHK --> Gdip_TextToGraphics
;
; If vPos
; {
; StringSplit, ReturnRC, ReturnRC, |
;
; If (vPos = "vCentre") || (vPos = "vCenter")
; ypos := ypos + (Height-ReturnRC4)//2
;
; COMMENT THIS OUT Else If (vPos = "Top") || (vPos = "Up")
; COMMENT THIS OUT ypos := 0
; Else If (vPos = "Bottom") || (vPos = "Down")
; ypos := ypos + Height-ReturnRC4
;
; CreateRectF(RC, xpos, ypos, Width, ReturnRC4)
; }
;
;
#SingleInstance,Ignore
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
Save_BatchLines = %A_BatchLines%
DetectHiddenWindows On
; Start gdi+
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
GoSub,GUIClose
}
;---------------------------------------
ApplicationName=Clown_SRT2XMLSUB
ApplicationVersion=v0.06
ApplicationTitle=%ApplicationName% %ApplicationVersion%
DetectHiddenWindows, On
GoSub,Define_Gui
GoSub,Main_Brain
Return
;---------------------------------------
GUIClose:
; gdi+ may now be shutdown on exiting the program
Gdip_Shutdown(pToken)
ExitApp
Return
;---------------------------------------
GoClownBD:
Run,http://www.clownbd.com/,,UseErrorLevel
Return
;---------------------------------------
Main_Brain:
Current_GUI = 2
Gui,%Current_GUI%:Default
Cur_Win_title = %ApplicationTitle%
Gui,Show,,%Cur_Win_title%
Return
;---------------------------------------
Gui_Submit_Nohide:
Gui,Submit,nohide
if Border = 0
GuiControl,Hide,BColour
else
GuiControl,Show,BColour
Return
;---------------------------------------
Preview_PNG:
Gui,Submit,nohide
Text := ApplicationTitle . "`n" . Font . " " . Size . " " . Style . " Preview"
;-- Build temporary window to determine maximum width
Gui 3:-Caption
gui 3:Margin,0,0
gui 3:Font,s%Size%,%Font%
gui 3:Add,Text,,%Text%
gui 3:Show,Hide ;-- Render but don't show
;-- How wide is it?
gui 3:+LastFound
WinGetPos ,,,Width,Height,% "ahk_id " . WinExist()
gui 3:Destroy
; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
Gui, 4: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
; Show the window
Gui, 4: Show, NA
; Get a handle to this window we have created in order to update it later
hwnd1 := WinExist()
; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
hbm := CreateDIBSection(A_ScreenWidth, A_ScreenHeight)
; Get a device context compatible with the screen
hdc := CreateCompatibleDC()
; Select the bitmap into the device context
obm := SelectObject(hdc, hbm)
; Get a pointer to the graphics of the bitmap, for use with drawing functions
G := Gdip_GraphicsFromHDC(hdc)
; Set the smoothing mode to antialias = 4 to make shapes appear smother (only used for vector drawing and filling)
Gdip_SetSmoothingMode(G, 4)
WriteText(G, Text, Size, Align, vPos, Font, Colour, "ff", Style, Border, BColour, Width, Height)
if SAlign = Left
{
TextToImage_X := 0 + Htolerance
}
if SAlign = Centre
{
TextToImage_X := ((A_ScreenWidth - Width) // 2) + Htolerance
}
if SAlign = Right
{
TextToImage_X := A_ScreenWidth - Width + Htolerance
}
if SvPos = Top
{
TextToImage_Y := 0 + Vtolerance
}
if SvPos = vCentre
{
TextToImage_Y := ((A_ScreenHeight - Height) // 2) + Vtolerance
}
if SvPos = Bottom
{
TextToImage_Y := A_ScreenHeight - Height + Vtolerance
}
; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen
; So this will position our gui at (0,0) with the Width and Height specified earlier
UpdateLayeredWindow(hwnd1, hdc, TextToImage_X, TextToImage_Y, Width, Height)
; Select the object back into the hdc
SelectObject(hdc, obm)
; Now the bitmap may be deleted
DeleteObject(hbm)
; Also the device context related to the bitmap may be deleted
DeleteDC(hdc)
Settimer,Kill_Preview,15000
Return
;---------------------------------------
Kill_Preview:
Settimer,Kill_Preview,Off
Gui, 4:Destroy
Return
;---------------------------------------
Define_Gui:
Gui,Destroy
Gui,1:Add,Text
Gui,1:+LastFound
WinSet,Transparent,0
WinSet,ExStyle,^0x20
Gui,1:-Caption
Gui,1:Show, w%A_ScreenWidth% h%A_ScreenHeight%,%ApplicationTitle%
Gui,2:Default
Gui,+owner1
Gui,+owner
Gui -SysMenu
Gui,Add,Text,y+15
Gui,Add,GroupBox,Section w450 h55 xm yp,Font Name - Font Size - Font Style - Font Colour
Gui,Add,DropDownList, xs+10 w100 ys+20 vFont gGui_Submit_Nohide,Arial||Courier New|Impact|Lucida Console|Tahoma|Times New Roman|
Gui,Add,DropDownList, xp+110 w100 yp vSize gGui_Submit_Nohide,24|30|36|40|48|60||72|
Gui,Add,DropDownList, xp+110 w100 yp vStyle gGui_Submit_Nohide,Regular||Bold|Italic|BoldItalic|Underline|Strikeout
Colour = ffffff
Gui, Add, ListView, xp+110 w100 r1 yp ReadOnly 0x4000 +Background%Colour% vColour gChoose_Color
Gui,Add,Text,y+20
Gui,Add,GroupBox,Section w450 h55 xm yp,Border Thickness - Border Colour - Text Horizontal Alignment - Text Vertical Alignment
Gui,Add,DropDownList, xs+10 w100 ys+20 vBorder gGui_Submit_Nohide,0|1|2||3|
BColour = 000000
Gui, Add, ListView, xp+110 w100 r1 yp ReadOnly 0x4000 +Background%BColour% vBColour gChoose_Color
Gui,Add,DropDownList, xp+110 w100 yp vAlign gGui_Submit_Nohide,Left|Centre||Right|
Gui,Add,DropDownList, xp+110 w100 yp vvPos gGui_Submit_Nohide,Top||Bottom|vCentre
Gui,Add,Text,y+20
Gui,Add,GroupBox,Section w450 h55 xm yp,Horizontal Alignment - Horizonal Tolerance - Vertical Alignment - Vertical Tolerance
Gui,Add,DropDownList, xs+10 w100 ys+20 vSAlign gGui_Submit_Nohide,Left|Centre||Right|
Gui,Add,Slider,xp+110 w100 yp Tooltip vHTolerance Range-100-100, 0
Gui,Add,DropDownList, xp+110 w100 yp vSvPos gGui_Submit_Nohide,Top|Bottom||vCentre
Gui,Add,Slider,xp+110 w100 yp Tooltip vVTolerance Range-100-100, -30
Gui,Add,Text,y+20
Gui,Add,Button,xm yp w75 r1 vGuiClose gGuiClose,Exit
Gui,Add,Button,xm+85 yp w75 r1 vGoClownBD gGoClownBD,About
Gui,Add,Button,xm+290 yp w75 r1 vButton_Preview gPreview_PNG,Preview
Gui,Add,StatusBar, vStatusBar
OnMessage(0x200, "WM_MOUSEMOVE")
OnMessage(0x201, "WM_LBUTTONDOWN")
SizeOfStructForChooseColor = 0x24
VarSetCapacity(StructForChooseColor, SizeOfStructForChooseColor, 0)
VarSetCapacity(StructArrayForChooseColor, 64, 0)
Gui, +LastFound
GuiHWND := WinExist() ; Relies on the line above to get the unique ID of GUI window.
InsertInteger(SizeOfStructForChooseColor, StructForChooseColor, 0) ; DWORD lStructSize
InsertInteger(GuiHWND, StructForChooseColor, 4) ; HWND hwndOwner (makes dialog "modal").
InsertInteger(0x0 , StructForChooseColor, 8) ; HINSTANCE hInstance
InsertInteger(0x0 , StructForChooseColor, 12) ; clr.rgbResult = 0;
InsertInteger(&StructArrayForChooseColor , StructForChooseColor, 16) ; COLORREF *lpCustColors
InsertInteger(0x00000100 , StructForChooseColor, 20) ; Flag: Anycolor
InsertInteger(0x0 , StructForChooseColor, 24) ; LPARAM lCustData
InsertInteger(0x0 , StructForChooseColor, 28) ; LPCCHOOKPROC lpfnHook
InsertInteger(0x0 , StructForChooseColor, 32) ; LPCTSTR lpTemplateName
Font_TT = The name of the true type font.
Size_TT = The size of the true type font.
Style_TT = The style of the true type font.
Colour_TT = The colour of the true type font.`nYou can click the box and get a colour picker.
Border_TT = The thickness of the border (if any).
BColour_TT = The colour of the border.`nYou can click the box and get a colour picker.
Align_TT = The horizontal alignment of the text within it's own area. Not to be confused with the final screen position.
vPos_TT = The vertical alignment of the text within it's own area. Not to be confused with the final screen position.
SAlign_TT = The horizontal alignment of the subtitles on screen. Not to be confused with the text alignment.
HTolerance_TT = The number of pixels left or right from left/center/right of screen
SvPos_TT = The vertical alignment of the subtitles on screen. Not to be confused with the final text alignment.
VTolerance_TT = The number of pixels up or down from top/center/bottom of screen
GuiClose_TT = Bye Bye !
GoClownBD_TT = Visit my webpage.
Button_Preview_TT = Show a preview of your selected text on-screen.`nPreview will autoclose in 10 seconds.
StatusBar_TT = There is nothing to see here, please move along.
Return
Choose_Color:
nRC := DllCall("comdlg32\ChooseColorA", str, StructForChooseColor) ; Display the dialog.
if (errorlevel <> 0) || (nRC = 0)
{
;~ MsgBox error while calling ChooseColor Errorlevel: %errorlevel% - RC: %nRC%
return
}
; Otherwise, the user pressed OK in the dialog, so determine what was selected.
;GuiControl,, Color, % BGRtoRGB(ExtractInteger(StructForChooseColor, 12))
SetFormat, integer, hex ; Show RGB color extracted below in hex format.
New_Colour = % BGRtoRGB(ExtractInteger(StructForChooseColor, 12))
GuiControl,+Background%New_Colour% , % A_GuiControl
%A_GuiControl% = %New_Colour%
SetFormat, integer, d
Return
ExtractInteger(ByRef pSource, pOffset = 0, pIsSigned = false, pSize = 4)
; See DllCall documentation for details.
{
SourceAddress := &pSource + pOffset ; Get address and apply the caller's offset.
result := 0 ; Init prior to accumulation in the loop.
Loop %pSize% ; For each byte in the integer:
{
result := result | (*SourceAddress << 8 * (A_Index - 1)) ; Build the integer from its bytes.
SourceAddress += 1 ; Move on to the next byte.
}
if (!pIsSigned OR pSize > 4 OR result < 0x80000000)
return result ; Signed vs. unsigned doesn't matter in these cases.
; Otherwise, convert the value (now known to be 32-bit) to its signed counterpart:
return -(0xFFFFFFFF - result + 1)
}
InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
; To preserve any existing contents in pDest, only pSize number of bytes starting at
; pOffset are altered in it. The caller must ensure that pDest has sufficient capacity.
{
mask := 0xFF ; This serves to isolate each byte, one by one.
Loop %pSize% ; Copy each byte in the integer into the structure as raw binary data.
{
DllCall("RtlFillMemory", UInt, &pDest + pOffset + A_Index - 1, UInt, 1 ; Write one byte.
, UChar, (pInteger & mask) >> 8 * (A_Index - 1)) ; This line is auto-merged with above at load-time.
mask := mask << 8 ; Set it up for isolation of the next byte.
}
}
WriteText(G="", Text="TextToImage", Size="20", Align="Bottom|Centre", vPos="Top", Font="Arial", Colour="ffffff", Transparancy="ff", Style="", Border="0", BColour="000000", Width="", Height="")
{
if Border > 0
{
Options = %Align% %vPos% w%Width% h%Height% r4 c%Transparancy%%BColour% s%Size% %Style%
Border_IDX1 := 0 - Border
Loop,2
{
If Border_IDX1 > %Border%
Break
Border_IDX2 := 0 - Border
Loop
{
If Border_IDX2 > %Border%
Break
BOptions = x%Border_IDX1% y%Border_IDX2% %Options%
Gdip_TextToGraphics(G,TEXT,BOptions,Font)
BOptions = x%Border_IDX2% y%Border_IDX1% %Options%
Gdip_TextToGraphics(G,TEXT,BOptions,Font)
Border_IDX2++
}
Border_IDX1 := 0 + Border
}
}
Options = %Align% %vPos% w%Width% h%Height% c%Transparancy%%Colour% r4 s%Size% %Style%
Gdip_TextToGraphics(G,TEXT,Options,Font)
return
}
BGRtoRGB(oldValue)
{
Value := (oldValue & 0x00ff00)
Value += ((oldValue & 0xff0000) >> 16)
Value += ((oldValue & 0x0000ff) << 16)
return Substr("000000" . substr(Value,3),-5)
}
WM_MOUSEMOVE()
{
static CurrControl, PrevControl, _TT ; _TT is kept blank for use by the ToolTip command below.
CurrControl := A_GuiControl
If (CurrControl <> PrevControl and not InStr(CurrControl, " "))
{
ToolTip ; Turn off any previous tooltip.
SetTimer, DisplayToolTip, 2000
PrevControl := CurrControl
}
return
DisplayToolTip:
SetTimer, DisplayToolTip, Off
Tooltip_Text = % %CurrControl%_TT
Tooltip_Text := RegExReplace(Tooltip_Text,"\[CR\]","`n")
ToolTip %Tooltip_Text%
SetTimer, RemoveToolTip, 5000
return
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return
}
WM_LBUTTONDOWN()
{
if (A_GuiControl = "Colour") or (A_GuiControl = "BColour")
Gosub,Choose_Color
return
}