Maybe you can find something helpful in this Win32 only code. I didn't use a standard PB StriingGadget because I wanted to lose the #ES_AUTOHSCROLL that PB seems to add to all StringGadgets. This allowed for better control of the auto word wrap.
I used PB logo for the background since everyone should have it available. You can change the image path to suit your needs.
Quickly tested on WinXPhome and Win98fe with PB 3.91. Sorry it's not commented very well.
Code: Select all
Global hString1, stringBrush, windowBrush, OldCallback
; change LoadImage() path to your image of choice
myImage = LoadImage(0, "C:\Program Files\PureBasic\Examples\Sources\Data\PureBasicLogo.bmp")
windowBrush = CreatePatternBrush_(myImage)
stringBrush = GetStockObject_(#HOLLOW_BRUSH)
Procedure myWindowCallback(hWnd, message, wParam, lParam)
result = #PB_ProcessPureBasicEvents
Select message
Case #WM_COMMAND
If lParam = hString1
InvalidateRect_(lParam, 0, 1)
EndIf
Case #WM_CTLCOLOREDIT
SetBkMode_(wParam, #TRANSPARENT)
SetTextColor_(wParam, RGB(215, 215, 0))
result = windowBrush
EndSelect
ProcedureReturn result
EndProcedure
Procedure.l myScrollCallback(hWnd, msg, wParam, lParam)
result = CallWindowProc_(OldCallback, hWnd, msg, wParam, lParam)
Select msg
Case #WM_VSCROLL
InvalidateRect_(hWnd, 0, 1)
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 381, 138, #PB_Window_ScreenCentered |#PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget| #PB_Window_SystemMenu, "Transparent StringGadget")
SetWindowCallback(@myWindowCallback())
CreateStatusBar(0, WindowID(0))
StatusBarText(0, 0, "** NOTE ** There will be some minor flickering from time to time.")
SetClassLong_(WindowID(),#GCL_HBRBACKGROUND,windowBrush)
hString1 = CreateWindowEx_(#WS_EX_CONTROLPARENT | #WS_EX_CLIENTEDGE, "EDIT", "", #WS_TABSTOP | #WS_CHILD | #WS_VISIBLE | #WS_VSCROLL | #ES_LEFT | #ES_AUTOVSCROLL | #ES_MULTILINE | #ES_WANTRETURN, 10, 10, 361, 60, WindowID(0) ,1 ,GetModuleHandle_(0), 0)
SetClassLong_(hString1, #GCL_HBRBACKGROUND, stringBrush)
OldCallback = SetWindowLong_(hString1, #GWL_WNDPROC, @myScrollCallback())
style = GetWindowLong_(WindowID(0), #GWL_STYLE)
newstyle = style | #WS_CLIPCHILDREN
SetWindowLong_(WindowID(0), #GWL_STYLE, newstyle)
Restore stringdata
For i = 0 To 19
Read sd$
sAll$ + sd$
Next
SendMessage_(hString1, #EM_REPLACESEL, 0, sAll$)
EndIf
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_EventSizeWindow
MoveWindow_(hString1, 0, 0, WindowWidth()+3, WindowHeight()-20, 1)
EndSelect
Until Event = #PB_Event_CloseWindow
DeleteObject_(windowBrush)
End
; sample text for Edit control aka StringGadget
DataSection
stringdata:
Data.s "Global hString1, stringBrush, windowBrush, OldCallback"
Data.s "; change LoadImage() path to your image of choice"
Data.s "myImage = LoadImage(0, 'C:\Program Files\PureBasic\Examples\Sources\Data\PureBasicLogo.bmp')"
Data.s "windowBrush = CreatePatternBrush_(myImage)"
Data.s "stringBrush = GetStockObject_(#HOLLOW_BRUSH)"
Data.s "Procedure myWindowCallback(hWnd, message, wParam, lParam)"
Data.s " result = #PB_ProcessPureBasicEvents"
Data.s " Debug hString1"
Data.s " Select message"
Data.s " Case #WM_COMMAND"
Data.s " If lParam = hString1"
Data.s " InvalidateRect_(lParam, 0, 1)"
Data.s " EndIf"
Data.s " Case #WM_CTLCOLOREDIT"
Data.s " SetBkMode_(wParam, #TRANSPARENT)"
Data.s " SetTextColor_(wParam, #BLACK)"
Data.s " result = windowBrush"
Data.s " EndSelect"
Data.s " ProcedureReturn result"
Data.s "EndProcedure"
EndDataSection