Page 1 of 1

Transparent BackGround Editor Gadget (Windows)

Posted: Mon May 16, 2011 7:57 pm
by RASHAD
Tested with PB 4.51 x86\x64 [Win 7 x64 - XP SP2 x86]

Code: Select all

If OpenWindow(0, 0, 0, 400, 300, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   HideWindow(0,1)
   OpenWindow(1, 0, 0,395, 200, "Transparent",#PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget |#PB_Window_ScreenCentered)
   SetParent_(WindowID(0),WindowID(1))
   
    EditorGadget(0, 10, 10, 375, 120)
    For a = 0 To 5
      AddGadgetItem(0, a, "Line "+Str(a))
    Next
    SetGadgetColor(0, #PB_Gadget_BackColor,$FFFFFE)
   
    SetWindowLong_(WindowID(1),#GWL_EXSTYLE,GetWindowLong_(WindowID(1),#GWL_EXSTYLE)|#WS_EX_LAYERED)
    SetLayeredWindowAttributes_(WindowID(1),$FFFFFE,0,#LWA_COLORKEY)

    SetActiveWindow(1)
    SetActiveGadget(0)
     
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf


Re: Transparent BackGround Editor Gadget (Windows)

Posted: Mon May 16, 2011 8:02 pm
by rsts
Nice :D

cheers

Re: Transparent BackGround Editor Gadget (Windows)

Posted: Mon May 16, 2011 11:11 pm
by Nituvious
Here is a similar function I posted earlier today in an old topic( :oops: ) that may be useful for those interested in this kind of thing, so that they may expand upon it.

Rashad, have you tried SetWindowLongPtr() on windows XP? If so, does it work as it's supposed to?

(thread here)

Code: Select all

;IncludeFile "C:\code\pb\include\WinAPI.pbi"
Declare OpenTransparentWindow(transColor.l, x.l, y.l, width.l, height.l, title.s, flag.l)

window = OpenTransparentWindow(RGB(255,254,253), 0, 0, 400, 400, "Invisible string gadget background", #PB_Window_SystemMenu)
StringGadget(0, 5, 5, 105, 23, "Test contents")
font = LoadFont(#PB_Any, "Arial", 12)
SetGadgetFont(0, FontID(font))
SetGadgetColor(0, #PB_Gadget_BackColor, RGB( 255,254, 253))
SetGadgetColor(0, #PB_Gadget_FrontColor, RGB( 255, 255, 255))

SetWindowColor(window, RGB(200,200,200))
HideWindow(window, 0)

While Not eventID = #PB_Event_CloseWindow
   eventID = WaitWindowEvent(1)
   Delay(10)
Wend




Procedure OpenTransparentWindow(transColor.l, x.l, y.l, width.l, height.l, title.s, flag.l) ;-- Create an invisible, borderless, and transparent window
   ; HideWindow(winResult, 0) after gadgets have been placed. Otherwise you may see flicker.
   ; I do not know if this works on all versions of windows or just Vista / 7
   ; I have only tested on both x86 and x64 Windows 7

   winResult = OpenWindow(#PB_Any, 1, 1, 1, 1, title.s, #PB_Window_Invisible | flag.l)
   SetWindowColor(winResult,transColor)

   SetWindowLongPtr_(WindowID(winResult),#GWL_EXSTYLE,  #WS_EX_LAYERED)  ; -- According to the MSDN, this function will work with both x86 and x64 ( http://msdn.microsoft.com/en-us/library/ms644898(v=VS.85).aspx )
   SetWindowPos_(WindowID(winResult),#Null, x, y, width, height, #Null) ; -- Must redraw window, according to the MSDN

   SetLayeredWindowAttributes_(WindowID(winResult),transColor,#Null,#LWA_COLORKEY)

   ProcedureReturn winResult

EndProcedure

Re: Transparent BackGround Editor Gadget (Windows)

Posted: Mon May 16, 2011 11:34 pm
by Foz
Interesting, with these techniques you can click through the form to the app below!

That would be most annoying when trying to select your position with the mouse...

Re: Transparent BackGround Editor Gadget (Windows)

Posted: Tue May 17, 2011 6:48 am
by RASHAD
@rsts
Thanks

@Nituvious
We are using the same tech.
Good snippet Nitu

@Foz
The next snippet unfortunately is for plain editor only
But it may be for some use

Code: Select all

Result = LoadImage(0, "girl2.bmp")
hBrush = CreatePatternBrush_(ImageID(0))

Global HwndEditText

Procedure.i WinProc(hwnd, msg, wparam, lparam)
  Select msg
 
    Case #WM_CTLCOLOREDIT
      SetBkMode_(wparam,#TRANSPARENT)
      SetTextColor_(wparam,#Black)
       SetClassLong_(WindowID(0),#GCL_HBRBACKGROUND,hBrush)     
      ProcedureReturn hBrush
      

  EndSelect

  ProcedureReturn #PB_ProcessPureBasicEvents

EndProcedure

OpenWindow(0,0,0,300,200,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
SetClassLong_(WindowID(0),#GCL_HBRBACKGROUND,hBrush)
InvalidateRect_(WindowID(0),0,1)

SetWindowCallback(@WinProc(),0)
  hInstance = GetModuleHandle_(0) 
  HwndEditText  = CreateWindowEx_(#WS_EX_STATICEDGE,"EDIT","", #WS_VISIBLE | #WS_CHILDWINDOW |  #ES_MULTILINE | #ES_WANTRETURN |#ES_NOHIDESEL, 10,10,280,120,WindowID(0),200,hInstance,0)
  SendMessage_(HwndEditText,#EM_REPLACESEL,0,"Hello")
  
  Repeat

  Until WaitWindowEvent()=#WM_CLOSE 


Re: Transparent BackGround Editor Gadget (Windows)

Posted: Tue May 17, 2011 1:12 pm
by Kwai chang caine
Thanks for sharing RASHAD 8)