Página 1 de 1

Prender janela console/GUI dentro de janela GUI

Enviado: 05 Dez 2021 09:41
por dbsh
Testado com QT 4.8.7, deve funcionar na 5
Acredito de deva funcionar com outras GUI
Se faltar alguma função, ou duvidas, na medida do possível estou a disposição.

OBS:
Crie as janelas da forma que você sempre criou depois execute:
windows api ...

Código: Selecionar todos


#command WINDOWS API <dll: USER, KERNEL, ADVAPI> <f> PARAMETRO <list,...> [TO <var>] => ;
   [var> := ]wapi_32( #<dll>, <(f)>[, <list>])

//windows api user SetParent parametro WinId(), WinId(QMainWindowGet():MdiArea)
windows api user SetParent parametro WinId(), WinId(QMainWindowGet())

/*
User = DLL Windows
SetParent = Method/Propriedade/Funcao da DLL
WinId = Parametro para "SetParent"
*/

FUNCTION wapi_32( nDll, sFuncao, ... )
LOCAL hHandleDll, uVar, sDll

DO CASE
CASE ValType( nDll ) = "C"
    sDll := nDll
    IF !'.DLL' $ Upper(sDll)
       IF Right(sDll, 2) = '32'
          sDll += '.dll'
       ELSE
          sDll += '32.dll'
       ENDIF
    ENDIF
CASE nDll == WAPI_USER32
    sDll := "user32.dll"
CASE nDll == WAPI_KERNEL32
    sDll := "kernel32.dll"
CASE nDll == WAPI_ADVAPI32
    sDll := "advapi32.dll"
OTHERWISE
    sDll := ''
ENDCASE

IF Empty( sDll )
   RETURN NIL
ENDIF

hHandleDll := hb_LibLoad( sDll )
uVar := hb_DynCall( { sFuncao, hHandleDll, HB_DYN_CALLCONV_STDCALL }, ... )
hb_LibFree( hHandleDll )

RETURN uVar


FUNCTION WinId( uId )
LOCAL nId

IF ValType(uId) = 'O'
   IF __ObjhasData(uId, 'WINID') .or. __ObjhasMsg(uId, 'WINID')
      nId := uId:WinId()
   ELSEIF __ObjhasData(uId, 'HWND') .or. __ObjhasMsg(uId, 'HWND')
      nId := uId:hWnd()
   ELSE
      nId := 0
   ENDIF
ELSEIF Empty( uId )
   nId := Wvt_GetWindowHandle()
ELSEIF ValType(uId) = 'N'
   nId := uId
ENDIF

RETURN nId

FUNCTION ConsoleWinPoint( nHandle )
LOCAL pWnd

DEFA nHandle TO WinId()

pWnd := win_N2P( nHandle )

RETURN pWnd


FUNCTION QAppGet( lExclui )
STATIC oApp
LOCAL oFont

IF !Empty( lExclui )
   oApp := NIL
   RETURN NIL
ENDIF

IF oApp = NIL
    oApp := QApplication()
    //oApp:InstallEventFilter( QObject() )

    addVar(oApp, 'Licenciado', clsVar())
    oApp:Licenciado:AddVar('RazaoSocial', 'Demonstracao')
    oApp:Licenciado:AddVar( 'Fantasia', 'Demonstracao')
    oApp:Licenciado:AddVar( 'CNPJ', '99.999.999/9999-99')
/*
    nFont := Val(IniRead('Fonte', 'App', '0'))
    IF Empty(nFont) .or. nFont > 72
      nFont := Int(oApp:DeskTop():availableGeometry():Width / 128)
      IF nFont > Int(oApp:DeskTop():availableGeometry():Height / 50)
        nFont := (oApp:DeskTop():availableGeometry():Height / 50)
      ENDIF
      IF nFont > 72
          nFont := 72
      ENDIF
      IF nFont < 6
          nFont := 6
      ENDIF
    ENDIF
*/
    oFont := QFont( _FONTE_FAMILY_ )
    oApp:SetFont( oFont )
ENDIF

RETURN oApp

FUNCTION QMainWindowGet( oMain )
STATIC oMainWindow := NIL

IF !Empty( oMain )
    oMainWindow := oMain
ELSEIF oMainWindow = NIL
   oMainWindow:= QMainWindow():New( QAppGet() )

/*
   oMainWindow:GT := 'QT'
   oMainWindow:Janelas := {}
   oMainWindow:MdiArea := QMdiArea(oMainWindow)
   oMainWindow:MdiArea:setStyleSheet("background:transparent;")
   oMainWindow:MdiArea:setAttribute(Qt_WA_TranslucentBackground)
   oMainWindow:MdiArea:SetBackground(QBrush(Qt_transparent))
   oMainWindow:MdiArea:SetHorizontalScrollBarPolicy(Qt_ScrollBarAsNeeded) //Qt_ScrollBarAsNeeded, Qt_ScrollBarAlwaysOff, Qt_ScrollBarAlwaysOn
   oMainWindow:MdiArea:SetVerticalScrollBarPolicy(Qt_ScrollBarAsNeeded)
   oMainWindow:MdiArea:setTabsClosable(.T.)
   oMainWindow:MdiArea:settabsMovable(.T.)
   oMainWindow:setCentralWidget(oMainWindow:MdiArea)
   //oMainWindow:MdiArea:SubWindowView()  // setViewMode(0) Exibir sub-janelas com caixilhos de janelas (padrão).
   //oMainWindow:MdiArea:TabbedView()     // setViewMode(1) Exibir sub-janelas com guias em uma barra de abas.
   oMainWindow:MdiArea:setViewMode(0)
   oMainWindow:_Done := 0
   oMainWindow:ShowMaximized()
   //QMainWindow.iconSize ( self )
   //QMainWindow.createPopupMenu ( self )
   //QMainWindow.tabPosition ( self , área Qt.DockWidgetArea  )
   //QMainWindow.setTabPosition ( self , Qt.DockWidgetAreas  areas , QTabWidget.TabPosition  tabPosition )
*/

ENDIF

RETURN oMainWindow