[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Transparent "Static" Window

David Youngblood

3/1/2012 5:11:00 PM

Anyone know how to draw a transparent Static class window (created by
CreateWindowEx)? I thought I had everything required, but can't get it to
work. I'm using the vbaccelerator subclassing control while testing. I would
appreciate it if someone could tell me what I'm doing wrong...

Private Sub Form_Load()
Const dwStyle As Long = WS_CHILD Or WS_GROUP Or WS_VISIBLE
Const dwExStyle As Long = WS_EX_TRANSPARENT
Call CreateWindowEx(dwExStyle, "Static", "My window", dwStyle, 0, 0, 100,
20, hwnd, 0, 0, ByVal 0)
AttachMessage Me, hwnd, WM_CTLCOLORSTATIC
End Sub

Private Sub Form_Unload(Cancel As Integer)
DetachMessage Me, hwnd, WM_CTLCOLORSTATIC
End Sub

Private Property Let ISubclass_MsgResponse(ByVal RHS As
SSubTimer6.EMsgResponse)
m_emr = RHS
End Property

Private Property Get ISubclass_MsgResponse() As SSubTimer6.EMsgResponse
m_emr = emrConsume
ISubclass_MsgResponse = m_emr
End Property

Private Function ISubclass_WindowProc(ByVal hwnd As Long, ByVal iMsg As
Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Dim hBr As Long

Select Case iMsg
Case WM_CTLCOLORSTATIC

'* lParam = hwndStatic
'* wParam = hdcStatic

Debug.Print "Mode: "; SetBkMode(wParam, TRANSPARENT)

hBr = GetStockObject(HOLLOW_BRUSH)
Debug.Print "hBrush: "; hBr
Debug.Print "SelectObject: "; SelectObject(wParam, hBr)

ISubclass_WindowProc = CallOldWindowProc(hwnd, iMsg, wParam, lParam)

End Select

End Function


4 Answers

mm

3/1/2012 5:43:00 PM

0

"David Youngblood" <dwy@flash.net> escribió en el mensaje
news:jioakt$9f5$1@dont-email.me...
> Anyone know how to draw a transparent Static class window (created by
> CreateWindowEx)? I thought I had everything required, but can't get it to
> work. I'm using the vbaccelerator subclassing control while testing. I
> would appreciate it if someone could tell me what I'm doing wrong...
>
> Private Sub Form_Load()
> Const dwStyle As Long = WS_CHILD Or WS_GROUP Or WS_VISIBLE
> Const dwExStyle As Long = WS_EX_TRANSPARENT
> Call CreateWindowEx(dwExStyle, "Static", "My window", dwStyle, 0, 0, 100,
> 20, hwnd, 0, 0, ByVal 0)
> AttachMessage Me, hwnd, WM_CTLCOLORSTATIC
> End Sub

if you don't have Option Explicit set, all the supposed constants like
WS_CHILD, WS_EX_TRANSPARENT, Etc., all them will be zeros, without raising
an error (because they are not declared - al least in the code that you
posted -).


MikeD

3/1/2012 11:52:00 PM

0

"David Youngblood" <dwy@flash.net> wrote in message
news:jioakt$9f5$1@dont-email.me...
> Anyone know how to draw a transparent Static class window (created by
> CreateWindowEx)? I thought I had everything required, but can't get it to
> work. I'm using the vbaccelerator subclassing control while testing. I
> would appreciate it if someone could tell me what I'm doing wrong...
>
> Private Sub Form_Load()
> Const dwStyle As Long = WS_CHILD Or WS_GROUP Or WS_VISIBLE
> Const dwExStyle As Long = WS_EX_TRANSPARENT
> Call CreateWindowEx(dwExStyle, "Static", "My window", dwStyle, 0, 0, 100,
> 20, hwnd, 0, 0, ByVal 0)
> AttachMessage Me, hwnd, WM_CTLCOLORSTATIC
> End Sub
>

From what I can see in the above, it looks like all you're doing is creating
a "label" that is 100 pixels in width and 20 pixels in height. So....why
can't you use VB's Label control and set the BackStyle property to
0 -Transparent? It really doesn't look like you're doing anything else, even
in your WindowProc procedure (but possibly you just didn't post all your
code). It might help if you stated exactly what you're trying to accomplish.
I don't mean just "create a static window", but the purpose behind doing
that. Also, post the declarations for the API functions and constants as
you have them in your code. Perhaps those are incorrect. And lastly, you
should explain exactly what problem you're having. Is the window not getting
created? Are you not receiving the WM_CTLCOLORSTATIC message in your
WindowProc?, Details, man, details. <g> Just saying that you can't get it
to work doesn't tell us anything.

Mike


David Youngblood

3/2/2012 7:02:00 AM

0

"MikeD" <nobody@nowhere.edu> wrote...
> "David Youngblood" <dwy@flash.net> wrote in message
>> Anyone know how to draw a transparent Static class window (created by
>> CreateWindowEx)? I thought I had everything required, but can't get it to
>> work. I'm using the vbaccelerator subclassing control while testing. I
>> would appreciate it if someone could tell me what I'm doing wrong...
>>
>> Private Sub Form_Load()
>> Const dwStyle As Long = WS_CHILD Or WS_GROUP Or WS_VISIBLE
>> Const dwExStyle As Long = WS_EX_TRANSPARENT
>> Call CreateWindowEx(dwExStyle, "Static", "My window", dwStyle, 0, 0,
>> 100, 20, hwnd, 0, 0, ByVal 0)
>> AttachMessage Me, hwnd, WM_CTLCOLORSTATIC
>> End Sub
>>
>
> From what I can see in the above, it looks like all you're doing is
> creating a "label" that is 100 pixels in width and 20 pixels in height.
> So....why can't you use VB's Label control and set the BackStyle property
> to 0 -Transparent?

This was just for testing. The end goal is to change some Static class
controls, used in a "legacy" third party control, from opaque to
transparent. It wasn't an issue before xp theming, but with xp themes the
controls just don't look right against a tab control background . Anyway,
the issue has been resolved...

David


David Youngblood

3/2/2012 7:03:00 AM

0

"David Youngblood" <dwy@flash.net> wrote...
> Anyone know how to draw a transparent Static class window (created by
> CreateWindowEx)? I thought I had everything required, but can't get it to
> work.

I was so close, all I needed to do was to return the brush handle,
ISubclass_WindowProc = GetStockObject(NULL_BRUSH)


As a side, this also works with checkbox and option buttons. This code will
make all checkbox and option buttons (within the subclassed parent)
transparent. Declares omitted for brevity and code uses vbaccelerator
subclasser

Private Sub Form_Load()
Me.ClipControls = False
AttachMessage Me, hwnd, WM_CTLCOLORSTATIC
End Sub

Private Sub Form_Unload(Cancel As Integer)
DetachMessage Me, hwnd, WM_CTLCOLORSTATIC
End Sub

Private Property Let ISubclass_MsgResponse(ByVal RHS As
SSubTimer6.EMsgResponse)
m_emr = RHS
End Property

Private Property Get ISubclass_MsgResponse() As SSubTimer6.EMsgResponse
m_emr = emrConsume
ISubclass_MsgResponse = m_emr
End Property

Private Function ISubclass_WindowProc(ByVal hwnd As Long, ByVal iMsg As
Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case iMsg
Case WM_CTLCOLORSTATIC
Call CallOldWindowProc(hwnd, iMsg, wParam, lParam)
Call SetBkMode(wParam, TRANSPARENT)
ISubclass_WindowProc = GetStockObject(NULL_BRUSH)
End Select
End Function