String Gadget Background Transparent?
String Gadget Background Transparent?
How can i do this?
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
For a text gadget it's not so hard, but for a string gadget, editing must be taken into account. The problem is that erasing with a null brush doesn't erase anything! So, let the hacks begin...
Code: Select all
;===============================================================
; Program: A bunch of dirty hacks
; Author: netmaestro
; Date: December 2, 2007
; Target OS: Microsoft Windows all
; Target compiler: PureBasic 4.xx and later
; License: Free, unrestricted, use at your own risk
;===============================================================
Global stringpattern.l, bkswitch.l = 0
CreateImage(0,320,240,32)
StartDrawing(ImageOutput(0))
For i=0 To 231 Step 16
For j = 0 To 311 Step 16
Box(j,i,8,8,RGB(230,230,255))
Box(j+8,i,8,8,#White)
Box(j,i+8,8,8,#White)
Box(j+8,i+8,8,8,RGB(230,230,255))
Next
Next
StopDrawing()
Procedure WinProc(hwnd, msg, wparam, lparam)
result = #PB_ProcessPureBasicEvents
Select msg
Case #WM_CTLCOLOREDIT
hdc = wParam
SetTextColor_(hdc, #Black)
SetBkMode_(hdc, #TRANSPARENT)
result = stringpattern
EndSelect
ProcedureReturn result
EndProcedure
OpenWindow(0,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
ImageGadget(0,0,0,0,0,ImageID(0))
DisableGadget(0, #True)
StringGadget(1,10,10,200,20,"hello")
GrabImage(0, 1, GadgetX(1)+2,GadgetY(1)+2, GadgetWidth(1)-2,GadgetHeight(1)-2)
stringpattern = CreatePatternBrush_(ImageID(1))
SetWindowCallback(@WinProc())
Repeat:Until WaitWindowEvent()=#WM_CLOSE
DeleteObject_(stringpattern)
Last edited by netmaestro on Mon Dec 03, 2007 1:07 am, edited 3 times in total.
BERESHEIT
Doesn't work properly here netty until you remove the Select / EndSelect in the subclass proc.
On my machine, enter some text, cursor back and then insert more text and the entire string gadget's contents become all mixed up.
As I say, the problem is rectified by removing the Select etc.
Otherwise, very nice. Hack central here we come!
On my machine, enter some text, cursor back and then insert more text and the entire string gadget's contents become all mixed up.
As I say, the problem is rectified by removing the Select etc.
Otherwise, very nice. Hack central here we come!
I may look like a mule, but I'm not a complete ass.
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
You can remove the timers completely if you just take the string gadget border into account. Here I did it manually :
Code: Select all
;===============================================================
; Program: A bunch of dirty hacks
; Author: netmaestro
; Date: December 2, 2007
; Target OS: Microsoft Windows all
; Target compiler: PureBasic 4.xx and later
; License: Free, unrestricted, use at your own risk
;===============================================================
CreateImage(0,320,240,32)
StartDrawing(ImageOutput(0))
For i=0 To 231 Step 16
For j = 0 To 311 Step 16
Box(j,i,8,8,RGB(230,230,255))
Box(j+8,i,8,8,#White)
Box(j,i+8,8,8,#White)
Box(j+8,i+8,8,8,RGB(230,230,255))
Next
Next
StopDrawing()
Procedure StringProc(hwnd, msg, wparam, lparam)
oldproc = GetProp_(hwnd, "oldproc")
Select msg
Case #WM_KEYDOWN
; Select wparam
; Case 8, 32
hdc = GetWindowDC_(#Null)
hdcout = GetDC_(hwnd)
hdcin = CreateCompatibleDC_(hdc)
SelectObject_(hdcin, ImageID(1))
BitBlt_(hdcout,0,0,200,20,hdcin,0,0,#SRCCOPY)
ReleaseDC_(0, hdc)
DeleteDC_(hdcin)
ReleaseDC_(hwnd, hdcout)
InvalidateRect_(hwnd, 0,1)
; EndSelect
Case #WM_NCDESTROY
RemoveProp_(hwnd, "oldproc")
EndSelect
ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
EndProcedure
Procedure WinProc(hwnd, msg, wparam, lparam)
result = #PB_ProcessPureBasicEvents
Select msg
Case #WM_CTLCOLOREDIT
hdc = wParam
SetTextColor_(hdc, #Black)
SetBkMode_(hdc, #TRANSPARENT)
result = GetStockObject_(#NULL_BRUSH)
EndSelect
ProcedureReturn result
EndProcedure
OpenWindow(0,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
ImageGadget(0,0,0,0,0,ImageID(0))
DisableGadget(0, #True)
UpdateWindow_(WindowID(0))
StringGadget(1,10,10,200,20,"")
GrabImage(0, 1, 12,12, 200, 20)
SetGadgetText(1, "initial value"); Here is where you would set an initial text for the gadget
oldproc = SetWindowLong_(GadgetID(1), #GWL_WNDPROC, @StringProc())
SetProp_(GadgetID(1), "oldproc", oldproc)
SetWindowCallback(@WinProc())
Repeat:Until WaitWindowEvent()=#WM_CLOSE
I may look like a mule, but I'm not a complete ass.
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
hehe, I just hacked a lot of your code to get one which works with themes etc. I'll post and then have a look at yours :
Code: Select all
;===============================================================
; Program: A bunch of dirty hacks
; Author: netmaestro
; Date: December 2, 2007
; Target OS: Microsoft Windows all
; Target compiler: PureBasic 4.xx and later
; License: Free, unrestricted, use at your own risk
;===============================================================
Global stringpattern
CreateImage(0,320,240,32)
StartDrawing(ImageOutput(0))
For i=0 To 231 Step 16
For j = 0 To 311 Step 16
Box(j,i,8,8,RGB(230,230,255))
Box(j+8,i,8,8,#White)
Box(j,i+8,8,8,#White)
Box(j+8,i+8,8,8,RGB(230,230,255))
Next
Next
StopDrawing()
Procedure WinProc(hwnd, msg, wparam, lparam)
result = #PB_ProcessPureBasicEvents
Select msg
Case #WM_CTLCOLOREDIT
hdc = wParam
SetTextColor_(hdc, #Black)
SetBkMode_(hdc, #TRANSPARENT)
result = stringpattern
EndSelect
ProcedureReturn result
EndProcedure
OpenWindow(0,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
ImageGadget(0,0,0,0,0,ImageID(0))
DisableGadget(0, #True)
UpdateWindow_(WindowID(0))
StringGadget(1,10,10,200,20,"")
GrabImage(0, 1, 12,12, 200, 20)
stringpattern = CreatePatternBrush_(ImageID(1))
SetGadgetText(1, "initial value"); Here is where you would set an initial text for the gadget
SetWindowCallback(@WinProc())
Repeat:Until WaitWindowEvent()=#WM_CLOSE
I may look like a mule, but I'm not a complete ass.
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Yep almost identical except I don't use the timer!
What am I talking about, it's all your code anyhow?
**EDIT : oops, clumsy me with the oversized grab! Course with that method I should throw some GetSystemMetrics_() etc.
I agree, it's a nice way of doing it and seems pretty tight.
What am I talking about, it's all your code anyhow?
**EDIT : oops, clumsy me with the oversized grab! Course with that method I should throw some GetSystemMetrics_() etc.
I agree, it's a nice way of doing it and seems pretty tight.
I may look like a mule, but I'm not a complete ass.
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
-
- 666
- Posts: 1033
- Joined: Mon Sep 01, 2003 2:33 pm
netmaestro & Srod... Just want you both to know (no taking the piddle out of a drunk bloke now) I have nothing but very deep respect for both of you... shame you both smell of wee haha, sorry! I wish I had 1/5th of the talent you guys show around here! Gentlemen, if either of you venture to sunny telford, I promise to buy you a beer or ten!
I'm on my way!LuCiFeR[SD] wrote:Gentlemen, if either of you venture to sunny telford, I promise to buy you a beer or ten!
Actually, I pass Telford (on my way to Shrewsbury) a couple of times every year. The next scheduled pit-stop is early Jan when I intend to down a keg or two without spilling a drop.
Aye, looks like I'll be dancing naked through the streets of Shrewsbury again...
I may look like a mule, but I'm not a complete ass.