PDA

View Full Version : Transparent background for controls



marcuslee
12-12-2009, 02:29
What is the best way to make the background of a control such as a label transparent? I was trying to get the WS_EX_TRANSPARENT equate to work ... but ;--)

Plus, I was reading that WS_EX_TRANSPARENT doesn't really work the way I want it to work. I am experimenting with creating a dialog that is shaped to a bmp ... but I would also want the backgrounds of my controls to be invisible.


Mark :)

Petr Schreiber
12-12-2009, 14:16
Hi Mark,

I don't know how for other controls, but for label the following trick works.
First parameter is foreground color, second is magic value to not render the label background.


Control SET COLOR hDlg, %label, %BLACK, -2

marcuslee
12-12-2009, 17:17
Hi Mark,

I don't know how for other controls, but for label the following trick works.
First parameter is foreground color, second is magic value to not render the label background.


Control SET COLOR hDlg, %label, %BLACK, -2



Thanks for the tip, but it doesn't seem to work with "Dialog SHAPETOBMP."

Labels, at least in my experience, have a background that matches the system color, so normally, this isn't an issue. It's just when you paint a different background that the question came up.


Mark :read:

Petr Schreiber
12-12-2009, 17:22
Hi Mark,

it worked here, see the attached image.

I just used:


Control ADD LABEL hDlg, 1000, "Ciao Mark, it seems to work for me", 200, 100, 100, 20
Control SET COLOR hDlg, 1000, %WHITE, -2


In the example WinRegion_FromBmp.tBasic.

Could you show me the code where it fails?


Petr

marcuslee
12-12-2009, 17:32
Okay, I did get it to work. I slapped some code into another program and it worked, but I can't get it to work in the following example. I don't know what I was doing wrong. I was using the same code that you were, I think.

Still, this little trick doesn't seem to work for Textboxes and TreeViews. :?


Mark




'---
' Splash window using region created from bitmap files
'---

Uses "UI"
Begin Const
%ID_Label = 1000
%Text01
%Butt01
End Const


DECLARE FUNCTION ReleaseCapture LIB "USER32.DLL" ALIAS "ReleaseCapture" () AS LONG

'------------------------------------------------------------------------------
' Program start point
'------------------------------------------------------------------------------
call Main

'------------------------------------------------------------------------------
' Callback procedure for main window
FUNCTION dlgMain(hDlg as long) as long
'------------------------------------------------------------------------------
local Msg AS LONG
local wParam AS LONG
local lParam AS LONG
local hRegion as long
local hBMP as long

WHILE IsWindow(hDlg)

'---Get the message and fill wParam and lParam
Msg = GetMessage(hDlg, wParam, lParam)

'---Now test the message
SELECT CASE Msg
case %WM_initdialog
'---Shape window following image contours
Dialog SHAPETOBMP hDlg, APP_SourcePath & "BMPRegion.BMP"', RGB(255, 0, 255)
Control ADD TEXTBOX , hDlg, %Text01 , "Hello there" , 100, 100, 200, 12
Control ADD LABEL, hDlg, %ID_Label, "Hello there!", 100, 50, 200, 50, %SS_CENTER
Control SET COLOR, hDlg, %ID_Label,%BLACK,-2



CASE %WM_LBUTTONDOWN
CALL ReleaseCapture
dialog send hDlg, %WM_NCLBUTTONDOWN, %HTCAPTION, %NULL

CASE %WM_RBUTTONDOWN
'---If left mouse click then exit slash window
exit while

CASE %WM_SYSCOMMAND
IF wParam = %SC_CLOSE THEN

EXIT WHILE
end if

END SELECT

wend

'---Close the dialog at the end
DIALOG END hDlg

END FUNCTION

'----------------------------------------------------------------------------
FUNCTION Main() as long
'----------------------------------------------------------------------------
LOCAL hDlg AS DWORD '---Used to store window handle

'---Create a new dialog
Dialog NEW 0, "Regions", -1, -1, 400, 400, %DS_CENTER Or %WS_POPUP Or %WS_VISIBLE Or %WS_SYSMENU, 0 To hDlg
'---Show dialog
Dialog SHOW MODELESS hDlg

'---Call dialog handle routine
call dlgMain(hDlg)

END FUNCTION

Petr Schreiber
12-12-2009, 17:45
Hi Mark,

the code you posted is ok, but uses old way of managing message pump - the one which tortures CPU too much (while isWindow, peekMessage, ...).
Callback mechanism is much more elegant, and the code is almost the same!

Also to note - no need to specify Main function on the end, and then call it.
When you name the main function TBMAIN, thinBASIC starts there automatically.

So here is adaptation of your code (changed text color to red for better visibility here, change as you need):


Uses "UI"

Begin Const
%ID_Label = 1000
%Text01
%Butt01
End Const

DECLARE FUNCTION ReleaseCapture LIB "USER32.DLL" ALIAS "ReleaseCapture" () AS LONG

'------------------------------------------------------------------------------
' Program start point
'------------------------------------------------------------------------------
FUNCTION TBMain() as long
'------------------------------------------------------------------------------
LOCAL hDlg AS DWORD '---Used to store window handle

'---Create a new dialog
Dialog NEW 0, "Regions", -1, -1, 560, 350, %DS_CENTER Or %WS_POPUP Or %WS_VISIBLE Or %WS_SYSMENU, 0 To hDlg


'---Show dialog
DIALOG SHOW modal hDlg, call cbDialog

END FUNCTION

'------------------------------------------------------------------------------
' Callback procedure for main window
'------------------------------------------------------------------------------
callback FUNCTION cbDialog() as long
'------------------------------------------------------------------------------

'---Now test the message
SELECT CASE cbMsg
case %WM_initdialog
'---Shape window following image contours
Dialog SHAPETOBMP CBHNDL, APP_SourcePath & "BMPRegion.BMP"

Control ADD TEXTBOX , CBHNDL, %Text01 , "Hello there" , 100, 100, 200, 12
Control ADD LABEL, CBHNDL, %ID_Label, "Hello there!", 100, 50, 200, 50, %SS_CENTER
Control SET COLOR, CBHNDL, %ID_Label,%RED,-2


CASE %WM_LBUTTONDOWN
CALL ReleaseCapture
dialog send cbhndl, %WM_NCLBUTTONDOWN, %HTCAPTION, %NULL

CASE %WM_RBUTTONDOWN
'---If left mouse click then exit slash window
dialog end cbhndl

END SELECT
End Function


Here label is colored perfectly, textbox not.
I think complete skinning would need more hardcore approach, using low level Win32 coding.

marcuslee
12-12-2009, 18:10
Hi Mark,

the code you posted is ok, but uses old way of managing message pump - the one which tortures CPU too much (while isWindow, peekMessage, ...).
Callback mechanism is much more elegant, and the code is almost the same!

Also to note - no need to specify Main function on the end, and then call it.
When you name the main function TBMAIN, thinBASIC starts there automatically.


Yeah, I hadn't worried about any of those things. I did see the old way, though. I figured it wouldn't be a bother since I was just messing around. Was it one of those things that messed things up?



Here label is colored perfectly, textbox not.
I think complete skinning would need more hardcore approach, using low level Win32 coding.


Without giving me all the answers, what do I need to research in order to accomplish this? Or, if it is easier, can you provide a quick example?


Mark

Petr Schreiber
12-12-2009, 18:16
Hi Mark,

I don't know what caused it precisely, to be fair. I guess it was the message pump.

Regarding Win32 skinning - it is quite complex topic, not sure if fully achieveable in ThinBASIC.
There is PowerBASIC tutorial available, which starts here:
http://www.jose.it-berater.org/smfforum/index.php?topic=1164.0

I don't think this kind of coding is currently possible in ThinBASIC, as it needs native code pointers for "subclassing", which TB does not feature at the moment.

Even Patrice Terrier, the great graphic guru, leaves the textBoxes not transparent in his WinLIFT skinning system:
http://www.jose.it-berater.org/smfforum/index.php?topic=3222.msg11225#msg11225

I think it serves better readability.

marcuslee
12-12-2009, 18:33
Even Patrice Terrier, the great graphic guru, leaves the textBoxes not transparent in his WinLIFT skinning system:
http://www.jose.it-berater.org/smfforum/index.php?topic=3222.msg11225#msg11225


The screen shots in that forum are pretty cool.


Mark