FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Ajustar tamaΓ±o caja toast
Posts: 1816
Joined: Wed Oct 26, 2005 02:49 PM
Ajustar tamaΓ±o caja toast
Posted: Fri Feb 07, 2025 11:11 PM
Hola buenas tardes para todos, queremos poder cambiar el tamaΓ±o de la caja del toast, pero parece que viene definido por defecto, ya busque el cΓ³digo fuente, pero no logro encontrarlo.


cRutaLgo := CurDrive()+":\"+CurDir()+"\loguito.bmp"
Toast( "CONFIRMACION DE PROCESO", "Documento nomina radicado correctamente DIAN","HymLyma | Digital Products ",cRutaLgo )
De paso aprovechamos para preguntar, si se puede colocar algΓΊn botΓ³n o enlace, que ejecute una acciΓ³n dentro de nuestra aplicaciΓ³n.
Saludos
LEANDRO AREVALO
BogotΓ‘ (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 25.01 ] [ xHarbour 64 bits) ]
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Ajustar tamaΓ±o caja toast
Posted: Sat Feb 08, 2025 09:41 AM
Estimado Leandro,

La funciΓ³n Toast() usa funciones propias de WinRT basado en Windows.UI y no es nada estandard ni fΓ‘cil de modificar.

Te adjunto aqui todo el cΓ³digo por si quieres revisarlo. He consultado con DeepSeek para ver si se puede hacer lo que quieres pero no parece dar una soluciΓ³n clara.

Comentarte que Cristobal implementΓ³ la Clase TToast en FWH y que usΓ‘ndola puedes tener mucho mas control aunque esa clase tambiΓ©n tiene un nivel de complejidad.

winrt.prg
#include "FiveWin.ch"

#define Show                       7
#define CreateToastNotification    7
#define CreateToastNotifierWithId  8
#define Item                       8
#define GetNamedItem               9
#define GetTemplateContent         9
#define add_Activated             12  
#define CreateTextNode            12
#define Get_Attributes            17
#define GetElementsByTagName      17
#define AppendChild               23

//---------------------------------------------------------------------------//

function WinRTString( cText )

   local pString
   
   WindowsCreateString( AnsiToWide( cText ), Len( cText ), @pString )

return pString

//---------------------------------------------------------------------------//

static function SetNodeText( pNodeList, nItem, cText, pXml )

   local pXmlNode, pXmlText, pXmlNodeChild
   local pString

   WinRTMethod( pNodeList, Item, nItem, @pXmlNode )
   pString = WinRTString( cText )
   WinRTMethod( pXml, CreateTextNode, pString, @pXmlText )
   WindowsDeleteString( pString )
   WinRTMethod( pXmlNode, AppendChild, pXmlText, @pXmlNodeChild )

return nil

//---------------------------------------------------------------------------//

static function SetImageFileName( pXml, cImageFileName ) 

   local pString := WinRTString( "image" )
   local pNodeList, pXmlNode, pAttributeMap
   local pXmlNodeAttribute, pXmlText, pXmlNodeChild

   WinRTMethod( pXml, GetElementsByTagName, pString, @pNodeList )
   WindowsDeleteString( pString )
   WinRTMethod( pNodeList, Item, 0, @pXmlNode )
   WinRTMethod( pXmlNode, Get_Attributes, @pAttributeMap )
   pString = WinRTString( "src" )
   WinRTMethod( pAttributeMap, GetNamedItem, pString, @pXmlNodeAttribute )
   WindowsDeleteString( pString )
   pString = WinRTString( cImageFileName )
   WinRTMethod( pXml, CreateTextNode, pString, @pXmlText )
   WindowsDeleteString( pString )
   WinRTMethod( pXmlNodeAttribute, AppendChild, pXmlText, @pXmlNodeChild )

return nil

//---------------------------------------------------------------------------//

function Toast( cFirstLine, cSecondLine, cThirdLine, cImageFileName )

   local pString, cIID, pToastFactory
   local pXml, pNodeList
   local pNotification, pNotificationFactory, pNotifier

   DEFAULT cFirstLine := "FiveWin notification",;
           cSecondLine := " ", cThirdLine := " ",;
           cImageFileName := "c:\fwh\bitmaps\pngs\fivetech.png"

   RoInitialize( 1 )

   pString = WinRTString( "Windows.UI.Notifications.ToastNotificationManager" )

   // "50AC103F-D235-4598-BBEF-98FE4D1A3AD4"
   cIID = Chr( 0x3F ) + Chr( 0x10 ) + Chr( 0xAC ) + Chr( 0x50 ) + ;
          Chr( 0x35 ) + Chr( 0xD2 ) + Chr( 0x98 ) + Chr( 0x45 ) + ;
          Chr( 0xBB ) + Chr( 0xEF ) + Chr( 0x98 ) + Chr( 0xFE ) + ;
          Chr( 0x4D ) + Chr( 0x1A ) + Chr( 0x3A ) + Chr( 0xD4 )

   RoGetActivationFactory( pString, cIID, @pToastFactory )

   WindowsDeleteString( pString );

   WinRTMethod( pToastFactory, GetTemplateContent, 3, @pXml )

   SetImageFileName( pXml, cImageFileName )
   
   pString = WinRTString( "text" )
   WinRTMethod( pXml, GetElementsByTagName, pString, @pNodeList )
   WindowsDeleteString( pString )

   SetNodeText( pNodeList, 0, cFirstLine,  pXml ) 
   SetNodeText( pNodeList, 1, cSecondLine, pXml ) 
   SetNodeText( pNodeList, 2, cThirdLine,  pXml ) 

   // 04124B20-82C6-4229-B109-FD9ED4662B53
   cIID = Chr( 0x20 ) + Chr( 0x4B ) + Chr( 0x12 ) + Chr( 0x04 ) + ;
          Chr( 0xC6 ) + Chr( 0x82 ) + Chr( 0x29 ) + Chr( 0x42 ) + ;
          Chr( 0xB1 ) + Chr( 0x09 ) + Chr( 0xFD ) + Chr( 0x9E ) + ;
          Chr( 0xD4 ) + Chr( 0x66 ) + Chr( 0x2B ) + Chr( 0x53 )

   pString = WinRTString( "Windows.UI.Notifications.ToastNotification" )
   RoGetActivationFactory( pString, cIID, @pNotificationFactory )
   WindowsDeleteString( pString )

   WinRTMethod( pNotificationFactory, CreateToastNotification, pXML, @pNotification )

   pString = WinRTString( " " )
   WinRTMethod( pToastFactory, CreateToastNotifierWithId, pString, @pNotifier )
   WindowsDeleteString( pString )

   // pEventHandler = WinRTEventHandler()
   // WinRTMethod( pNotification, add_Activated, pEventHandler, nEventToken )
   // MsgInfo( WinRTEventToken() )
   // WinRTMethod( pNotification, add_Activated + 1, pEventHandler, nEventToken )
   // MsgInfo( WinRTEventToken() )
   // WinRTMethod( pNotification, add_Activated + 2, pEventHandler, nEventToken )
   // MsgInfo( WinRTEventToken() )

   WinRTMethod( pNotifier, Show, pNotification )

   RoUninitialize()

return nil

//---------------------------------------------------------------------------//

DLL FUNCTION RoInitialize( nType AS LONG ) AS LONG PASCAL LIB "combase.dll"

DLL FUNCTION RoUninitialize() AS VOID PASCAL LIB "combase.dll"

DLL FUNCTION WindowsCreateString( cWideText AS LPSTR, nLength AS LONG, @pString AS PTR ) ;
   AS LONG PASCAL LIB "combase.dll"
   
DLL FUNCTION WindowsDeleteString( pString AS PTR ) AS LONG PASCAL LIB "combase.dll"

DLL FUNCTION RoGetActivationFactory( pString AS PTR, REFIID AS LPSTR, @pFactory AS PTR ) ;
   AS LONG PASCAL LIB "combase.dll"

DLL FUNCTION WindowsGetStringRawBuffer( pString AS PTR, @nLenght AS LONG ) ;
   AS LONG PASCAL LIB "combase.dll"
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Ajustar tamaΓ±o caja toast
Posted: Sat Feb 08, 2025 10:45 AM
En una siguiente consulta a DeepSeek parece haber dado unas pistas:
function Toast( cFirstLine, cSecondLine, cThirdLine, cImageFileName )

   local pString, cIID, pToastFactory
   local pXml, pNodeList
   local pNotification, pNotificationFactory, pNotifier
   local cXml

   DEFAULT cFirstLine := "FiveWin notification",;
           cSecondLine := " ", cThirdLine := " ",;
           cImageFileName := "c:\fwh\bitmaps\pngs\fivetech.png"

   RoInitialize( 1 )

   // Create XML document instance
   pString = WinRTString( "Windows.Data.Xml.Dom.XmlDocument" )
   RoActivateInstance( pString, @pXml )
   WindowsDeleteString( pString )

   // Define compact XML (no image or inline image)
   cXml := ;
   '<toast>'+;
      '<visual>'+;
         '<binding template="ToastGeneric">'+;
            iif( Empty( cImageFileName ), '', '<image src="' + cImageFileName + '"/>' ) + ;
            '<text>' + cFirstLine + '</text>'+;
            '<text>' + cSecondLine + '</text>'+;
            '<text>' + cThirdLine + '</text>'+;
         '</binding>'+;
      '</visual>'+;
   '</toast>'

   // Load the XML into the document
   pString = WinRTString( cXml )
   WinRTMethod( pXml, "LoadXml", pString )
   WindowsDeleteString( pString )

   // Proceed with creating the notification (same as before)
   pString = WinRTString( "Windows.UI.Notifications.ToastNotificationManager" )
   cIID = Chr( 0x3F ) + Chr( 0x10 ) + Chr( 0xAC ) + Chr( 0x50 ) + ;
          Chr( 0x35 ) + Chr( 0xD2 ) + Chr( 0x98 ) + Chr( 0x45 ) + ;
          Chr( 0xBB ) + Chr( 0xEF ) + Chr( 0x98 ) + Chr( 0xFE ) + ;
          Chr( 0x4D ) + Chr( 0x1A ) + Chr( 0x3A ) + Chr( 0xD4 )
   RoGetActivationFactory( pString, cIID, @pToastFactory )
   WindowsDeleteString( pString )

   // ... (rest of the code remains the same)
   
   WinRTMethod( pNotifier, "Show", pNotification )

   RoUninitialize()

return nil
For a minimal Toast with just one line of text and no image:
Toast( "Short Message", "", "" )
Toast( "Short Message", "", "", "c:\path\to\small_image.png" )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1816
Joined: Wed Oct 26, 2005 02:49 PM
Re: Ajustar tamaΓ±o caja toast
Posted: Mon Feb 10, 2025 09:17 PM
Antonio buenas tardes, como estas?

Intentamos compilar la funciΓ³n, pero salen los siguiente errores:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
?FiveWin for xHarbour 24.09 64bits - Sep. 2024   Harbour development power  β”‚β–„
?(c) FiveTech 1993-2024 for Microsoft Windows 9X/NT/200X/ME/XP/Vista/7/8/10 β”‚β–ˆ
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜?
Β  β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€?
Compiling...
C:\xHar2407_64\bin\harbour leandro16 /n /d__64__ /iC:\fwh64_2409\include;C:\xHar2407_64\include /w /p
xHarbour 1.3.1 Intl. (SimpLex) (Build 20240624)
Copyright 1999-2024, http://www.xharbour.org http://www.harbour-project.org/
Compiling 'leandro16.prg' and generating preprocessed output to 'leandro16.ppo'...
Generating C source output to 'leandro16.c'...
Done.
Lines 58, Functions/Procedures 1, pCodes 159
Embarcadero C++ 7.70 for Win64 Copyright (c) 2012-2023 Embarcadero Technologies, Inc.
leandro16.c:
Turbo Incremental Link64 6.98 Copyright (c) 1997-2023 Embarcadero Technologies, Inc.
Error: Unresolved external 'HB_FUN_ROACTIVATEINSTANCE' referenced from C:\FWH64_2409\SAMPLES\LEANDRO16.OBJ
* Linking errors *

c:\fwh64_2409\samples>
#include "Fivewin.ch"

function Toast( cFirstLine, cSecondLine, cThirdLine, cImageFileName )

   local pString, cIID, pToastFactory
   local pXml, pNodeList
   local pNotification, pNotificationFactory, pNotifier
   local cXml

   DEFAULT cFirstLine := "FiveWin notification"
   DEFAULT cSecondLine := " " 
   DEFAULT cThirdLine := " "
   DEFAULT cImageFileName := "c:\fwh\bitmaps\pngs\fivetech.png"

   RoInitialize( 1 )

   // Create XML document instance
   pString = WinRTString( "Windows.Data.Xml.Dom.XmlDocument" )
   RoActivateInstance( pString, @pXml )
   WindowsDeleteString( pString )

   // Define compact XML (no image or inline image)
   cXml := ;
   '<toast>'+;
      '<visual>'+;
         '<binding template="ToastGeneric">'+;
            iif( Empty( cImageFileName ), '', '<image src="' + cImageFileName + '"/>' ) + ;
            '<text>' + cFirstLine + '</text>'+;
            '<text>' + cSecondLine + '</text>'+;
            '<text>' + cThirdLine + '</text>'+;
         '</binding>'+;
      '</visual>'+;
   '</toast>'

   // Load the XML into the document
   pString = WinRTString( cXml )
   WinRTMethod( pXml, "LoadXml", pString )
   WindowsDeleteString( pString )

   // Proceed with creating the notification (same as before)
   pString = WinRTString( "Windows.UI.Notifications.ToastNotificationManager" )
   cIID = Chr( 0x3F ) + Chr( 0x10 ) + Chr( 0xAC ) + Chr( 0x50 ) + ;
          Chr( 0x35 ) + Chr( 0xD2 ) + Chr( 0x98 ) + Chr( 0x45 ) + ;
          Chr( 0xBB ) + Chr( 0xEF ) + Chr( 0x98 ) + Chr( 0xFE ) + ;
          Chr( 0x4D ) + Chr( 0x1A ) + Chr( 0x3A ) + Chr( 0xD4 )
   RoGetActivationFactory( pString, cIID, @pToastFactory )
   WindowsDeleteString( pString )

   // ... (rest of the code remains the same)
   
   WinRTMethod( pNotifier, "Show", pNotification )

   RoUninitialize()

return nil
Saludos
LEANDRO AREVALO
BogotΓ‘ (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 25.01 ] [ xHarbour 64 bits) ]
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Ajustar tamaΓ±o caja toast
Posted: Tue Feb 11, 2025 07:30 AM
https://learn.microsoft.com/en-us/windows/win32/api/roapi/nf-roapi-roactivateinstance

Prueba con este cΓ³digo:
DLL FUNCTION RoActivateInstance( pRuntimeClassName AS LPSTR, @pInstance AS PTR ) AS LONG PASCAL LIB "combase.dll"

FUNCTION RoActivateInstanceWrapper( cRuntimeClassName )
   LOCAL nResult, pHString, pInstance
   LOCAL nLength := Len( cRuntimeClassName )
   LOCAL IID_IInspectable := "{AF86E2E0-B12D-4C6A-9C5A-D7AA65101E90}" // IID de IInspectable

   // Inicializar el entorno de Windows Runtime
   nResult := RoInitialize( 0 ) // RO_INIT_SINGLETHREADED
   IF nResult != 0
      RETURN nResult
   ENDIF

   // Crear un HSTRING a partir de la cadena Unicode
   nResult := WindowsCreateString( cRuntimeClassName, nLength, @pHString )
   IF nResult != 0
      RoUninitialize()
      RETURN nResult
   ENDIF

   // Llamar a RoActivateInstance directamente
   nResult := RoActivateInstance( pHString, @pInstance )
   IF nResult != 0
      WindowsDeleteString( pHString )
      RoUninitialize()
      RETURN nResult
   ENDIF

   // Liberar HSTRING
   WindowsDeleteString( pHString )

   // Desinicializar Windows Runtime
   // RoUninitialize()

   // Retornar la instancia obtenida
RETURN pInstance
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1816
Joined: Wed Oct 26, 2005 02:49 PM
Re: Ajustar tamaΓ±o caja toast
Posted: Tue Feb 11, 2025 06:48 PM
Antonio buenas tardes como estas?

Se compilo la aplicaciΓ³n sin problema, pero no ejecuta ninguna acciΓ³n.
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
?FiveWin for xHarbour 24.09 64bits - Sep. 2024   Harbour development power  β”‚β–„
?(c) FiveTech 1993-2024 for Microsoft Windows 9X/NT/200X/ME/XP/Vista/7/8/10 β”‚β–ˆ
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜?
Β  β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€?
Compiling...
C:\xHar2407_64\bin\harbour leandro16 /n /d__64__ /iC:\fwh64_2409\include;C:\xHar2407_64\include /w /p
xHarbour 1.3.1 Intl. (SimpLex) (Build 20240624)
Copyright 1999-2024, http://www.xharbour.org http://www.harbour-project.org/
Compiling 'leandro16.prg' and generating preprocessed output to 'leandro16.ppo'...
Generating C source output to 'leandro16.c'...
Done.
Lines 41, Functions/Procedures 2, pCodes 192
Embarcadero C++ 7.70 for Win64 Copyright (c) 2012-2023 Embarcadero Technologies, Inc.
leandro16.c:
Turbo Incremental Link64 6.98 Copyright (c) 1997-2023 Embarcadero Technologies, Inc.
* Application successfully built *

c:\fwh64_2409\samples>
#include "Fivewin.ch"


DLL FUNCTION RoActivateInstance( pRuntimeClassName AS LPSTR, @pInstance AS PTR ) AS LONG PASCAL LIB "combase.dll"

FUNCTION RoActivateInstanceWrapper( cRuntimeClassName )
   LOCAL nResult, pHString, pInstance
   LOCAL nLength := Len( cRuntimeClassName )
   LOCAL IID_IInspectable := "{AF86E2E0-B12D-4C6A-9C5A-D7AA65101E90}" // IID de IInspectable

   // Inicializar el entorno de Windows Runtime
   nResult := RoInitialize( 0 ) // RO_INIT_SINGLETHREADED
   IF nResult != 0
      RETURN nResult
   ENDIF

   // Crear un HSTRING a partir de la cadena Unicode
   nResult := WindowsCreateString( cRuntimeClassName, nLength, @pHString )
   IF nResult != 0
      RoUninitialize()
      RETURN nResult
   ENDIF

   // Llamar a RoActivateInstance directamente
   nResult := RoActivateInstance( pHString, @pInstance )
   IF nResult != 0
      WindowsDeleteString( pHString )
      RoUninitialize()
      RETURN nResult
   ENDIF

   // Liberar HSTRING
   WindowsDeleteString( pHString )

   // Desinicializar Windows Runtime
   // RoUninitialize()

   // Retornar la instancia obtenida
RETURN pInstance
Saludos
LEANDRO AREVALO
BogotΓ‘ (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 25.01 ] [ xHarbour 64 bits) ]
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Ajustar tamaΓ±o caja toast
Posted: Tue Feb 11, 2025 10:17 PM

El Toast aparece con el mismo tamaΓ±o ?

Estas usando la versiΓ³n modificada que publicaste ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1816
Joined: Wed Oct 26, 2005 02:49 PM
Re: Ajustar tamaΓ±o caja toast
Posted: Thu Feb 13, 2025 07:58 PM
Antonio buenas tardes gracias por responder
Antonio Linares wrote: El Toast aparece con el mismo tamaΓ±o ?
Si el mismo tamaΓ±o.
Antonio Linares wrote: Estas usando la versiΓ³n modificada que publicaste ?
Si correcto.
Saludos
LEANDRO AREVALO
BogotΓ‘ (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 25.01 ] [ xHarbour 64 bits) ]

Continue the discussion