PureB app with completely transparent rectangle on its gui?

Just starting out? Need help? Post your questions and find answers here.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

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

Post 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
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

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

Post 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?
BERESHEIT
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

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

Post 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).
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4995
Joined: Sun Apr 12, 2009 6:27 am

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

Post 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
Egypt my love
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

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

Post 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.
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Post Reply