Transparent Window with text

Just starting out? Need help? Post your questions and find answers here.
Learner
User
User
Posts: 15
Joined: Tue Dec 14, 2004 1:32 am
Location: Australia

Transparent Window with text

Post by Learner »

I am trying to make a window with no borders and text only that will stay on top. Something like a timer that will sit at the top window bar. Have been playing with this code to try to create a transparent background to write on without success. Can anyone help? thanks..

Code: Select all

Procedure WinTransParentRegion(win,width,height)
  outterRgn  = CreateRectRgn_(0, 0, width, height) 
  innerRgn = CreateRectRgn_(0, 0, width, height) 
  winRgn = outterRgn 
  CombineRgn_(winRgn, outterRgn, innerRgn, #RGN_XOR) 
  SetWindowRgn_(WindowID(win), winRgn, 1) 
  DeleteObject_(outterRgn) 
  DeleteObject_(innerRgn) 
EndProcedure  

OpenWindow(3,0,0,50,50,"HiddenWindow",#PB_Window_Invisible) 
hWnd2=OpenWindow(1, textPos, 0, 105, 20 , "",#PB_Window_BorderLess,WindowID(3)) 

SetWindowLong_(WindowID(1),#GWL_EXSTYLE,GetWindowLong_(WindowID(1),#GWL_EXSTYLE)|#WS_EX_LAYERED|#WS_EX_TOOLWINDOW)  
WinTransParentRegion(1,105,1)
StartDrawing(WindowOutput(1)) 
    ;Locate(169,0)
    ;DrawingFont(UseFont(2))
    oldtime=Date()-StartTime
    time=ResultDate-StartTime
    DrawText(0,0," Active "+FormatDate("%hh:%ii:%ss",time )+"  ")
StopDrawing() 
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Looks like you have created an empty region there!

Not sure you need a region though - try this :

Code: Select all

width = 120
height = 20
hWnd=OpenWindow(1, 0, 0, width, height, "",#PB_Window_BorderLess|#PB_Window_ScreenCentered) 
SetWindowColor(1, #White)
SetWindowLong_(hWnd,#GWL_EXSTYLE,GetWindowLong_(hWnd,#GWL_EXSTYLE)|#WS_EX_LAYERED|#WS_EX_TOOLWINDOW)  
SetLayeredWindowAttributes_(hWnd, #White, 0, #LWA_COLORKEY) 

SetTimer_(hWnd, 100, 500, 0)
Repeat
  eventID = WaitWindowEvent()
  Select eventID
    Case #WM_TIMER
      If EventwParam() = 100
        hdc = StartDrawing(WindowOutput(1)) 
        If hdc
          Box(0, 0, width, height, #White)
          SetBkMode_(hdc, #TRANSPARENT)
          DrawText(0,0," Active "+FormatDate("%hh:%ii:%ss",Date())+"  ") 
          StopDrawing() 
        EndIf
      EndIf
  EndSelect
 
Until eventID = #PB_Event_CloseWindow
I may look like a mule, but I'm not a complete ass.
Learner
User
User
Posts: 15
Joined: Tue Dec 14, 2004 1:32 am
Location: Australia

Transparent Window with text

Post by Learner »

Ok thanks alot. This this what Ive got so far and seems to pretty much do what I want.

Code: Select all

ExamineDesktops() 
textPos=DesktopWidth(0)/2
width = 120
height = 20

; Open Window that doesnt show on taskbar
OpenWindow(3,0,0,0, 0,"HiddenWindow",#PB_Window_Invisible) 
hWnd2=OpenWindow(1, textPos, 0, width, height, "",#PB_Window_BorderLess,WindowID(3))
If hWnd2=0
  MessageRequester("Critical Error", "Can't Open Timer Window") 
  End
EndIf
SetWindowColor(1, #White)

; make window background transparent ?
SetWindowLong_(hWnd2,#GWL_EXSTYLE,GetWindowLong_(hWnd2,#GWL_EXSTYLE)|#WS_EX_LAYERED|#WS_EX_TOOLWINDOW) 
SetLayeredWindowAttributes_(hWnd2, #White, 0, #LWA_COLORKEY)

StickyWindow(1,1)
StartTime=Date()

SetTimer_(hWnd2, 100, 500, 0)
Repeat
  EventID = WaitWindowEvent()
  Select EventID
    Case #WM_TIMER
      If EventwParam() = 100
        hdc = StartDrawing(WindowOutput(1))
          If hdc
            ;Box(0, 0, width, height, #White)
            ;SetBkMode_(hdc, #TRANSPARENT)
            time=Date()-StartTime
            DrawText(0,0," Active "+FormatDate("%hh:%ii:%ss",time )+"  ")
          StopDrawing()
        EndIf
      EndIf
  EndSelect
  
Until EventID = #PB_Event_CloseWindow 
Post Reply