Hi all,
Has anyone encountered a simple(ish) way of creating a format window with a transparent background (not in .NET world) ?
Cheers, Alan
Welcome to our forums
Hi all,
Has anyone encountered a simple(ish) way of creating a format window with a transparent background (not in .NET world) ?
Cheers, Alan
I do not know of any reference to opacity except in the .NET context, i.e. I don't think it is available in the native Windows API. This would mean that there is no way to get it via ClearWin+ (there will probably be a way via Visual ClearWin and .NET).
Try doing a detailed search in Google using 'opacity Windows'.
'Layered windows' does the trick using winapi SetLayeredWindowAttributes along with the GWL_EXSTYLE for the window. Details in MSDN. It all works very nicely 😄
Can you show us an example please?
Eddie
For a window with handle hWnd you first set extended style to WS_EX_LAYERED, then you can use SetLayeredWindowAttributes to set the opacity(alpha value) and/or a colour value that should be made transparent. Here's my function for setting the opacity:
! Set opacity level for a window (call after window creation) - automatically
! sets appropriate extented style and sets opacity from 0 (transparent) to
! 255 (no transparency).
logical function SetWindowOpacity(hWnd, alpha)
use mswin
use WinUser
integer, intent(in):: hWnd
integer, intent(in):: alpha
integer:: attrib, i
! Get current window attributes to ensure WS_EX_LAYERED extended style is set
attrib = GetWindowLong(hWnd, GWL_EXSTYLE)
if (IAND(attrib,WS_EX_LAYERED) /= WS_EX_LAYERED) then
i = SetWindowLong(hWnd, GWL_EXSTYLE, IOR(attrib,WS_EX_LAYERED))
end if
! Set layered window alpha value
SetWindowOpacity = SetLayeredWindowAttributes(hWnd, 0, int(alpha,1), LWA_ALPHA)
end function SetWindowOpacity
You'll need to define the functions and some of the constants as they're not in mswin:
module WinUser
integer, parameter:: WS_EX_LAYERED = Z'00080000'
integer, parameter:: LWA_COLORKEY = Z'00000001', &
LWA_ALPHA = Z'00000002'
STDCALL SetLayeredWindowAttributes 'SetLayeredWindowAttributes' (VAL, VAL, VAL, VAL) : LOGICAL*4
end module WinUser
For modeless windows you can just call after all you've created the window, for modal ones it would have to go in a startup handler function.
Hope that helps, Alan
Oops. I've just noticed - should really change the 'int(alpha,1)' to 'CORE1(LOC(alpha))' to stop it having the heebie geebies with values above 128 in checkmate builds.
Alan,
Thanks for that, a great effect, works a treat!
Just got to figure out a good use for it.
When and where do you use it?
Yes it's quite effective, and surprisingly straightforward for Windows ! I use it in a CAD drawing program to create a tool-tip style window that hovers near the crosshairs when editing a model. It gives the user info about the current point, length of line being draw etc. - just extended status info really. I found that a little transparency stops the window getting in the way of the model, but gives you the info you want exactly where you're looking, rather than having to look at a status bar or a window on some other part of the screen. Still - it hasn't been used by any 'real' users yet - they may revolt !
Thanks from me too
Eddie