By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

VB6 Transparency

P: 21
In VB6 , is it possible to have the form invisible but the things inside it visible?
Sep 14 '07 #1
Share this Question
Share on Google+
8 Replies


VBPhilly
P: 95
In VB6 , is it possible to have the form invisible but the things inside it visible?
You have to use windows api in VB6:

Declarations:
Expand|Select|Wrap|Line Numbers
  1. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  2. Private Declare Function SetWindowLong Lib "user32"  Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long,  ByVal dwNewLong As Long) As Long
  3. Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crey As Byte, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
  4. Private Const GWL_EXSTYLE = (-20)
  5. Private Const WS_EX_LAYERED = &H80000
  6. Private Const LWA_ALPHA = &H2&
  7.  
Using the api:
Expand|Select|Wrap|Line Numbers
  1.  Dim bytOpacity As Byte       'Set the transparency level    
  2. bytOpacity = 128    
  3. Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED)    
  4. Call SetLayeredWindowAttributes(Me.hwnd, 0, bytOpacity, LWA_ALPHA)
  5.  

finally, restoring the windows opacity;

Expand|Select|Wrap|Line Numbers
  1.  Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) And (Not WS_EX_LAYERED))
  2.  
Reference: http://articles.techrepublic.com.com...-5031805.html#
Sep 14 '07 #2

kadghar
Expert 100+
P: 1,295
You have to use windows api in VB6:

Declarations:
Expand|Select|Wrap|Line Numbers
  1. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  2. Private Declare Function SetWindowLong Lib "user32"  Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long,  ByVal dwNewLong As Long) As Long
  3. Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crey As Byte, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
  4. Private Const GWL_EXSTYLE = (-20)
  5. Private Const WS_EX_LAYERED = &H80000
  6. Private Const LWA_ALPHA = &H2&
  7.  
Using the api:
Expand|Select|Wrap|Line Numbers
  1.  Dim bytOpacity As Byte       'Set the transparency level    
  2. bytOpacity = 128    
  3. Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED)    
  4. Call SetLayeredWindowAttributes(Me.hwnd, 0, bytOpacity, LWA_ALPHA)
  5.  

finally, restoring the windows opacity;

Expand|Select|Wrap|Line Numbers
  1.  Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) And (Not WS_EX_LAYERED))
  2.  
Reference: http://articles.techrepublic.com.com...-5031805.html#
I've used that method before, but is it possible to make the Form transparente while the controls in it are not?
That'll be really cool
Sep 14 '07 #3

VBPhilly
P: 95
I've used that method before, but is it possible to make the Form transparente while the controls in it are not?
That'll be really cool
I see what you mean. That would be cool.

I dont know of any quick way.

Although, if your desktop is black, you could simply make your form black.

Another idea is to make your visible controls become forms themselves (make the form borderless and the same size as the visible control) and layer them on top of the transparent form. Thats alot of form tracking though.

Anyway, good luck with it.
Sep 14 '07 #4

P: 21
Thanks guys ,but
1) I'd tried the Control-is-a-form method before posting here...But what if you have a circle shape?I Doubt you can have circular forms...
2) I'll try the API Functions Later...
3) <Not Related : How do you add bytes?>
Sep 14 '07 #5

Expert 5K+
P: 8,434
1) I'd tried the Control-is-a-form method before posting here...But what if you have a circle shape?I Doubt you can have circular forms...
I think you can. I've seen a demo of a circular clock or something, which was done just to show off differently-shaped windows. Try a quick search for expressions like "round clock". It may have even been mentioned previously on TheScripts, so you can try our search box up the top.

2) I'll try the API Functions Later...
3) <Not Related : How do you add bytes?>
To what?

By the way, one way you might be able to simulate a transparent form is by taking a snapshot of the screen before displaying your form (standard stuff when writing a screensaver) then paint that picture (appropriately positioned) onto your form.

Oh, one other thing. I didn't read the code form that link (don't have time) but is it possible that it could be applied to one or more controls? That is, set the form to transparent, then set control(s) to non-transparent?
Sep 15 '07 #6

P: 21
Set the form to invisible and the controls visible
Pre-Tried,Useless
Nothing found " Round forms";"Circular Forms"
Sep 15 '07 #7

VBPhilly
P: 95
Pre-Tried,Useless
Nothing found " Round forms";"Circular Forms"
Good old irregular shaped forms.
check out this link:
http://www.thescarms.com/VBasic/IrregularForms.aspx
Sep 15 '07 #8

P: 21
Thank you
<:TOPIC SOLVED:>
Sep 16 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.