Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Interface and Graphics > Transparent OCX


Reply
 
Thread Tools Display Modes
  #1  
Old 07-16-2012, 08:04 PM
Secret_Face Secret_Face is offline
Newcomer
 
Join Date: Jul 2012
Posts: 3
Talking Transparent OCX


Hello guys, I'm new in this forum. So I was thinking of something interesting, but I have some problems.

So I know how to make semi-transparent window in VB 6.0, but the thing is that every control inside goes transparent with the form. I don't need this. Actually what I need is to make semi-transparent control, for ex. Text box or some scrolls .. So I use this code to make the form transparent

Code:
Private Declare Function SetWindowLong Lib "USER32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Declare Function SetLayeredWindowAttributes Lib "USER32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Private Sub Form_Load()
    SetWindowLong Me.hWnd, (-20), &H80000
    SetLayeredWindowAttributes Me.hWnd, &HFF888, 155, &H2
    
End Sub
check the result in attachment 1.

But it won't work in UserControl form, right ?

Any idea how can I put the text box inside the UserControl, actually to build my "own" text box with UserControl form (attachment 2), and then to make that UserControl transparent. And when I put that OCX in my project voila, I have semi-transparent TextBox
Attached Images
File Type: jpg 1.JPG (13.1 KB, 16 views)
File Type: jpg 2.JPG (8.9 KB, 14 views)
Reply With Quote
  #2  
Old 07-19-2012, 06:29 AM
Secret_Face Secret_Face is offline
Newcomer
 
Join Date: Jul 2012
Posts: 3
Default

Anyone ?
Reply With Quote
  #3  
Old 07-20-2012, 02:08 PM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default Alphablending semi-transparent text control

Just in case no one else answers.

You question is has been asked many many times before (like here).
The issue, as HDC_0 explains in the last post of in this thread:
Quote:
The textbox control doesn't usually "expose" it's device context
except through subclassing..
So now you are probably going to ask:
"I can't find an example of subclassing a textbox - help me!"

There used to be a site called "EliteVB" maintained by someone called "TheHand".

When his site site shut down he made arrangements with the people who used
to run the forum to have his sub-classing examples transferred to the XVBT forum's CodeLibrary,
and thus, attached to this post, you can find an example of what it takes to subclass a textbox.

Of course that just demonstrates "simple" transparency.

"What about alphablending text?" you ask.
(yes, unbelievably, it really helps if you use the "fancy" programming terms like "alphablending"
when talking about such things on a programmers forum..)

Well a quick search of the forum brings up this thread,
which has a link in the first post to rpgnewbie's fader with speed adjust post.

Thus I anticipate your next question:
"Well that example uses two picturebox controls,
how can I adapt it to use text generated at runtime".

The alphablending part is still valid
but you to do a little more work to "paint" the text:
1.) Copy whatever graphics that lies underneath the textbox control
(using the form's device context) into two separate memDC backbuffers.
2.) In memory device context backbuffer #1 you draw text over the graphics.
3.) Then you use the the alpha-blending code to merge the two
memDC backbuffers (graphic image & graphic image with text overlaid),
into a single image / picture showing the semi-transparent text.
4.) "Flip" (transfer) the combined graphic into a picturebox
(with the picbox control's AutoRedraw property set to true)
using the Bitblt API.

Yes --its a little bit involved.
That's why you probably won't get a lot of replies to this post
and why there aren't already hundreds of semi-transparent textbox controls out there.

If you really want to go all out you can also get per pixel semi-transparency using DIBSections,

Note: If you only need to a show just a few lines of text semi-transparency,
instead of creating a special custom ocx yourself,
I would make up the all the needed lines of text (at design time) as a png,
and then just use LaVolpe's AlphaImage control.
There is a more advanced version off forum.

Last edited by surfR2911; 07-20-2012 at 02:40 PM.
Reply With Quote
  #4  
Old 07-20-2012, 03:50 PM
Secret_Face Secret_Face is offline
Newcomer
 
Join Date: Jul 2012
Posts: 3
Default

Thank you buddy, I will read carefully everything and check it out.
I hope I'm gonna make it somehow ))))
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->