Wrap

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jrachr
Posts: 543
Joined: 01 Mar 2021, 17:33

Wrap

24 Mar 2024, 19:34

GoodDay. I have searched for hours and can't get this. Where in here would I put Wrap to make this text wrap.


Code: Select all

; This script prints a GUI
#Requires AutoHotkey v1.1.33.11
; https://github.com/marius-sucan/AHK-GDIp-Library-Compilation
#Include D:\PortableApps\AutoHotkeyPortable\Data\lib standard\Gdip_All.ahk
Global hWnd
Menu m, Add, &Print `tCtrl+P, print
Gui +HwndhWnd
Gui Menu, m
Gui Font, s10 Bold
Gui Add, Text, w500 h100 Center, Pasta Delivery coming Do not Lock door. Leave open Thank You for your help.        
Gui Show,, Test
Return
User avatar
mikeyww
Posts: 26973
Joined: 09 Sep 2014, 18:38

Re: Wrap

24 Mar 2024, 19:43

If a width (W) is specified in Options but no rows (R) or height (H), the control's text will be word-wrapped as needed, and the control's height will be set automatically.
Source: GUI Control Types - Syntax & Usage | AutoHotkey v1
jrachr
Posts: 543
Joined: 01 Mar 2021, 17:33

Re: Wrap

24 Mar 2024, 19:47

Thank you for such a quick answer. Cheer's
jrachr
Posts: 543
Joined: 01 Mar 2021, 17:33

Re: Wrap

27 Mar 2024, 17:41

Good Evening. This will be the last stab at this for me as I cannot figure it out. According to ahk this script should wrap after 300 pixels and then print what the wrapped gui shows when I press Ctrl & P. But it will not do that.All it does is print the 1 line straight across the page as if it was not wrapped at all. I obviously am doing something wrong but it is beyond me. I know alot of people have tried to help me with and I appreciate it very much. Here is where I am at.

Code: Select all

; This script prints a GUI
#Requires AutoHotkey v1.1.33.11
; https://github.com/marius-sucan/AHK-GDIp-Library-Compilation
#Include D:\PortableApps\AutoHotkeyPortable\Data\lib standard\Gdip_All.ahk
Global hWnd
Menu m, Add, &Print `tCtrl+P, print
Gui +HwndhWnd
Gui Menu, m
Gui Font, s20 Bold
Gui Add, Text,w300,Delivery coming Do not Lock door.Leave open Thank You for your help.        
Gui Show,, Test
Return

print(itemName, itemPos, menuName) {
 ; See also: SGDIPrint-library
 ; https://www.autohotkey.com/board/topic/88606-sgdiprint-library-reposted-with-permission/
 Static image := A_ScriptDir "\gui.png"
      , app   := "d:\utils\irfanView64\i_view64.exe"
 pToken := Gdip_Startup()
 pBitmap := Gdip_BitmapFromHWND(hWnd)
 Gdip_SaveBitmapToFile(pBitmap, image), Gdip_DisposeImage(pBitmap), Gdip_Shutdown(pToken)
 ; Run % app " """ image """ /print" ; IrfanView
 Run % "Print """ image """"         ; Windows Print Pictures
 SoundBeep 1500
}
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Wrap

27 Mar 2024, 18:45

jrachr wrote:this script should wrap after 300 pixels
It does:

jrachr print gui.png
jrachr print gui.png (48.7 KiB) Viewed 244 times
print what the wrapped gui shows when I press Ctrl & P
The Print command is for plain text files. Since you are trying to print an image file (PNG), you should use the IrfanView /print parameter to print it. In other words, in the last script you posted, comment out this line:

Code: Select all

 Run % "Print """ image """"         ; Windows Print Pictures
And un-comment this line:

Code: Select all

; Run % app " """ image """ /print" ; IrfanView
Tested here...works perfectly. Regards, Joe
jrachr
Posts: 543
Joined: 01 Mar 2021, 17:33

Re: Wrap

27 Mar 2024, 19:04

@JoeWinograd. Thank you very much Joe. I am not a script or a programmer which unfortunately for some of this you have to be but when people such as yourself explain it to people such as myself in simple English it is all so clear. As I said I will check tomorrow and get back to you. Cheer's
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Wrap

27 Mar 2024, 19:30

You're welcome, jr. Looking forward to your feedback tomorrow.
jrachr
Posts: 543
Joined: 01 Mar 2021, 17:33

Re: Wrap

28 Mar 2024, 11:21

@JoeWinograd. Well Joe.Murphy's Law.Got all ready for this and printer is out of ink.So when I get some I will get back to you. Once again thank's for your help.

Code: Select all

; This script prints a GUI
#Requires AutoHotkey v1.1.33.11
; https://github.com/marius-sucan/AHK-GDIp-Library-Compilation
#Include D:\PortableApps\AutoHotkeyPortable\Data\lib standard\Gdip_All.ahk
Global hWnd
Menu m, Add, &Print `tCtrl+P, print
Gui +HwndhWnd
Gui Menu, m
Gui Font, s20 Bold
Gui Add, Text,w300,Delivery coming Do not Lock door.Leave open Thank You for your help.        
Gui Show,, Test
Return

print(itemName, itemPos, menuName) {
 ; See also: SGDIPrint-library
 ; https://www.autohotkey.com/board/topic/88606-sgdiprint-library-reposted-with-permission/
 Static image := A_ScriptDir "\gui.png"
      , app   := "D:\PortableApps\IrfanViewPortable\App\IrfanView64\i_view64.exe"
 pToken := Gdip_Startup()
 pBitmap := Gdip_BitmapFromHWND(hWnd)
 Gdip_SaveBitmapToFile(pBitmap, image), Gdip_DisposeImage(pBitmap), Gdip_Shutdown(pToken)
 Run % app " """ image """ /print" ; IrfanView
 ;Run % "Print """ image """"         ; Windows Print Pictures
 SoundBeep 1500
}
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Wrap

28 Mar 2024, 11:58

OK. Btw, I just tested the script in your last post...worked perfectly here.

Edit: Meant to say that you can test the script even with the printer being out of ink by "printing" to a PDF file. That's what I did here, and I was going to upload the file for you to see, but the forum does not allow uploads of PDF files.
jrachr
Posts: 543
Joined: 01 Mar 2021, 17:33

Re: Wrap

30 Mar 2024, 12:40

@JoeWinograd. Well finally got an ink cartridge Joe. Here is where I am at.Your script prints perfectly except for a couple of issues. 1. it only prints across the top of the page(I am guessing I need to increase Font size?). 2. It is printing the Test Print Ctrl + P on the very top of PNG along with rest of of label(Can this be addressed or do I just cut it off?).And 3. I know in order to wrap there can be no spaces at the beginning of text but is there any way if in this case I needed say 5 spaces like in this script I could send them in bulk like we can in regular scripts? Send, {Space6}. As you can see what I have works. Just need it in middle of page and bigger. Once again thank's for all your help.

Code: Select all

; This script prints a GUI
#Requires AutoHotkey v1.1.33.11
; https://github.com/marius-sucan/AHK-GDIp-Library-Compilation
#Include D:\PortableApps\AutoHotkeyPortable\Data\lib standard\Gdip_All.ahk
Global hWnd
Menu m, Add, &Print `tCtrl+P, print
Gui +HwndhWnd
Gui Menu, m
Gui Font, s30 Bold
Gui Add, Text,w500 Center,%A_SPACE%%A_SPACE%%A_SPACE%%A_SPACE%%A_SPACE%%A_SPACE%%A_SPACE%%A_SPACE%Delivery Coming             Please Do not Lock Door        
Gui Show,, Test
Return

print(itemName, itemPos, menuName) {
 ; See also: SGDIPrint-library
 ; https://www.autohotkey.com/board/topic/88606-sgdiprint-library-reposted-with-permission/
 Static image := A_ScriptDir "\gui.png"
      , app   := "D:\PortableApps\IrfanViewPortable\App\IrfanView64\i_view64.exe"
 pToken := Gdip_Startup()
 pBitmap := Gdip_BitmapFromHWND(hWnd)
 Gdip_SaveBitmapToFile(pBitmap, image), Gdip_DisposeImage(pBitmap), Gdip_Shutdown(pToken)
 Run % app " """ image """ /print" ; IrfanView
 ;Run % "Print """ image """"         ; Windows Print Pictures
 SoundBeep 1500
}
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Wrap

30 Mar 2024, 16:23

jrachr wrote:Well finally got an ink cartridge Joe.
OK, but remember my earlier comment...you can test "printing" to a PDF file.
Your script ...
One thing that I want to make very clear...it is NOT my script. All I did was test it when you posted it to show that it does, indeed, wrap to 300 pixels.
it only prints across the top of the page
Yes, the printed page looks like this:

print at top.png
print at top.png (50.84 KiB) Viewed 153 times

But that's because of the image you're creating. If you want it elsewhere on the page, experiment with the width and height params in the Gui,Add,Text line, as well as newline chars in the text itself. To make it easier to experiment, I suggest using a Message variable, such as:

Code: Select all

Message:="`n`n`n`n`n`n`n`n`nDelivery Coming`nPlease Do not Lock Door"
I added that line and replaced the Gui,Add,Text line with this:

Code: Select all

Gui Add,Text,w720 h1040 Center,%Message%
That results in this printed page:

print in middle.png
print in middle.png (47.14 KiB) Viewed 153 times

And, of course, you can experiment with different font sizes and styles. Regards, Joe
jrachr
Posts: 543
Joined: 01 Mar 2021, 17:33

Re: Wrap

30 Mar 2024, 16:47

@joewinograd. First Joe. You are 200 percent correct.You people here helping can only work with the information you have to work with hence the 300 pixels. I tried to get this Print to Pdf to work so I could check as you suggested but could not figure it out. Any direction there would be apprecative. That being said what you have done as far as the message thing is very helpful.Now how do I test it via pdf? Also Please accept my apologies for suggesting it was your script.What I meant was your corrections as far as my initial script went as far as comment this line in and this line out.And last after all this will that test and print Ctrl + P still be at the top of page? Thank you
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Wrap

30 Mar 2024, 19:38

jrachr wrote:Any direction there would be apprecative ... how do I test it via pdf?
You need to get the name of the PDF print driver (it's in Devices and Printers). For example, if you use a third-party PDF print driver, its name may be something like Bullzip PDF Printer, CutePDF Writer, doPDF 11, etc. If you use the print driver built into W10 or W11, it is Microsoft Print to PDF. Put that as a param (enclosed in double-quote marks) in the IrfanView command. For example, change your Run line to this:

Code: Select all

Run % app " """ image """ /print=""Microsoft Print to PDF""" ; IrfanView
will that test and print Ctrl + P still be at the top of page?
Yes, because you're creating a GUI with a Title bar and a Menu. If you don't want those, create a borderless GUI and remove the Menu.

But this raises a question that I've been holding off asking...now is the right time to ask it. Are you doing this to actually achieve the printing goal or are you doing it as a learning experience...to learn about how to code GUIs...how to use Gdip...how to use the IrfanView command line in AHK...etc.? If the former, it doesn't make sense, imo, to create an AHK GUI just for the purpose of printing a page. Why not use Word with a big font? If you don't have Word, use the built-in WordPad. For example, I just created a file in WordPad with the first line as Arial Bold 48-point and the second line as Arial Bold 36-point (both lines centered). It looks like this when printed:

WordPad print to Microsoft PDF.png
WordPad print to Microsoft PDF.png (41.38 KiB) Viewed 129 times

Regards, Joe
jrachr
Posts: 543
Joined: 01 Mar 2021, 17:33

Re: Wrap

30 Mar 2024, 19:51

I was trying to do both learn and print. At end of day trying to do to much at one time. Never thought of wordpad. Will check it out.What you show me will work perfectly. Thank You so much for all your trouble and HELP.Cheer's
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Wrap

30 Mar 2024, 20:07

You're very welcome! Cheers, Joe

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], GEOVAN, mikeyww and 231 guests