Page 1 of 1

PureB app with completely transparent rectangle on its gui?

Posted: Fri Jan 08, 2010 12:20 am
by dell_jockey
Hi Group,

for a new project, I'd like to write a PB app that contains a rectangle that is completely transparent, i.e. it needs to show the desktop (or any other app) behind it.
Can someone please point me to documentation on how to do that? I haven't been succesful with searching MSDN...

Thanks!

Re: PureB app with completely transparent rectangle on its gui?

Posted: Fri Jan 08, 2010 12:23 am
by Rook Zimbabwe
One assumes you have explored #PB_Window_Hidden :?:

I did try somethig like this once... a frameless window with a transparent image as its overlay and no other controls...

I did it to play a joke on a buddy... no matter where he clicked on the window his computer would only throw random popups full of insults at him...

Ahhh VB5... thems was the days! :twisted:

there was this idea:
http://www.purebasic.fr/english/viewtop ... ow#p309567

Re: PureB app with completely transparent rectangle on its gui?

Posted: Fri Jan 08, 2010 12:37 am
by dell_jockey
Hi Rook,

what I'm after is to write an app that has some buttons and other controls, and that also has a rectangle on its gui that is completely transparent - the idea being to have an already existing app running 'behind' it on the exact screen location of the transparent rectangle that my app would sport. Conclusion: only a self-defined rectangular region should be transparent, but the rest should be a 'normal' gui with normal controls/gadgets, etc.

Re: PureB app with completely transparent rectangle on its gui?

Posted: Fri Jan 08, 2010 1:34 am
by Kaeru Gaman
when you know the app you want to have "behind but visible thru a transparent region",
you could perhaps also embed this second app into a container at this location?
... I'm just wondering what the idea is about...

Re: PureB app with completely transparent rectangle on its gui?

Posted: Fri Jan 08, 2010 1:59 am
by srod
For Win 2000 onwards you can use a layered window :

Code: Select all

Procedure SetWinTransparency(hwnd) 
  SetWindowLong_(hwnd, #GWL_EXSTYLE, #WS_EX_LAYERED) 
  SetLayeredWindowAttributes_(hwnd, #Blue, 0, 1) 
EndProcedure 

hwnd=OpenWindow(0,0,0,400,400,"",#PB_Window_SystemMenu |#PB_Window_ScreenCentered|#PB_Window_Invisible) 
ContainerGadget(1, 150, 150, 100, 100, #PB_Container_BorderLess)
CloseGadgetList()
SetWinTransparency(hwnd) 
SetGadgetColor(1, #PB_Gadget_BackColor, #Blue)
HideWindow(0, 0)
Repeat 
Until WaitWindowEvent() = #PB_Event_CloseWindow 
End 
With this example, all blue regions will be transparent. Switch this for a color which you know will not pop up anywhere else on your window.

Another way is to use a window region, but this is really only suitable for a window without a title bar.

Re: PureB app with completely transparent rectangle on its gui?

Posted: Fri Jan 08, 2010 3:16 am
by netmaestro
Another way, though with using a window region you don't get a themed caption and you can never put gadgets in the transparent part(s):

Code: Select all

OpenWindow(0,0,0,800,600,"My Holey Window",#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget)
GetWindowRect_(WindowID(0), wr.RECT)
w = wr\right-wr\left
h = wr\bottom-wr\top

hRgn1 = CreateRectRgn_(0,0,w,h)
hRgn2 = CreateRectRgn_(50,50,256,256)
hRgn3 = CreateEllipticRgn_(300,100,700,500)
CombineRgn_(hRgn1, hRgn2, hRgn1,#RGN_XOR)
CombineRgn_(hRgn1, hRgn3, hRgn1,#RGN_XOR)
SetWindowRgn_(WindowID(0),hRgn1,1)

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

Re: PureB app with completely transparent rectangle on its gui?

Posted: Fri Jan 08, 2010 10:26 am
by dell_jockey
Kaeru Gaman wrote:when you know the app you want to have "behind but visible thru a transparent region",
you could perhaps also embed this second app into a container at this location?
... I'm just wondering what the idea is about...
Hi Kaeru,

the app 'behind the scenes' is an executable, for which I don't have access to the source. 'Embedding into a container' in this case would mean to embed an external executable. Is this possible at all? Through udp (and/or DDE) there exists a protocol with which some limited control of the external app would be possible.

The basic idea: create some sort of 'remote control' software within which to display/run an external app and use either DDE or UDP to control that external app.

Re: PureB app with completely transparent rectangle on its gui?

Posted: Fri Jan 08, 2010 10:35 am
by dell_jockey
netmaestro wrote:Another way, though with using a window region you don't get a themed caption and you can never put gadgets in the transparent part(s):

Code: Select all

OpenWindow(0,0,0,800,600,"My Holey Window",#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget)
GetWindowRect_(WindowID(0), wr.RECT)
w = wr\right-wr\left
h = wr\bottom-wr\top

hRgn1 = CreateRectRgn_(0,0,w,h)
hRgn2 = CreateRectRgn_(50,50,256,256)
hRgn3 = CreateEllipticRgn_(300,100,700,500)
CombineRgn_(hRgn1, hRgn2, hRgn1,#RGN_XOR)
CombineRgn_(hRgn1, hRgn3, hRgn1,#RGN_XOR)
SetWindowRgn_(WindowID(0),hRgn1,1)

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

Hi srod, hi netmaestro

thanks a lot for both of your contributions! Much appreciated.

Unfortunately I have no control over the colours that might appear on the background, so srod's layered window solution might be best.
The thing I like about netmaestro's solution is that the background visible within the 'hole' is updated while scrolling/moving the window, so the impression is much smoother.
I guess I need to put in some effort to find a way to get that same smooth background updating when using the layered window solution...;)

thanks again!

Re: PureB app with completely transparent rectangle on its gui?

Posted: Fri Jan 08, 2010 10:56 am
by Trond
You know this is really simple. Just create four windows around a hole:

Code: Select all

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbb                 dddddddd
bbbbbbb                 dddddddd
bbbbbbb                 dddddddd
bbbbbbb                 dddddddd
bbbbbbb                 dddddddd
bbbbbbb                 dddddddd
cccccccccccccccccccccccccccccccc
cccccccccccccccccccccccccccccccc
cccccccccccccccccccccccccccccccc
cccccccccccccccccccccccccccccccc
a = window 1
b = window 2
c = window 3
d = window 4
space = other program

Also there is a nice function SetParent_() that you can use to put your other program inside your window.

Re: PureB app with completely transparent rectangle on its gui?

Posted: Fri Jan 08, 2010 12:32 pm
by gnozal
dell_jockey wrote:what I'm after is to write an app that has some buttons and other controls, and that also has a rectangle on its gui that is completely transparent - the idea being to have an already existing app running 'behind' it on the exact screen location of the transparent rectangle that my app would sport.
Why not embed the external app window in a static gadget ?
Below a quick and dirty code to embed the windows calculator.

Code: Select all

Enumeration
  #Window_0
EndEnumeration
Enumeration
  #Container_0
  #Button_1
  #Button_2
  #Button_3
  #Button_4
EndEnumeration
Procedure OpenWindow_Window_0()
  If OpenWindow(#Window_0, 486, 213, 400, 400, "Embedded Windows Calculator", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
    ButtonGadget(#Button_1, 44, 365, 100, 28, "1")
    ButtonGadget(#Button_2, 268, 365, 93, 28, "2")
    ButtonGadget(#Button_3, 12, 185, 20, 64, "3")
    ButtonGadget(#Button_4, 374, 191, 19, 62, "4")
    ImageGadget(#Container_0, 74, 60, 246, 226, #Null)
    HideGadget(#Container_0, #True)
  CloseGadgetList()
EndIf
EndProcedure
OpenWindow_Window_0()

MyCalc = RunProgram("calc.exe","","",#PB_Program_Hide | #PB_Program_Open)
If MyCalc
  While hMyCalc = #Null
    hMyCalc = FindWindow_(@"SciCalc", 0)
  Wend
EndIf
GetWindowRect_(hMyCalc, @RectMyCalc.RECT)
SetParent_(hMyCalc, GadgetID(#Container_0))
ShowWindow_(hMyCalc, #SW_SHOWMAXIMIZED)
; hide external window caption and borders
MoveWindow_(hMyCalc, - GetSystemMetrics_(#SM_CYFRAME), - GetSystemMetrics_(#SM_CYCAPTION) - GetSystemMetrics_(#SM_CYFRAME), RectMyCalc\bottom - RectMyCalc\top, RectMyCalc\right - RectMyCalc\left, #True)
; one could also resize the container according to the external window dimensions
HideGadget(#Container_0, #False)

Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = #Window_0
        If MyCalc
          KillProgram(MyCalc)
          CloseProgram(MyCalc)
        EndIf
        CloseWindow(#Window_0)
        Break
      EndIf
  EndSelect
ForEver

Re: PureB app with completely transparent rectangle on its gui?

Posted: Fri Jan 08, 2010 12:54 pm
by netmaestro
@gnozal: Just hangs on Win7. Also, on other OS's, there is a basic problem with using SetParent_() to embed an app into another: toplevel windows are the only ones which can have a menu, so what happens when you force it to a childwindow with SetParent?

Re: PureB app with completely transparent rectangle on its gui?

Posted: Fri Jan 08, 2010 1:18 pm
by gnozal
netmaestro wrote:@gnozal: Just hangs on Win7. Also, on other OS's, there is a basic problem with using SetParent_() to embed an app into another: toplevel windows are the only ones which can have a menu, so what happens when you force it to a childwindow with SetParent?
I don't have Win7, maybe it hangs because it can't find the calculator (different class name ?) : quick coding, not tested.
The menus seem to work.
I embed jaPBe in PureFORM using this technique (se7en not tested).

Re: PureB app with completely transparent rectangle on its gui?

Posted: Fri Jan 08, 2010 2:44 pm
by RASHAD
dell_jockey hi
I feel that I do't get your point clear after srod,NM and gnozal feedback
But here is my trial may be it will suit you

Code: Select all

CreateImage(0, 256,128, #PB_Image_DisplayFormat)
StartDrawing(ImageOutput(0))
  Box(0,0,256,128,#Blue)
  DrawingMode(#PB_2DDrawing_Outlined)
  Box(0,0,256,128,RGB(0, 0, 0))
StopDrawing()

hWin=OpenWindow(0, 0, 0,640,480, "Window_0",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
hMenu.i = CreateMenu(#PB_Any, hWin)

MenuTitle("MenuChoice")
    OpenSubMenu("SubChoice")
        MenuItem(0101, "Choice1")
        MenuBar()
        MenuItem(0111, "Choice2")
        MenuItem(0112, "Choice3")
        MenuItem(0113, "Choice4")
        MenuItem(0114, "Choice5")
        MenuBar()
        MenuItem(0121, "Choice6")
        MenuItem(0122, "Choice7")
        MenuItem(0123, "Choice8")
        MenuItem(0124, "Choice9")
    CloseSubMenu()

      ButtonGadget(1,10,430,120,20,"TEST 1")
      ButtonGadget(2,510,430,120,20,"TEST 2")
      SetWindowLong_(WindowID(0),#GWL_EXSTYLE,#WS_EX_LAYERED)
      SetLayeredWindowAttributes_(WindowID(0),#Blue,0,#LWA_COLORKEY)
      ImageGadget(0,200,20,256,128,ImageID(0))

    Repeat
       EventID = WaitWindowEvent()
       
       Select EventID

        Case #PB_Event_Gadget
       
         Select EventGadget()
         
               Case 1
                MessageRequester("","Button 1 is pressed")

               Case 2
                MessageRequester("","Button 2 is pressed")
                   
         EndSelect
         
              Case #PB_Event_CloseWindow
              Quit = 1
              
            
      EndSelect
         
    Until Quit = 1
    End
Another view

Code: Select all


InitMovie()

Procedure WndProc(hwnd, uMsg, wParam, lParam)

      GetWindowRect_(WindowID(0),R.RECT)
      result = #PB_ProcessPureBasicEvents 

 Select uMsg   
      
        Case #WM_SIZE,#WM_MOVE,#WM_PAINT
          MoveWindow_(WindowID(1),r\left+3,r\top+25, 640, 480,1) 
             
   EndSelect
   
  ProcedureReturn result 
EndProcedure

CreateImage(0, 256,128, #PB_Image_DisplayFormat)
StartDrawing(ImageOutput(0))
  Box(0,0,256,128,#Blue)
  DrawingMode(#PB_2DDrawing_Outlined)
  Box(0,0,256,128,RGB(0, 0, 0))
StopDrawing()

hWin=OpenWindow(0, 0, 0,640,480, "Window_0",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
GetWindowRect_(hWin,r.RECT)

hW = OpenWindow(1,r\left+3,r\top+25, 640, 480, "test",#PB_Window_BorderLess|#WS_POPUP,WindowID(0))
hMenu.i = CreateMenu(#PB_Any, hW)

MenuTitle("MenuChoice")
    OpenSubMenu("SubChoice")
        MenuItem(0101, "Choice1")
        MenuBar()
        MenuItem(0111, "Choice2")
        MenuItem(0112, "Choice3")
        MenuItem(0113, "Choice4")
        MenuItem(0114, "Choice5")
        MenuBar()
        MenuItem(0121, "Choice6")
        MenuItem(0122, "Choice7")
        MenuItem(0123, "Choice8")
        MenuItem(0124, "Choice9")
    CloseSubMenu()

      ButtonGadget(1,10,430,120,20,"TEST 1")
      ButtonGadget(2,510,430,120,20,"TEST 2")
      SetWindowLong_(WindowID(1),#GWL_EXSTYLE,#WS_EX_LAYERED)
      SetLayeredWindowAttributes_(WindowID(1),#Blue,0,#LWA_COLORKEY)
      ImageGadget(0,200,20,256,128,ImageID(0))
      SetWindowCallback(@WndProc(),0)

    Repeat
       SetActiveWindow(1)
       EventID = WaitWindowEvent()
       
       Select EventID

        Case #PB_Event_Gadget
       
         Select EventGadget()
         
               Case 1
               LoadMovie(0,"g:\wanted.avi")
               PlayMovie(0,WindowID(0))

               Case 2
               MessageRequester("","Button 2 is pressed")
                   
         EndSelect
         
              Case #PB_Event_CloseWindow
              Quit = 1
              
            
      EndSelect
         
    Until Quit = 1
    End

Re: PureB app with completely transparent rectangle on its gui?

Posted: Fri Jan 08, 2010 7:05 pm
by dell_jockey
so many options to wade through this weekend. Thanks a a lot to all of you!

Rashad: your first listing seems to fit the bill rather well. Have to check it out more thoroughly though.