0

I have tried several ways to tile my background image for my AutoHotkey (AHK) Version 1.1.36.02 GUI, but always getting error messages.

This is my code:

Gui, -Caption +LastFound +AlwaysOnTop
Gui, +Border
Gui, Margin, 0, 0
Gui, Color, white
Gui, Add, Picture, x0 y0 w1 h52, 1x52.png
Gui, Show, x100 y600 w200 h398

And this is the image I want to use as the tiled background. It is already saved at the same folder of my AHK script, which is 1px x 52px : https://i.stack.imgur.com/mxxNg.png

How can I do this in the correct way?

2
  • Add SetWorkingDir %A_ScriptDir% on top. You cannot see the picture because it is white as the gui color. Mar 13 at 21:20
  • user3419297 you are absolutely right. I removed the Gui, Color, White line and it works now. Thank you.
    – rx65m
    Mar 20 at 12:44

1 Answer 1

0

If you are still looking for a way to get a tiled background, give this a try...

; Tiled Background.ahk has included files...
; BAT.png, BATblack.png, and Weathered.bmp
; Background image must be .bmp file.

; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
#NoEnv ; Recommended for performance and future compatibility.
#Persistent ; Keeps a script permanently running until user closes it or ExitApp is encountered.
#SingleInstance, Force ; Determines whether a script is allowed to run again when it is already running.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
Menu, Tray, Icon, wmploc.dll, 99
; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 

^T::

; = = = = = Use the included testing samples. Must remain in same location as script.
; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 

Gui,
    +Resize          ; Makes the window resizable and enables its maximize button in the title bar.
    +AlwaysOnTop     ; Makes a window stay on top of all other windows.

OnMessage(0x136,"WM_CTLCOLORDLG") 
; = = = = = WM_CTLCOLORDLG message:  Sent to a dialog box before the system draws the dialog box. By responding to this message, the dialog box can set its text and background colors using the specified display device context handle.

Gui, Margin, 15, 15
Gui, Font, S12 Bold, Arial Black

Gui, Add, Picture,x14 y16 Center vImage1 BackgroundTrans , %A_ScriptDir%/BATblack.png    ; Offset shadowed image.
Gui, Add, Picture,x10 y10 Center vImage2 BackgroundTrans , %A_ScriptDir%/BAT.png     ; Image inside Gui.

Gui, Show,, GUI with 'Tiled background' 
Sleep 10
Return

; = = = = = Must use bmp image. Change with personal choice below. "Weathered.bmp" is example.
WM_CTLCOLORDLG(){
    Static wBrush
    If !wBrush
    hBM:=DllCall("LoadImage",Int,0,Str,"Weathered.bmp",Int,0,Int,0,Int,0,UInt,0x2010),wBrush:=DllCall("CreatePatternBrush",UInt,hBM)
    Return wBrush
}
GuiClose:
GuiEscape:
    Reload
;    ExitApp

; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
RETURN

^Home::
    Reload       ; Ctrl + [Home]

^Esc::
    ExitApp          ; Ctrl + [Esc]
; = = = = = 

Images are examples only. Feel free to change this as you see fit.

BATblack Image BAT Image Weathered Image - for tiling

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.