Hi. I’m trying to make a floating window that has rounded corners and a drop shadow and has no system colors, borders or buttons etc. I want it cross platform but am currently just trying to get it to work on Win32. I have used the CustomWindowShape example included with Xojo and have managed to get part of it working (the shape and no system UI) but I can’t get the image I’m using for the window background to reflect the transparency drop shadow gradient of the png file.
Here’s the code (from this forum) to get rid of the system interface that’s working:
[code] #If TargetWin32 then
//////////////////////////////////////////////////////////////////////////////////////////////////
// — Custom shaped window code - by the Xojo community.
// Original code by Julen Ibarretxe Uriguen
// Modified by Bill Gookin
// Lastly modified by Sam Rowlands
//
// This uses code from the Windows Functionality Suite to reduce flicker.
//
// It works by removing the window’s border and title, then telling the OS to mask out
// a certain color. This is faster than using CreateRectRgn, CombineRgn, DeleteObject
//////////////////////////////////////////////////////////////////////////////////////////////////
// --- The following code reduces the border and window title to nothing!
Const WS_BORDER = &H800000
Const WS_CAPTION = &HC00000
Const WS_THICKFRAME = &H40000
Const WS_MINIMIZE = &H20000000
Const WS_MAXIMIZE = &H1000000
Const GWL_EXSTYLE=-20
Const SWP_FRAMECHANGED = &H20
Const WS_EX_LAYERED=&h00080000
Const GWL_STYLE = -16
const WS_SYSMENU = &h00080000
Declare function GetWindowLong lib "User32" Alias "GetWindowLongA" ( hwnd as integer, flags as integer ) as integer
Dim WS_NOBORDER as integer = GetWindowLong(me.Handle, GWL_EXSTYLE) and not WS_CAPTION and not WS_THICKFRAME and not WS_MINIMIZE and not WS_MAXIMIZE and WS_SYSMENU
Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (hwnd As Integer, nIndex As Integer, dwNewLong As Integer) As Integer
call setwindowlong (me.Handle, GWL_STYLE, WS_NOBORDER)
call setwindowlong (me.Handle, GWL_EXSTYLE,WS_EX_LAYERED) // -- Needed to allow the setLayerWindowAttributes to work
Declare Function SetWindowPos Lib "User32" (hwnd as Integer, hWndInstertAfter as Integer, x as Integer, y as Integer, cx as Integer, cy as Integer, flags as Integer) as Integer
call SetWindowPos(me.WinHWND, 0, left, top, width-1, height-1, SWP_FRAMECHANGED) //Apply border reduction
// --- This last declare is the magic one, that masks out via color. The color is in ARGB, instead of RGBA (Xojo)
Declare function SetLayeredWindowAttributes lib "user32" (hWnd as Integer, ColorRef as integer, AlphaCode as byte, dwFlags as integer) as Boolean
call setlayeredwindowattributes(me.Handle, &h00FFFFFF, 0, 1)
'// --- To reduce 'flickering' we'll freeze the display, refresh and then release.
'Soft Declare Function SendMessageA Lib "User32" ( hwnd as Integer, msg as Integer, wParam as Integer, lParam as Integer ) as Integer
'Soft Declare Function SendMessageW Lib "User32" ( hwnd as Integer, msg as Integer, wParam as Integer, lParam as Integer ) as Integer
'
'Const WM_SETREDRAW = &hB
'
'if System.IsFunctionAvailable( "SendMessageW", "User32" ) then
'call sendMessageW( me.handle, WM_SETREDRAW, 0, 0 )
'me.refresh( true )
'call sendMessageW( me.handle, WM_SETREDRAW, 1, 0 )
'
'else
'call sendMessageA( me.handle, WM_SETREDRAW, 0, 0 )
'me.refresh( true )
'call sendMessageA( me.handle, WM_SETREDRAW, 1, 0 )
'
'end if
#endif
[/code]
What I’m left with is a custom shaped window but instead of a semi-transparent drop shadow over the screen behind, it’s a drop shadow over the system color bg. I’ve been at this for hours and have searched the forum and web and can’t seem to work it out.
To clarify: I am using two pics: 1) A png image (for the window background) with a transparent gradient drop shadow. 2) A mask/matte of that image which is just pure black on white but obviously with a gradient drop shadow from black to white around all four sides.
How can I get the drop shadow to work as you’d expect it to?
Thanks!