Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[How To] set a 'Tiled background' for GUI ?


  • Please log in to reply
7 replies to this topic
SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

How to set a 'Tiled background' for GUI ?
http://www.autohotke...p=467410#467410


Posted Image

#SingleInstance, Force

IfNotExist, tile.bmp,  UrlDownloadToFile, http://goo.gl/F9KIf,          tile.bmp
IfNotExist, lens.png,  UrlDownloadToFile, http://i.imgur.com/pGL6k.png, lens.png

Gui +Resize
; [color=#808080]Gui, Color, FFFFFF[/color] [color=Red] ; <- NEVER USE THIS along with WM_CTLCOLORDLG[/color]

[color=darkred]OnMessage([/color] 0x136, "[color=red]WM_CTLCOLORDLG[/color]" [color=darkred])[/color]

Gui, Font, S30 Bold, Arial Black
Gui, Add, Text, w450 y90 c880000 Border 0x201, WM_CTLCOLORDLG
Gui, Add, Picture, xm+25 ym BackgroundTrans, lens.png
Gui, Show,, GUI with 'Tiled background' ( Maximize/Resize this window )
Sleep 1
Return

[color=red]WM_CTLCOLORDLG() {[/color]
Static wBrush
  If ! wBrush
    hBM := DllCall( "[color=darkred]LoadImage[/color]", Int,0, Str,"tile.bmp", Int,0, Int,0, Int,0, UInt,0x2010 )
  , wBrush := DllCall( "[color=darkred]CreatePatternBrush[/color]", UInt,hBM )
Return wBrush
[color=red]}[/color]


The code snippet should be self explanatory, except for a couple of DllCalls.
All you might need is to change the file name for "tile.bmp" to your own bitmap.

The code snippet downloads the following two images:

Posted ImagePosted Image



[*:2e5lr0tw]Do not use Gui, Color, < Color > when monitoring WM_COLORCTLDLG. Your script will never receive the message.


[*:2e5lr0tw]If your GUI is fixed size and you fancy gradient background, you may use GDI_QuickBitmap()


kWo4Lk1.png

Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
Looks like we're circling around the same places lately. ;)

No later than the other day I was playing with this Pattern Brush, trying to set a bitmap background to an Edit control. Subclassing the Window Procedure and hooking WM_CTLCOLOREDIT works fine, as long as there's no text in the Edit box. But as soon as I type something inthere, the whole row will be filled with the designated background color, hiding the bitmap background.

Do you know if there's a way to draw the text transparently in an Edit control, so as to preserve the bitmap background aspect? 8)

(AHK 1.0.48.05 and Win98SE) forever | My scripts are here


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Looks like we're circling around the same places lately. ;)


I have been attempting to reproduce USkin's functionality with native message monitoring ( global subclassing ).
Even USkin is unable to override Gui, Color command. :(

BTW, I decided to post this tip ( before I forget ) after seeing ( again ) this hard solution: Tiled GUI background?

a way to draw the text transparently in an Edit control, so as to preserve the bitmap background aspect? 8)


Call SetBkMode() before returning the Brush:

DllCall( "SetBkMode", UInt,wParam, UInt,1 ) ; TRANSPARENT

Also, take a look at Lexikos' code ( the original idea ) : <!-- m -->http://www.autohotke... ... 695#164695<!-- m -->

:)

Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
Yep, SetBkMode is all that was needed. I must've been too tired at the time, not to try this one, coz I already have been through SetBkColor and other combinations. Nice find, thank you!
There's still an issue that most likely belongs to Win9x, where the brush appears shifted both vertically and horizontally, thing that does not happen on XP (with the same code). I know Win95 doesn't accept bitmaps larger than 8x8 px, but Win98 and later are supposed to. Oh well, that's another thing I'll have to test further.

That USkin, is it of any good? I'm not sure I can test it here, since I already have Tihiy's Revolutions Pack installed on my 98SE, which includes a full system skiining engine, which used to be called UberSkin - quite close resemblance to this USkin. I'll go have a look though, maybe it has some good ideas to offer. ;)

EDIT: see comparison screenshot below
Posted Image

(AHK 1.0.48.05 and Win98SE) forever | My scripts are here


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

That USkin, is it of any good?

It does not support all controls and offers no flexibility.
Even to change a font, one has to resort to GuiControl after creating the control.

I'm not sure I can test it here, since I already have Tihiy's Revolutions Pack installed on my 98SE, which includes a full system skiining engine, which used to be called UberSkin - quite close resemblance to this USkin. I'll go have a look though, maybe it has some good ideas to offer. ;)


Please let me know. I guess that: if it uses a global hook then it will have the upper-hand.

Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
USkin examples run on 98SE but no skinning occurs whatsoever. That trial dialog is very annoying too.
I'll look at the code but honestly, my hopes are low considering it's written in C# (if I'm not mistaken).
If you could get Tihiy (at the MSFN.org forum) to show you the UberSkin code used in Revolutions Pack, now that may be a good source of inspiration. I'm not sure if he would do that, though.

EDIT: I just remembered this toy, always from CodeProject, that I has tested few years ago and it does work in 98SE (with .NET installed): XPExplorerBar. I personally am not fond of .NET though, it's too high of a language for me; I'd prefer ASM if I had to choose.

(AHK 1.0.48.05 and Win98SE) forever | My scripts are here


iBob35555VR
  • Members
  • 89 posts
  • Last active: Dec 24 2012 03:32 PM
  • Joined: 02 Dec 2011

How to set a 'Tiled background' for GUI ?

is possible to make a function to directly add one?
example:
AddGUIBackground("Tile.bmp")
then, have the background Tile.bmp in the GUI...
and, if is possible... say the function here? :D
... All posts where I said the word "smart", maybe, I meant "small" as I had them confused. "Smart script","Smart change" etc are examples.

maestrith
  • Members
  • 786 posts
  • Last active: Apr 10 2019 01:28 PM
  • Joined: 17 Sep 2005

I hate to see good code go bad.

Re-post:

#SingleInstance, Force

IfNotExist,tile.bmp,UrlDownloadToFile,http://www.maestrith.com/files/tile.bmp,tile.bmp
IfNotExist,lens.png,UrlDownloadToFile,http://i.imgur.com/pGL6k.png,lens.png

Gui,+Resize

OnMessage(0x136,"WM_CTLCOLORDLG")

Gui, Font, S30 Bold, Arial Black
Gui, Add, Text, w450 y90 c880000 Border 0x201, WM_CTLCOLORDLG
Gui, Add, Picture, xm+25 ym BackgroundTrans, lens.png
Gui, Show,, GUI with 'Tiled background' ( Maximize/Resize this window )
Sleep 1
Return

WM_CTLCOLORDLG(){
	Static wBrush
	If !wBrush
	hBM:=DllCall("LoadImage",Int,0,Str,"tile.bmp",Int,0,Int,0,Int,0,UInt,0x2010),wBrush:=DllCall("CreatePatternBrush",UInt,hBM)
	Return wBrush
}
GuiClose:
GuiEscape:
ExitApp
return

Changed the url for the bmp because the old link is dead.

Stripped out all of the old color code.