Text to Screen
Text to Screen
AHK 1.1.34
I wish to Display several lines of Text on the Screen (NOT using Msgbox, as I wish the lines to go to the large area of screen, NOT a pop-up box)
Is there a way to do this in basic terms.... i.e. as I say, merely Text... no need for a more colourful GUI approach
Many thanks.
Geoff H.
I wish to Display several lines of Text on the Screen (NOT using Msgbox, as I wish the lines to go to the large area of screen, NOT a pop-up box)
Is there a way to do this in basic terms.... i.e. as I say, merely Text... no need for a more colourful GUI approach
Many thanks.
Geoff H.
Re: Text to Screen
Text on screen using GDI+ and a layered window.
Code: Select all
;****************************************************************************************************************************************************************************
#Include <My Altered GDIP lib> ;<<<<<<<<<<<<<<<<<<--------------------------- replace with your copy of gdip.ahk
;#Include <PopUpWindow_V2> ; At the bottom of the script
;****************************************************************************************************************************************************************************
#SingleInstance, Force
SetBatchLines, -1
Gdip_Startup()
MyText := "Blah Blah Blah"
;~ MyText := "I wish to Display several lines of Text on the Screen (NOT using Msgbox, as I wish the lines to go to the large area of screen, NOT a pop-up box) `nIs there a way to do this in basic terms.... i.e. as I say, merely Text... no need for a more colourful GUI approach"
Gui1 := New PopUpWindow( { AutoShow: 1 , X: 0 , Y: 0 , W: A_ScreenWidth , H: A_ScreenHeight , Options: " -DPIScale +AlwaysOnTop " } )
DrawText( Gui1.G , 0 , 0 , MyText , "0xFFFF00ff" , Gui1.W , Gui1.H , options := " Center vCenter Bold s152 " , type := "comic Sans MS" )
Gui1.UpdateWindow()
return
GuiClose:
GuiContextMenu:
*ESC::ExitApp
RALT::PopUpWindow.Helper()
DrawText( G , x , y , text , color , width , height , options := " Center vCenter Bold s12 " , type := "comic Sans MS" ){
Brush := Gdip_BrushCreateSolid( color ) , Gdip_TextToGraphics( G , text , options " c" brush " x" x " y" y , type , width , height ) , Gdip_DeleteBrush( Brush )
}
;Layered Window Class ( Canvas )
;####################################################################################################################################################################################
;####################################################################################################################################################################################
;####################################################################################################################################################################################
;####################################################################################################################################################################################
class PopUpWindow {
;PopUpWindow v2.2
;Date Written: Oct 28th, 2021
;Last Edit: Feb 7th, 2022 :Changed the trigger method.
;Written By: Hellbent aka CivReborn
;SpcThanks: teadrinker , malcev
static Index := 0 , Windows := [] , Handles := [] , EditHwnd , HelperHwnd
__New( obj := "" ){
This._SetDefaults()
This.UpdateSettings( obj )
This._CreateWindow()
This._CreateWindowGraphics()
if( This.AutoShow )
This.ShowWindow( This.Title )
}
_SetDefaults(){
This.X := 10
This.Y := 10
This.W := 10
This.H := 10
This.Smoothing := 2
This.Options := " -DPIScale +AlwaysOnTop "
This.AutoShow := 0
This.GdipStartUp := 0
This.Title := ""
This.Controls := []
This.Handles := []
This.Index := 0
}
AddTrigger( obj ){
local k , v , cc , bd
This.Controls[ ++This.Index ] := { X: 10
, Y: 10
, W: 10
, H: 10 }
for k, v in obj
This.Controls[ This.Index ][ k ] := obj[ k ]
cc := This.Controls[ This.Index ]
Gui, % This.Hwnd ":Add", Text, % "x" cc.X " y" cc.Y " w" cc.W " h" cc.H " hwndhwnd"
This.Handles[ hwnd ] := This.Index
This.Controls[ This.Index ].Hwnd := hwnd
if( IsObject( cc.Label ) ){
bd := cc.Label
GuiControl, % This.Hwnd ":+G" , % hwnd , % bd
}else{
bd := This._TriggerCall.Bind( This )
GuiControl, % This.Hwnd ":+G" , % hwnd , % bd
}
return hwnd
}
_TriggerCall(){
MouseGetPos,,,, ctrl, 2
Try
;~ SetTimer, % This.Controls[ This.Handles[ ctrl ] ].Label, -0
gosub, % This.Controls[ This.Handles[ ctrl ] ].Label
}
DrawTriggers( color := "0xFFFF0000" , AutoUpdate := 0 ){
local brush , cc
Brush := Gdip_BrushCreateSolid( color )
Gdip_SetSmoothingMode( This.G , 3 )
loop, % This.Controls.Length() {
cc := This.Controls[ A_Index ]
Gdip_FillRectangle( This.G , Brush , cc.x , cc.y , cc.w , cc.h )
}
Gdip_DeleteBrush( Brush )
Gdip_SetSmoothingMode( This.G , This.Smoothing )
if( AutoUpdate )
This.UpdateWindow()
}
UpdateSettings( obj := "" , UpdateGraphics := 0 ){
local k , v
if( IsObject( obj ) )
for k, v in obj
This[ k ] := obj[ k ]
( This.X = "Center" ) ? ( This.X := ( A_ScreenWidth - This.W ) / 2 )
( This.Y = "Center" ) ? ( This.Y := ( A_ScreenHeight - This.H ) / 2 )
if( UpdateGraphics ){
This._DestroyWindowsGraphics()
This._CreateWindowGraphics()
}
}
_CreateWindow(){
local hwnd
Gui , New, % " +LastFound +E0x80000 hwndhwnd -Caption " This.Options
PopUpWindow.Index++
This.Index := PopUpWindow.Index
PopUpWindow.Windows[ PopUpWindow.Index ] := This
This.Hwnd := hwnd
PopUpWindow.Handles[ hwnd ] := PopUpWindow.Index
if( This.GdipStartUp && !PopUpWindow.pToken )
PopUpWindow.pToken := GDIP_STARTUP()
}
_DestroyWindowsGraphics(){
Gdip_DeleteGraphics( This.G )
SelectObject( This.hdc , This.obm )
DeleteObject( This.hbm )
DeleteDC( This.hdc )
}
_CreateWindowGraphics(){
This.hbm := CreateDIBSection( This.W , This.H )
This.hdc := CreateCompatibleDC()
This.obm := SelectObject( This.hdc , This.hbm )
This.G := Gdip_GraphicsFromHDC( This.hdc )
Gdip_SetSmoothingMode( This.G , This.Smoothing )
}
ShowWindow( Title := "" ){
Gui , % This.Hwnd ":Show", % "x" This.X " y" This.Y " w" This.W " h" This.H " NA", % Title
}
HideWindow(){
Gui , % This.Hwnd ":Hide",
}
UpdateWindow( alpha := 255 ){
UpdateLayeredWindow( This.hwnd , This.hdc , This.X , This.Y , This.W , This.H , alpha )
}
ClearWindow( AutoUpdate := 0 ){
Gdip_GraphicsClear( This.G )
if( Autoupdate )
This.UpdateWindow()
}
DrawBitmap( pBitmap , obj , dispose := 1 , AutoUpdate := 0 ){
Gdip_DrawImage( This.G , pBitmap , obj.X , obj.Y , obj.W , obj.H )
if( dispose )
Gdip_DisposeImage( pBitmap )
if( Autoupdate )
This.UpdateWindow()
}
PaintBackground( color := "0xFF000000" , AutoUpdate := 0 ){
if( isObject( color ) ){
Brush := Gdip_BrushCreateSolid( ( color.HasKey( "Color" ) ) ? ( color.Color ) : ( "0xFF000000" ) )
if( color.Haskey( "Round" ) )
Gdip_FillRoundedRectangle( This.G , Brush , color.X , color.Y , color.W , color.H , color.Round )
else
Gdip_FillRectangle( This.G , Brush , color.X , color.Y , color.W , color.H )
}else{
Brush := Gdip_BrushCreateSolid( color )
Gdip_FillRectangle( This.G , Brush , -1 , -1 , This.W + 2 , This.H + 2 )
}
Gdip_DeleteBrush( Brush )
if( AutoUpdate )
This.UpdateWindow()
}
DeleteWindow( GDIPShutdown := 0 ){
Gui, % This.Hwnd ":Destroy"
SelectObject( This.hdc , This.obm )
DeleteObject( This.hbm )
DeleteDC( This.hdc )
Gdip_DeleteGraphics( This.G )
hwnd := This.Hwnd
for k, v in PopUpWindow.Windows[ Hwnd ]
This[k] := ""
PopUpWindow.Windows[ Hwnd ] := ""
if( GDIPShutdown ){
Gdip_Shutdown( PopUpWindow.pToken )
PopUpWindow.pToken := ""
}
}
_OnClose( wParam ){
if( wParam = 0xF060 ){ ;SC_CLOSE ;[ clicking on the gui close button ]
Try{
Gui, % PopUpWindow.HelperHwnd ":Destroy"
SoundBeep, 555
}
}
}
CreateCachedBitmap( pBitmap , Dispose := 0 ){
local pCachedBitmap
if( This.CachedBitmap )
This.DisposeCachedbitmap()
DllCall( "gdiplus\GdipCreateCachedBitmap" , "Ptr" , pBitmap , "Ptr" , this.G , "PtrP" , pCachedBitmap )
This.CachedBitmap := pCachedBitmap
if( Dispose )
Gdip_DisposeImage( pBitmap )
}
DrawCachedBitmap( AutoUpdate := 0 ){
DllCall( "gdiplus\GdipDrawCachedBitmap" , "Ptr" , this.G , "Ptr" , This.CachedBitmap , "Int" , 0 , "Int" , 0 )
if( AutoUpdate )
This.UpdateWindow()
}
DisposeCachedbitmap(){
DllCall( "gdiplus\GdipDeleteCachedBitmap" , "Ptr" , This.CachedBitmap )
}
Helper(){
local hwnd , MethodList := ["__New","UpdateSettings","ShowWindow","HideWindow","UpdateWindow","ClearWindow","DrawBitmap","PaintBackground","DeleteWindow" , "AddTrigger" , "DrawTriggers", "CreateCachedBitmap" , "DrawCachedBitmap" , "DisposeCachedbitmap" ]
Gui, New, +AlwaysOnTop +ToolWindow +HwndHwnd
PopUpWindow.HelperHwnd := hwnd
Gui, Add, Edit, xm ym w250 r1 Center hwndhwnd, Gui1
PopUpWindow.EditHwnd := hwnd
loop, % MethodList.Length()
Gui, Add, Button, xm y+1 w250 r1 gPopUpWindow._HelperClip, % MethodList[ A_Index ]
Gui, Show,,
OnMessage( 0x112 , This._OnClose.Bind( hwnd ) )
}
_HelperClip(){
local ClipList
GuiControlGet, out, % PopUpWindow.HelperHwnd ":", % PopUpWindow.EditHwnd
ClipList := { __New: " := New PopUpWindow( { AutoShow: 1 , X: 0 , Y: 0 , W: A_ScreenWidth , H: A_ScreenHeight , Options: "" -DPIScale +AlwaysOnTop "" } )"
, UpdateSettings: ".UpdateSettings( { X: """" , Y: """" , W: """" , H: """" } , UpdateGraphics := 0 )"
, ShowWindow: ".ShowWindow( Title := """" )"
, HideWindow: ".HideWindow()"
, UpdateWindow: ".UpdateWindow()"
, ClearWindow: ".ClearWindow( AutoUpdate := 0 )"
, DrawBitmap: ".DrawBitmap( pBitmap := """" , { X: 0 , Y: 0 , W: " Out ".W , H: " Out ".H } , dispose := 1 , AutoUpdate := 0 )"
, PaintBackground: ".PaintBackground( color := ""0xFF000000"" , AutoUpdate := 0 ) " ";{ Color: ""0xFF000000"" , X: 2 , Y: 2 , W: " Out ".W - 4 , H: " Out ".H - 4 , Round: 10 }"
, DeleteWindow: ".DeleteWindow( GDIPShutdown := 0 )"
, AddTrigger: ".AddTrigger( { X: """" , Y: """" , W: """" , H: """" , Value: """" , Label: """" } )"
, DrawTriggers: ".DrawTriggers( color := ""0xFFFF0000"" , AutoUpdate := 0 )"
, CreateCachedBitmap: ".CreateCachedBitmap( pBitmap , Dispose := 0 )"
, DrawCachedBitmap: ".DrawCachedBitmap( AutoUpdate := 0 )"
, DisposeCachedbitmap: ".DisposeCachedbitmap()" }
clipboard := Out ClipList[ A_GuiControl ]
}
}
Re: Text to Screen
Here is how you change things.
Add this to the last script.
Add this to the last script.
Code: Select all
F1:: ;Update with new text
Gui1.ClearWindow()
MyNewText := A_Hour ":" A_Min ":" A_Sec
DrawText( Gui1.G , 0 , 0 , MyNewText , "0xFF000000" , Gui1.W , Gui1.H , options := " Center vCenter Bold s152 " , type := "comic Sans MS" )
Gui1.UpdateWindow()
return
F2:: ;Clear the screen
Gui1.ClearWindow( 1 )
return
Re: Text to Screen
Another approach, a simple GUI with TransColor. Try this example:
Code: Select all
data := "
(
AHK 1.1.34
I wish to Display several lines of Text on the Screen
(NOT using Msgbox, as I wish the lines to go to the large area of screen,
NOT a pop-up box)
Is there a way to do this in basic terms.... i.e. as I say,
merely Text... no need for a more colourful GUI approach
Many thanks.
Geoff H.
)"
; https://www.autohotkey.com/boards/viewtopic.php?p=395842#p395842
Gui, -Caption +AlwaysOnTop +Owner +LastFound +E0x20
WinSet, TransColor, 1
Gui, Color, 1
Gui, Font, s18 w700 q4, Times New Roman
Gui, Add, Text,, % data
Gui, Show, NA
Re: Text to Screen
Feel free to check out TextRender at https://github.com/iseahound/TextRender
Despite the large codebase (it's heavily optimized using DllCall) syntax is simple:
Despite the large codebase (it's heavily optimized using DllCall) syntax is simple:
Code: Select all
#include TextRender (for v1).ahk
TextRender("alert!", "time: 3seconds") ; anonymous self-destructing instance
tr := TextRender("This is a more permanent one").Default() ; Adding Default() enables right click to close, whereas its normally right click to copy text
Re: Text to Screen
Hi iseahound,
Many thanks for this, however I have a problem trying it out.....
On trying to run I get the message "TextRender GUI is currently only on AutoHotkey v2"
- although I do see that the comments in the notes say "#Requires AutoHotkey v1.1.33+"
..... I am running on AHK 1.1.33.9
?
Regards.
Geoff H.
Many thanks for this, however I have a problem trying it out.....
On trying to run I get the message "TextRender GUI is currently only on AutoHotkey v2"
- although I do see that the comments in the notes say "#Requires AutoHotkey v1.1.33+"
..... I am running on AHK 1.1.33.9
?
Regards.
Geoff H.
Re: Text to Screen
Hi Hellbent,
Many thanks for your response.
At present I am trying to see if I can get TextRender to resolve my requirement.
I was looking for a concise method (this is going into a straightforward Text environment, in QBasic, it would merely be 6 PRINT statements so I wanted to keep to a minimum)..... thanks once again
Regards.
Geoff H.
Many thanks for your response.
At present I am trying to see if I can get TextRender to resolve my requirement.
I was looking for a concise method (this is going into a straightforward Text environment, in QBasic, it would merely be 6 PRINT statements so I wanted to keep to a minimum)..... thanks once again
Regards.
Geoff H.
Re: Text to Screen
Hi Sofista,
I typed that code in... but nothing was displayed.
At present I am trying to see if I can get TextRender to resolve my requirement.
I was looking for a concise method (this is going into a straightforward Text environment, in QBasic, it would merely be 6 PRINT statements so I wanted to keep to a minimum)
Many thanks for for help & support
Regards.
Geoff H.
I typed that code in... but nothing was displayed.
At present I am trying to see if I can get TextRender to resolve my requirement.
I was looking for a concise method (this is going into a straightforward Text environment, in QBasic, it would merely be 6 PRINT statements so I wanted to keep to a minimum)
Many thanks for for help & support
Regards.
Geoff H.
Re: Text to Screen
Download this file https://github.com/iseahound/TextRender/blob/main/TextRender%20(for%20v1).ahk which is for AutoHotkey v1.
There is a comprehensive getting started tutorial here: https://github.com/iseahound/TextRender/wiki/Quick-Start
Let me know if anything in the tutorial can be improved.
There is a comprehensive getting started tutorial here: https://github.com/iseahound/TextRender/wiki/Quick-Start
Let me know if anything in the tutorial can be improved.
Re: Text to Screen
As I told you before, it is just a GUI. Enclose it between a hotkey and a return, and try it again. Quit the script with control + escape.
Code: Select all
q:: ; change it for the hotkey you want
data := "
(
AHK 1.1.34
I wish to Display several lines of Text on the Screen
(NOT using Msgbox, as I wish the lines to go to the large area of screen,
NOT a pop-up box)
Is there a way to do this in basic terms.... i.e. as I say,
merely Text... no need for a more colourful GUI approach
Many thanks.
Geoff H.
)"
; https://www.autohotkey.com/boards/viewtopic.php?p=395842#p395842
Gui, -Caption +AlwaysOnTop +Owner +LastFound +E0x20
WinSet, TransColor, 1
Gui, Color, 1
Gui, Font, s18 w700 q4, Times New Roman
Gui, Add, Text,, % data
Gui, Show, NA
return
^Esc::
ExitApp
Re: Text to Screen
Many thanks (again) Sofista,
Understood (on how to invoke this).
How may I display these from within some running AHK Code, as opposed to a HotKey? (as, after displaying the lines, I wish to request the User enters a response)
Regards.
Geoff H.
Understood (on how to invoke this).
How may I display these from within some running AHK Code, as opposed to a HotKey? (as, after displaying the lines, I wish to request the User enters a response)
Regards.
Geoff H.
Re: Text to Screen
You are welcome. I see. Try to convert it to a function, for example:
Code: Select all
q:: ; your script
; your code
; your code
data := "
(
I wish to Display several lines of Text on the Screen
(NOT using Msgbox, as I wish the lines to go to the large area of screen,
NOT a pop-up box)
Is there a way to do this in basic terms.... i.e. as I say,
merely Text... no need for a more colourful GUI approach
)"
DisplayTextOnScreen(data)
return
^Esc::
Gui, Destroy
DisplayTextOnScreen(data) {
; https://www.autohotkey.com/boards/viewtopic.php?p=395842#p395842
Gui, -Caption +AlwaysOnTop +Owner +LastFound +E0x20
WinSet, TransColor, 1
Gui, Color, 1
Gui, Font, s18 w700 q4, Times New Roman
Gui, Add, Text,, % data
Gui, Show, NA
}
Re: Text to Screen
Excellent Sofista... exactly what I wanted!! Many, many thanks for your great help, support - and patience!!
Best Regards.
Geoff H.
Best Regards.
Geoff H.
Re: Text to Screen
Glad to be of help
Happy scripting!
Happy scripting!