Browser as app will not be child in a container

Just starting out? Need help? Post your questions and find answers here.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Browser as app will not be child in a container

Post by infratec »

Hi,

if I use --app, the SetParent_() call results in an error.
As 'normal' browser window it works, simply set #InAppMode to #False

Any idea how to bring the app window inside of the container?

Code: Select all

EnableExplicit

#User_Data_Dir = "c:\tmp\msedge"

#InAppMode = #True


Procedure.i CreateUserDataDir(Dir$)
  
  Protected Part$, i.i
  
  
  If Right(Dir$, 1) <> #PS$
    Dir$ + #PS$
  EndIf
  
  i = 1
  Repeat
    Part$ + StringField(Dir$, i, #PS$) + #PS$
    ;Debug Part$
    If Right(Part$, 2) <> ":" + #PS$
      If FileSize(Part$) <> -2
        If CreateDirectory(Part$) = 0
          Break
        EndIf
      EndIf
    EndIf
    i + 1
  Until Part$ = Dir$
  
  ProcedureReturn Bool(FileSize(Dir$) = -2)
  
EndProcedure


CreateUserDataDir(#User_Data_Dir)




Define.i hWnd, Prog, Event, Quit, TimeOut
Define Parameter$, WindowText$

OpenWindow(0, 0, 0, 1024, 768, "PureBasic Window", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)

ContainerGadget(0, 0, 0, WindowWidth(0), WindowHeight(0))
SetWindowLongPtr_(GadgetID(0), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(0), #GWL_EXSTYLE) | #WS_EX_CONTROLPARENT)

Parameter$ = "--user-data-dir=" + #DQUOTE$ + #User_Data_Dir + #DQUOTE$ + " "
 Parameter$ + "--window-position=" + #DQUOTE$ + "0,0" + #DQUOTE$ + " "
Parameter$ + "--window-size=" + #DQUOTE$ + Str(WindowWidth(0)) + "," + Str(WindowHeight(0)) + #DQUOTE$ + " "
CompilerIf #InAppMode = #True
  Parameter$ + "--app=https://www.purebasic.fr/english/"
CompilerElse
  Parameter$ + "--no-first-run "
  Parameter$ + "https://www.purebasic.fr/english/"
CompilerEndIf
Debug Parameter$

Prog = RunProgram("msedge", Parameter$, "");, #PB_Program_Hide)

TimeOut = ElapsedMilliseconds()
Repeat
  CompilerIf #InAppMode = #True
    hWnd = FindWindowEx_(#Null, hWnd, #Null, "PureBasic Forums - English - Index page")
  CompilerElse
    hWnd = FindWindowEx_(#Null, hWnd, #Null, "PureBasic Forums - English - Index page - Profil 1 – Microsoft​ Edge")
  CompilerEndIf
  
  If hWnd
    Debug hWnd
    
    WindowText$ = Space(#MAX_PATH)
    GetWindowText_(hWnd, @WindowText$, #MAX_PATH)
    Debug WindowText$
    
    Break
  Else
    Delay(100)
  EndIf
Until ElapsedMilliseconds() - TimeOut > 10000

If SetParent_(hWnd, GadgetID(0)) = 0
  Debug "SetParent() Error: " + Str(GetLastError_())
EndIf

Repeat
  Event = WaitWindowEvent()
  
  If Event = #PB_Event_CloseWindow  ; If the user has pressed on the close button
    Quit = #True
  EndIf
  
Until Quit
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Browser as app will not be child in a container

Post by chi »

You missed the 'e' in Profile and the dash between 1 and Microsoft is not Ascii 45 (but 8211)

Code: Select all

"PureBasic Forums - English - Index page - Profile 1 - Microsoft​ Edge"
Et cetera is my worst enemy
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Browser as app will not be child in a container

Post by RASHAD »

Hi infratec

Code: Select all

EnableExplicit

#User_Data_Dir = "c:\tmp\msedge"

#InAppMode = #True


Procedure.i CreateUserDataDir(Dir$)
  
  Protected Part$, i.i
  
  
  If Right(Dir$, 1) <> #PS$
    Dir$ + #PS$
  EndIf
  
  i = 1
  Repeat
    Part$ + StringField(Dir$, i, #PS$) + #PS$
    ;Debug Part$
    If Right(Part$, 2) <> ":" + #PS$
      If FileSize(Part$) <> -2
        If CreateDirectory(Part$) = 0
          Break
        EndIf
      EndIf
    EndIf
    i + 1
  Until Part$ = Dir$
  
  ProcedureReturn Bool(FileSize(Dir$) = -2)
  
EndProcedure


CreateUserDataDir(#User_Data_Dir)




Define.i hWnd, Prog, Event, Quit, TimeOut
Define Parameter$, WindowText$

OpenWindow(0, 0, 0, 1024, 768, "PureBasic Window", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)

ContainerGadget(0, 0, 0, WindowWidth(0), WindowHeight(0))
SetWindowLongPtr_(GadgetID(0), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(0), #GWL_EXSTYLE) | #WS_EX_CONTROLPARENT)

Parameter$ = "--user-data-dir=" + #DQUOTE$ + #User_Data_Dir + #DQUOTE$ + " "
 Parameter$ + "--window-position=" + #DQUOTE$ + "0,0" + #DQUOTE$ + " "
Parameter$ + "--window-size=" + #DQUOTE$ + Str(WindowWidth(0)) + "," + Str(WindowHeight(0)) + #DQUOTE$ + " "
CompilerIf #InAppMode = #True
  Parameter$ + "--app=https://www.purebasic.fr/english/"
CompilerElse
  Parameter$ + "--no-first-run "
  Parameter$ + "https://www.purebasic.fr/english/"
CompilerEndIf
Debug Parameter$

Prog = RunProgram("msedge", Parameter$, "", #PB_Program_Hide)

TimeOut = ElapsedMilliseconds()
Repeat
  CompilerIf #InAppMode = #True
    hWnd = FindWindowEx_(#Null, hWnd, #Null, "PureBasic Forums - English - Index page")
  CompilerElse
    hWnd = FindWindowEx_(#Null, hWnd, #Null, "PureBasic Forums - English - Index page - Profil 1 – Microsoft​ Edge")
  CompilerEndIf
  
  If hWnd
    Debug hWnd
    
    WindowText$ = Space(#MAX_PATH)
    GetWindowText_(hWnd, @WindowText$, #MAX_PATH)
    Debug WindowText$
    
    Break
  Else
    Delay(100)
  EndIf
Until ElapsedMilliseconds() - TimeOut > 10000

MoveWindow_(hWnd,0,0,GadgetWidth(0),GadgetHeight(0),1)
SetParent_(hWnd, GadgetID(0))
ShowWindow_(hwnd,#SW_SHOW	)

Repeat
  Event = WaitWindowEvent()
  
  If Event = #PB_Event_CloseWindow  ; If the user has pressed on the close button
    Quit = #True
  EndIf
  
Until Quit

Egypt my love
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Browser as app will not be child in a container

Post by infratec »

Hi RASHAD

I knew that you have a solution :D

But ... it's not exactly what I need.
This looks more like MDI. I want that the content of the browser window is inside of the container and not the whole window.

I tried:

Code: Select all

lStyle = GetWindowLong_(hWnd, #GWL_STYLE)
lStyle & ~(#WS_CAPTION | #WS_THICKFRAME | #WS_MINIMIZEBOX | #WS_MAXIMIZEBOX | #WS_SYSMENU)
SetWindowLong_(hWnd, #GWL_STYLE, lStyle)

SetWindowPos_(hWnd, #HWND_TOP, 0, 0, GadgetWidth(0), GadgetHeight(0), #SWP_FRAMECHANGED)

MoveWindow_(hWnd,0,0,GadgetWidth(0),GadgetHeight(0),1)
SetParent_(hWnd, GadgetID(0))

ShowWindow_(hwnd,#SW_SHOW	)
But no success :cry:
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Browser as app will not be child in a container

Post by RASHAD »

Hi infratec
I suggest using ScrollAreaGadget()
Now what you should do is using ScrollAreaGadget events and max & min scroll limits to get your requirements
That is if I understood you correctly :mrgreen:

Code: Select all

EnableExplicit

#User_Data_Dir = "c:\tmp\msedge"

#InAppMode = #True


Procedure.i CreateUserDataDir(Dir$)
  
  Protected Part$, i.i
  
  
  If Right(Dir$, 1) <> #PS$
    Dir$ + #PS$
  EndIf
  
  i = 1
  Repeat
    Part$ + StringField(Dir$, i, #PS$) + #PS$
    ;Debug Part$
    If Right(Part$, 2) <> ":" + #PS$
      If FileSize(Part$) <> -2
        If CreateDirectory(Part$) = 0
          Break
        EndIf
      EndIf
    EndIf
    i + 1
  Until Part$ = Dir$
  
  ProcedureReturn Bool(FileSize(Dir$) = -2)
  
EndProcedure


CreateUserDataDir(#User_Data_Dir)


Define.i hWnd, Prog, Event, Quit, TimeOut
Define Parameter$, WindowText$

OpenWindow(0, 0, 0, 1024, 768, "PureBasic Window", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)

ScrollAreaGadget(0, 0, 0, WindowWidth(0), WindowHeight(0),WindowWidth(0),2000)
CloseGadgetList()

;ContainerGadget(0, 0, 0, WindowWidth(0), WindowHeight(0))
;SetWindowLongPtr_(GadgetID(0), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(0), #GWL_EXSTYLE) | #WS_EX_CONTROLPARENT)

Parameter$ = "--user-data-dir=" + #DQUOTE$ + #User_Data_Dir + #DQUOTE$ + " "
 Parameter$ + "--window-position=" + #DQUOTE$ + "0,0" + #DQUOTE$ + " "
Parameter$ + "--window-size=" + #DQUOTE$ + Str(WindowWidth(0)) + "," + Str(WindowHeight(0)) + #DQUOTE$ + " "
CompilerIf #InAppMode = #True
  Parameter$ + "--app=https://www.purebasic.fr/english/"
CompilerElse
  Parameter$ + "--no-first-run "
  Parameter$ + "https://www.purebasic.fr/english/"
CompilerEndIf
Debug Parameter$

Prog = RunProgram("msedge", Parameter$, "", #PB_Program_Hide)

TimeOut = ElapsedMilliseconds()
Repeat
  CompilerIf #InAppMode = #True
    hWnd = FindWindowEx_(#Null, hWnd, #Null, "PureBasic Forums - English - Index page")
  CompilerElse
    hWnd = FindWindowEx_(#Null, hWnd, #Null, "PureBasic Forums - English - Index page - Profil 1 – Microsoft​ Edge")
  CompilerEndIf
  
  If hWnd
    Debug hWnd
    
    WindowText$ = Space(#MAX_PATH)
    GetWindowText_(hWnd, @WindowText$, #MAX_PATH)
    Debug WindowText$
    
    Break
  Else
    Delay(100)
  EndIf
Until ElapsedMilliseconds() - TimeOut > 10000

MoveWindow_(hWnd,-6,-140,GadgetWidth(0)+24,GadgetHeight(0)+140,1)
SetParent_(hWnd, GadgetID(0))
ShowWindow_(hwnd,#SW_SHOW	)

Repeat 
  Event = WaitWindowEvent()
  
  If Event = #PB_Event_CloseWindow  ; If the user has pressed on the close button
    Quit = #True
  EndIf
  
Until Quit

Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Browser as app will not be child in a container

Post by RASHAD »

One more try

Code: Select all

EnableExplicit

#User_Data_Dir = "c:\tmp\msedge"

#InAppMode = #True


Procedure.i CreateUserDataDir(Dir$)
  
  Protected Part$, i.i
  
  
  If Right(Dir$, 1) <> #PS$
    Dir$ + #PS$
  EndIf
  
  i = 1
  Repeat
    Part$ + StringField(Dir$, i, #PS$) + #PS$
    ;Debug Part$
    If Right(Part$, 2) <> ":" + #PS$
      If FileSize(Part$) <> -2
        If CreateDirectory(Part$) = 0
          Break
        EndIf
      EndIf
    EndIf
    i + 1
  Until Part$ = Dir$
  
  ProcedureReturn Bool(FileSize(Dir$) = -2)
  
EndProcedure


CreateUserDataDir(#User_Data_Dir)


Define.i hWnd, Prog, Event, Quit, TimeOut
Define Parameter$, WindowText$

OpenWindow(0, 0, 0, 1024, 768, "PureBasic Window", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)

ScrollAreaGadget(0, 0, 0, WindowWidth(0), WindowHeight(0),WindowWidth(0),1500,10)
  ContainerGadget(1,0, 0, WindowWidth(0), WindowHeight(0)+5000,#PB_Container_Flat)
  CloseGadgetList()
CloseGadgetList()

;ContainerGadget(0, 0, 0, WindowWidth(0), WindowHeight(0))
;SetWindowLongPtr_(GadgetID(0), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(0), #GWL_EXSTYLE) | #WS_EX_CONTROLPARENT)

Parameter$ = "--user-data-dir=" + #DQUOTE$ + #User_Data_Dir + #DQUOTE$ + " "
 Parameter$ + "--window-position=" + #DQUOTE$ + "0,0" + #DQUOTE$ + " "
Parameter$ + "--window-size=" + #DQUOTE$ + Str(WindowWidth(0)) + "," + Str(WindowHeight(0)) + #DQUOTE$ + " "
CompilerIf #InAppMode = #True
  Parameter$ + "--app=https://www.purebasic.fr/english/"
CompilerElse
  Parameter$ + "--no-first-run "
  Parameter$ + "https://www.purebasic.fr/english/"
CompilerEndIf
Debug Parameter$

Prog = RunProgram("msedge", Parameter$, "", #PB_Program_Hide)

TimeOut = ElapsedMilliseconds()
Repeat
  CompilerIf #InAppMode = #True
    hWnd = FindWindowEx_(#Null, hWnd, #Null, "PureBasic Forums - English - Index page")
  CompilerElse
    hWnd = FindWindowEx_(#Null, hWnd, #Null, "PureBasic Forums - English - Index page - Profil 1 – Microsoft​ Edge")
  CompilerEndIf
  
  If hWnd
    Debug hWnd
    
    WindowText$ = Space(#MAX_PATH)
    GetWindowText_(hWnd, @WindowText$, #MAX_PATH)
    Debug WindowText$
    
    Break
  Else
    Delay(100)
  EndIf
Until ElapsedMilliseconds() - TimeOut > 10000

MoveWindow_(hWnd,-6,-140,GadgetWidth(1)+24,GadgetHeight(1)+500,1)
SetParent_(hWnd, GadgetID(1))
ShowWindow_(hwnd,#SW_SHOW	)

Repeat 
  Event = WaitWindowEvent()
  
  If Event = #PB_Event_CloseWindow  ; If the user has pressed on the close button
    Quit = #True
  EndIf
  
Until Quit


Egypt my love
User avatar
idle
Always Here
Always Here
Posts: 5040
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Browser as app will not be child in a container

Post by idle »

this command line reference might be useful
https://peter.sh/experiments/chromium-c ... -switches/

note you can also lock up the tmp directory is something goes wrong.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Browser as app will not be child in a container

Post by infratec »

@idle

I knew this page already, but unfortunately it is more aor less a 'try and error'.
because if you use --kiosk most of the parameters are meaningless.
Same if you use --app

You have to findout what is working and whats not.

@RASHAD

what a bad hack :wink:
To move the borders out of the visible area.
Now I have to find a crossplatform way to detect all metrics of the borders.
Btw. ContainerGadget() was the right way.
firace
Addict
Addict
Posts: 899
Joined: Wed Nov 09, 2011 8:58 am

Re: Browser as app will not be child in a container

Post by firace »

Give this a try (quick and dirty Windows code, based on an old Kiffi post I believe)

Code: Select all

Global GoogleFound

externalCommand.s =  "C:\'Program Files (x86)'\Microsoft\Edge\Application\msedge.exe '--chrome-frame --user-data-dir=%TEMP%\tt_chromekioskZZ  --start-minimized  --app=https://en.wikipedia.org/wiki/Main_Page'" 
externalCommand = ReplaceString(externalCommand,"'",Chr(34))


Procedure EnumWindows(hWnd,Visibility=#True) ;Prozedur, die die Handles der Fenster erhält
  Static title.s{1024},class.s{1024},PID.l=0
  
  GetWindowText_(hWnd,@title,1024) ;Fenstertitel auslesen
  GetClassName_(hWnd,@class,1024)  ;Fensterklasse auslesen
  GetWindowThreadProcessId_(hWnd,@PID) ;PID des Prozesses
  
  If  title = "Wikipedia, the free encyclopedia"
    
    SetParent_(hWnd, GadgetID(1))
    SetWindowPos_(hWnd, 0, 0, 0, WindowWidth(0), WindowHeight(0), #SWP_NOZORDER | #SWP_FRAMECHANGED)
    Region = CreateRectRgn_(20, 90, 760, 330 ) : SetWindowRgn_(hWnd, Region, #True)
    GoogleFound = #True
    
  EndIf
  
  ProcedureReturn #True
EndProcedure

OpenWindow(0, 0, 0, 800, 390, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ContainerGadget(1, 0, -80, WindowWidth(0), 390, 0)

RunProgram(   "cmd", "/c "  + externalCommand, "", #PB_Program_Hide)  

Repeat
  EnumWindows_(@EnumWindows(),#True)     
  
  If GoogleFound
    Break 
  EndIf
  
  Delay(50)
ForEver

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
Post Reply