Text to Screen

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
geoffh
Posts: 48
Joined: 25 Mar 2014, 10:01

Text to Screen

Post by geoffh » 21 Sep 2022, 14:50

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.

User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Text to Screen

Post by Hellbent » 21 Sep 2022, 17:17

Text on screen using GDI+ and a layered window.
temp.gif
temp.gif (420.12 KiB) Viewed 1702 times

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 ]
		
	}
}

User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Text to Screen

Post by Hellbent » 21 Sep 2022, 17:25

Here is how you change things.
Add this to the last script.
temp.gif
temp.gif (180.91 KiB) Viewed 1692 times

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

sofista
Posts: 644
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Text to Screen

Post by sofista » 21 Sep 2022, 17:35

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

iseahound
Posts: 1427
Joined: 13 Aug 2016, 21:04
Contact:

Re: Text to Screen

Post by iseahound » 22 Sep 2022, 13:19

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:

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

geoffh
Posts: 48
Joined: 25 Mar 2014, 10:01

Re: Text to Screen

Post by geoffh » 24 Sep 2022, 08:14

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.

geoffh
Posts: 48
Joined: 25 Mar 2014, 10:01

Re: Text to Screen

Post by geoffh » 24 Sep 2022, 08:19

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.

geoffh
Posts: 48
Joined: 25 Mar 2014, 10:01

Re: Text to Screen

Post by geoffh » 24 Sep 2022, 08:21

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.

iseahound
Posts: 1427
Joined: 13 Aug 2016, 21:04
Contact:

Re: Text to Screen

Post by iseahound » 24 Sep 2022, 16:09

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.

sofista
Posts: 644
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Text to Screen

Post by sofista » 24 Sep 2022, 16:57

geoffh wrote:
24 Sep 2022, 08:21
Hi Sofista,

I typed that code in... but nothing was displayed.

[...]
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

geoffh
Posts: 48
Joined: 25 Mar 2014, 10:01

Re: Text to Screen

Post by geoffh » 25 Sep 2022, 09:22

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.

sofista
Posts: 644
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Text to Screen

Post by sofista » 25 Sep 2022, 12:13

geoffh wrote:
25 Sep 2022, 09:22
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.
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
}

geoffh
Posts: 48
Joined: 25 Mar 2014, 10:01

Re: Text to Screen

Post by geoffh » 26 Sep 2022, 06:43

Excellent Sofista... exactly what I wanted!! Many, many thanks for your great help, support - and patience!! :lol: :lol:

Best Regards.

Geoff H.

sofista
Posts: 644
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Text to Screen

Post by sofista » 26 Sep 2022, 11:25

Glad to be of help :D

Happy scripting!

Post Reply

Return to “Ask for Help (v1)”