How to create a transparent window (hand-coded)?

I am in search of how to create a transparent window. Using the code below (USER32.lib, and SetLayeredWindowAttributes()), the program is not compiling. I think it is because I do not have USER32.lib. Duh!

Is this the best way of creating a transparent window anyway? Or, is there another solution?

PROGRAM

  MAP
    MODULE( 'USER32.LIB' )
      SETLAYEREDWINDOWATTRIBUTES( long, long, byte, long ), long
    END
  END

WIN WINDOW,AT(,,395,224),FONT('MS Sans Serif',8,,FONT:regular),GRAY,NOFRAME
       BUTTON('&OK'),AT(309,201,35,14),USE(?OkButton),LEFT,DEFAULT
       BUTTON('&Cancel'),AT(351,201,36,14),USE(?CancelButton),LEFT
     END

  CODE
  OPEN(WIN)
  I# = SetLayeredWindowAttributes(0, 0, 128, 2h) !not sure about the 2h as the last parameter...
  ACCEPT
  END
  CLOSE(WIN)

I’d first read the doc of SetLayeredWindowAttributes api to not passing random values.

What release of Clarion are you using?
Later releases have SetLayeredWindowAttribute including in the Win API exports,. but earlier releases don’t and so you need to create a custom User32.Lib file using Clarion’s LibMaker.

Note also that your API declaration is missing the required attributes PASCAL and NAME eg

           SetLayeredWindowAttributes(long hwnd,long crKey,long bAlpha,long dwFlags),long,pascal,raw,name('SetLayeredWindowAttributes')

Attached is a complete hand coded project that creates a normal window and then (on a timer tick) gradually makes it more and more transparent.

Created originally in Clarion 9 (where the custom User32.LIB file is required) - in later Clarion releases you’ll need to remove the MyUser32.LIB file from the project to get rid of duplicate declaration errors.Transparency.zip (1.9 KB)

The Name() is not required in this case because the Label is the Windows Export name. It is common to add a unique prefix of your own to avoid a future duplicate symbol when you include something that also defines that function without any decoration. e.g. you might prefix with “Bobs_”

Bobs_SetLayeredWindowAttributes(long hwnd,long crKey,long bAlpha,long dwFlags),BOOL,pascal,raw,name('SetLayeredWindowAttributes')

This function returned a BOOL that was chnaged to LONG. The BOOL type exists is Clairon as EQUATE(LONG). I would suggest leaving the Prototype as BOOL so you know it returns True or False with True being success. An API that returns LONG or DWORD you have to look at MSDN to see what kind of info it returns, and what values = success.

And “raw” isn’t really necessary there either. If you’re passing *CSTRING, raw doesn’t pass the extra “length” data. Not sure if there are other data types where raw is useful, but it has to do with passing something by address.

Thanks for all of the replies, Guys! Much appreciated.

I go back and forth between using Clarion (C6 or C10) and PureBasic. Both have their strengths and weaknesses. Clarion is so easy to use for windows, reports, and databases. PureBasic is when you want to do some lower level stuff. Here is the code in PureBasic that I used yesterday to accomplish a transparent window and it meets my needs. PureBasic takes more work to get things done but sometimes it just works. For my needs I need both languages.

Here is the “PureBasic” code:

Procedure   SetWindowTranparency(Window, TransparencyColor = #Cyan, Transparency = 255)
Protected hWnd = WindowID(window)
   ;Transform into opaque layered window
   SetWindowLongPtr_(hWnd, #GWL_EXSTYLE, GetWindowLongPtr_(hWnd, #GWL_EXSTYLE) | #WS_EX_LAYERED)
   SetLayeredWindowAttributes_(hWnd, TransparencyColor, Transparency, #LWA_COLORKEY | #LWA_ALPHA)
EndProcedure

! Code to open the window and set it as transparent that happens in the Main() portion of the program:
Define MainWindow = CreateWindow(Width, WindowY)
SetWindowTranparency(MainWindow, #Black, 255)

My goal was to create a transparent window that had colored lines. Using the lines, a driver in iRacing could use the lines as “turn-in points”. I have some more tweaking to do but the “guides” really helped me drive the Dalllara F3 at Oulton Park! A very fast track to drive. This works good for practice but in a race it would be too distracting. We sometimes use the details on the car driven as turn in points. On the F3 we use the rivets (right above the white steering wheel gadget).

I think I am good to go for this project. Thanks again for your ideas and follow through!