forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Transparent format windows

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
acw



Joined: 04 Nov 2005
Posts: 165
Location: Darkest Devon

PostPosted: Thu Apr 30, 2009 9:23 pm    Post subject: Transparent format windows Reply with quote

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
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Fri May 01, 2009 7:51 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
acw



Joined: 04 Nov 2005
Posts: 165
Location: Darkest Devon

PostPosted: Fri May 01, 2009 9:57 am    Post subject: Reply with quote

"Layered windows" does the trick using winapi SetLayeredWindowAttributes along with the GWL_EXSTYLE for the window. Details in MSDN. It all works very nicely Very Happy
Back to top
View user's profile Send private message Visit poster's website
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Sat May 09, 2009 11:20 am    Post subject: Reply with quote

Can you show us an example please?

Eddie
Back to top
View user's profile Send private message
acw



Joined: 04 Nov 2005
Posts: 165
Location: Darkest Devon

PostPosted: Mon May 11, 2009 5:05 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
acw



Joined: 04 Nov 2005
Posts: 165
Location: Darkest Devon

PostPosted: Mon May 11, 2009 7:35 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Tue May 12, 2009 8:43 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
acw



Joined: 04 Nov 2005
Posts: 165
Location: Darkest Devon

PostPosted: Tue May 12, 2009 9:02 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Tue May 12, 2009 9:20 am    Post subject: Reply with quote

Thanks from me too

Eddie
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group