View previous topic :: View next topic |
Author |
Message |
acw
Joined: 04 Nov 2005 Posts: 165 Location: Darkest Devon
|
Posted: Thu Apr 30, 2009 9:23 pm Post subject: Transparent format windows |
|
|
Hi all,
Has anyone encountered a simple(ish) way of creating a format window with a transparent background (not in .NET world) ?
Cheers,
Alan |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Fri May 01, 2009 7:51 am Post subject: |
|
|
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". |
|
Back to top |
|
|
acw
Joined: 04 Nov 2005 Posts: 165 Location: Darkest Devon
|
Posted: Fri May 01, 2009 9:57 am Post subject: |
|
|
"Layered windows" does the trick using winapi SetLayeredWindowAttributes along with the GWL_EXSTYLE for the window. Details in MSDN. It all works very nicely |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Sat May 09, 2009 11:20 am Post subject: |
|
|
Can you show us an example please?
Eddie |
|
Back to top |
|
|
acw
Joined: 04 Nov 2005 Posts: 165 Location: Darkest Devon
|
Posted: Mon May 11, 2009 5:05 pm Post subject: |
|
|
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:
Code: | ! 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:
Code: | 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 |
|
Back to top |
|
|
acw
Joined: 04 Nov 2005 Posts: 165 Location: Darkest Devon
|
Posted: Mon May 11, 2009 7:35 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
JohnHorspool
Joined: 26 Sep 2005 Posts: 270 Location: Gloucestershire UK
|
Posted: Tue May 12, 2009 8:43 am Post subject: |
|
|
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? |
|
Back to top |
|
|
acw
Joined: 04 Nov 2005 Posts: 165 Location: Darkest Devon
|
Posted: Tue May 12, 2009 9:02 am Post subject: |
|
|
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 ! |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Tue May 12, 2009 9:20 am Post subject: |
|
|
Thanks from me too
Eddie |
|
Back to top |
|
|
|