I have been attempting to solve this problem for a few weeks now, but I'm not having much luck...
I would like to create a seamless fading effect on each form/window in my program; one that, when an image is clicked with a mouse and held, the window fades away by approximately 50% transparency, and when the mouse button is released, fades back to opaque.
I have been able to do this to an extent, with the SetLayeredWindo wAttributes function, by using the following code: Declarations - Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
-
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
-
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
-
-
Public Type OSVERSIONINFO
-
dwOSVersionInfoSize As Long
-
dwMajorVersion As Long
-
dwMinorVersion As Long
-
dwBuildNumber As Long
-
dwPlatformId As Long
-
szCSDVersion As String * 128
-
End Type
-
-
Public Const GWL_EX_STYLE = -20
-
Public Const LWA_ALPHA = &H2
-
Public Const WS_EX_LAYERED = &H80000
-
-
Public BlendVal As Long
-
Public LayWinAttribRef As Long
-
Public WinVer As OSVERSIONINFO
-
(The version check is included, so that the program can be used in Windows operating systems prior to Windows 2000, without the program causing errors. The initial call to SetLayeredWindo wAttributes in the Form_Activate procedure prevents a black-fade effect from occurring) General Code - Private Sub Form_Activate()
-
-
If WinVer.dwMajorVersion >= 5 Then
-
BlendVal = GetWindowLong(hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED
-
LayWinAttribRef = SetWindowLong(hWnd, GWL_EXSTYLE, BlendVal)
-
SetLayeredWindowAttributes hWnd, 0, 255, LWA_ALPHA
-
End If
-
-
End Sub
-
-
Private Sub imgTitleStetch_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
-
-
Select Case Button
-
Case 1
-
...
-
If WinVer.dwMajorVersion >= 5 Then Call TransFormOut(hWnd, 7)
-
End Select
-
-
End Sub
-
-
Private Sub imgTitleStetch_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
-
-
Select Case Button
-
Case 1
-
If WinVer.dwMajorVersion >= 5 Then Call TransFormIn(hWnd, 7)
-
End Select
-
-
End Sub
-
-
Public Sub TransFormIn(frmHWND As Long, FazeSpeed As Long)
-
-
For Faze = 90 To 255 Step FazeSpeed
-
SetLayeredWindowAttributes frmHWND, 0, Faze, LWA_ALPHA
-
Next Faze
-
-
If Faze <> 255 Then
-
SetLayeredWindowAttributes frmHWND, 0, 255, LWA_ALPHA
-
End If
-
-
End Sub
-
-
Public Sub TransFormOut(frmHWND As Long, FazeSpeed As Long)
-
-
For Faze = 255 To 90 Step -FazeSpeed
-
SetLayeredWindowAttributes frmHWND, 0, Faze, LWA_ALPHA
-
Next Faze
-
-
If Faze <> 90 Then
-
SetLayeredWindowAttributes frmHWND, 0, 90, LWA_ALPHA
-
End If
-
-
End Sub
The above methods works to a degree. Mid-range computers or slower will perform the fade effect fine, but fast computers change the speed of the effect, so that it becomes slower to fade in and out (which doesn't make any sense).
Another method of achieving the fading windows effect is to use the UpdateLayeredWi ndow function (in theory). At current, the best code I have managed to produce using this function is as follows: Declarations - Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
-
Public Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
-
Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
-
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
-
Public Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
-
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
-
Public Declare Function UpdateLayeredWindow Lib "user32" (ByVal hWnd As Long, ByVal hdcDst As Long, pptDst As Any, psize As Any, ByVal hdcSrc As Long, pptSrc As Any, ByVal crKey As Long, ByRef pblend As BLENDFUNCTION, ByVal dwFlags As Long) As Long
-
-
Public Type BLENDFUNCTION
-
BlendOp As Byte
-
BlendFlags As Byte
-
SourceConstantAlpha As Byte
-
AlphaFormat As Byte
-
End Type
-
-
Public Type POINT
-
x As Long
-
y As Long
-
End Type
-
-
Public Type SIZE
-
cx As Long
-
cy As Long
-
End Type
-
-
Public Const GWL_EX_STYLE = -20
-
Public Const ULW_ALPHA = &H2
-
Public Const WS_EX_LAYERED = &H80000
-
-
Public BlendFunc As BLENDFUNCTION
-
Public BlendPic As Long
-
Public BlendVal As Long
-
Public SourceDC As Long
-
Public SourcePoint As POINT
-
Public WindowSize As SIZE
-
For the following code to work properly, the form's "AutoRedraw " property and "HasDC" property must be set to True, and the form's '"ScaleMode" property must be set to Pixels. General Code - Private Sub Form_Activate()
-
-
BlendVal = GetWindowLong(hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED
-
SetWindowLong hWnd, GWL_EXSTYLE, BlendVal
-
-
SourceDC = CreateCompatibleDC(hDC)
-
-
BlendPic = CreateCompatibleBitmap(hDC, ScaleWidth, ScaleHeight)
-
-
SelectObject SourceDC, BlendPic
-
-
BitBlt SourceDC, 0, 0, ScaleWidth, ScaleHeight, hDC, 0, 0, SRCCOPY
-
-
With BlendFunc
-
.AlphaFormat = 0
-
.BlendFlags = 0
-
.BlendOp = AC_SRC_OVER
-
.SourceConstantAlpha = 90
-
End With
-
-
WindowSize.cx = ScaleWidth
-
WindowSize.cy = ScaleHeight
-
-
UpdateLayeredWindow hWnd, 0, ByVal 0, WindowSize, SourceDC, SourcePoint, 0, BlendFunc, ULW_ALPHA
-
ScaleMode = 1 'Change back to twips
-
-
End Sub
As claimed by Microsoft, using the UpdateLayeredWi ndow function is supposedly more efficient than using the SetLayeredWindo wAttributes function.
At the moment, I'm testing the translucent effect (on Windows XP) by starting the program with the first window at a translucency of 90. The code appears to only replicate the background picture of the window, but not the form's controls.
If anyone knows how to use the UpdateLayeredWi ndow function to achieve translucency on an entire form (controls included), I would very much appreciate any answers offered.
0 2557 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Krhis |
last post by:
A friend of mine gave me a link to these two sites, he wanted to know
the scripts that are used here... but it seems that not even I can
help him. So I am hoping some one else could help us by showing were
we could get the sources of these two "fade" effects.
Text links are blue, but when you put your mouse on them, they turn
white (from the left to the right).
Example: http://www.digik.net/
And here too, another one, putting your...
|
by: Lloyd Dupont |
last post by:
In my C# & MC++ app there is some drawing done through GDI (not +, but
win32).
I would like to be able to create a translucent HBRUSH.
the RGB macro create only solid color...
and, anyway, CreateSolidBrush ignore the higher byte.
Any idea?
I though I might do some trick with CreateDIBPatternBrush but I'm not sure
|
by: Chris Lieb |
last post by:
Hi,
I am writing a class in JavaScript to cause a repeating fade effect.
The fade class takes care of the fading and the rgb class takes care of
manipulating rgb values:
function rgb(red, green, blue) {
// private variable initialization
this.red = red;
this.green = green;
|
by: Luciano A. Ferrer |
last post by:
Hello!
Im trying to do a few fade effects here
http://relojurbano.com.ar/scalda/baseporque.php
using fadomatic
( http://chimpen.com/fadomatic/ )
I dont know if fadomatic is a good solution for it
but Im having problems with IE...
If you look that page in IE, the upper fades do not work
|
by: Immortalist |
last post by:
Various aquisition devices that guide learning along particular
pathways towards human biases. And as E.O. Wilson might say mental
development appears to be genetically constrained.
(1) Language Aquisition Device
(2) Color Aqusition Device
(3) Sound Aquistion Device
(4) Smell Aquisition Device
(5) Touch Aquisition Device
(6) Art Aquisition Device
| |
by: Ali Rizwan |
last post by:
Hi all,
I made a usercontrol and want to give fade effects to it.
Now problem is that i m using alpha command as i use in my cool form.
Nothing is happninig.
How can i give fade effect to a usercontrol.
Thanx
|
by: Gretsch |
last post by:
Hi,
Can someone help me with the command format please.
I have a function (called fade) that was 3 parameters:
the first 2 are colours therefore formatted #123456
and the 3rd is a number of milliseconds.
A normal call to the function therefore looks like this:
|
by: Sin Jeong-hun |
last post by:
As far as I know if I change the form's opacity, every control on the
form also inherits that opacity. But in many real applications (not
application programs), we see opaque text (100% opacity) on a
traslucent background, for example text messages on TV. Or look at the
title bar text of Aero. Background is translucent but the text is
opaque.
Is it possible to use 100% opaque text on a traslucent form?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |