FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Incrustar CALCULADORA en FWH
Posts: 1076
Joined: Fri Oct 07, 2005 10:41 PM
Incrustar CALCULADORA en FWH
Posted: Fri Oct 31, 2008 08:52 AM
Bueno, pos eso

Aquí una clase para tal efecto.

Aunque hay unos detalles, como el borrado de la imagen de la calculadora al minimizar o maximizar el recurso.

aquí el código y esperemos haya alguien que haga las pruebas y entre todos vemos si logramos detallarla y hacerla funcionar al 100%

/*
   Tomado: Recursos visualbasic
   Fecha:  31 . octubre . 2008
   Hora:   02.48

   INCOS, wmormar
*/

#include "fivewin.ch"
#include "CStruct.ch"
#include "wintypes.ch"

   // Constante para la llamada dinámica del API
#define DC_CALL_STD            0x0020

#define SHOWMAXIMIZED_eSW      3
   // Constante para usar con el Api DeleteMenu
#define MF_BYPOSITION          0x400
#define MF_REMOVE              0x1000

   // Constante para usar con el Api SendMessage para cerrar
   // la aplicación ( en este caso La calculadora )
#define SC_CLOSE              61536
#define WM_SYSCOMMAND         274

   // Constante para usar con GetWindowLong y SetWindowLong
#define GWL_STYLE             -16

   // Constantes para SetWindowPos
#define SWP_FRAMECHANGED      0x0020
#define SWP_NOMOVE            0x0002
#define SWP_NOSIZE            0x0001
#define SWP_NOZORDER          0x0004
#define HWND_TOP              0

CLASS TCalculator
   // Mantiene el Handle del programa
   DATA hwnd
   DATA hwndcalc
   DATA cTitlecalculator     AS CHARACTER  INIT  "Calculadora"
   DATA ocontainer           AS OBJECT
   DATA nTime                AS NUMERIC    INIT 25000

   METHOD normal()
   METHOD barra_titulo( lErase )
   METHOD Eliminar_Menu( hwnd )
   METHOD Cerrar_Programa( hwnd )
   METHOD Cerrar_Programa( hwnd )
   METHOD incrustar_calculadora( ocontainer )
   METHOD Incrustar( hwnd )
   METHOD liberar_programa( hwnd )
   METHOD GetMenu( hwnd )
   METHOD DeleteMenu( hmenu, nposition, wflags )
   METHOD GetMenuItemCount( hmenu )
   METHOD DrawMenuBar( hwnd )
   METHOD GetWindowLong( hwnd, nindex )
   METHOD SetWindowLong( hwnd, nindex, dwnewlong )
   METHOD SetWindowPos( hwnd, hwndinsertafter, x, y, cx, cy, wflags )

ENDCLASS

/*******************************************************************/
// Cargando calculadora normal de windows
METHOD normal()
   ShellExecute( ::hwnd,,"calc.exe",,, )

   RETURN NIL

/*******************************************************************/
// Elimina y reestablece la barra de título de una ventana
METHOD barra_titulo( hwnd, lErase )
   LOCAL nStyle

   // Almacena en la variable el estilo actual
   nStyle := ::GetWindowLong( hwnd, GWL_STYLE )

   IF !lErase
      nStyle := nor( nStyle, WS_CAPTION )
   ELSE
      nStyle += nor( WS_CAPTION )
   ENDIF

   // Aplica el nuevo estilo
   ::SetWindowLong( hwnd, GWL_STYLE, nStyle )

   // Mueve de posición la calculadora
   ::SetWindowPos( ::hwndcalc, HWND_TOP, 0, 0, 0, 0, ;
                   nor( SWP_FRAMECHANGED, SWP_NOMOVE, SWP_NOSIZE, SWP_NOZORDER ) )

   RETURN NIL

/*******************************************************************/
//Elimina el menú de una ventana específica
METHOD Eliminar_Menu( hwnd )
   LOCAL hmenu
   LOCAL nmenu
   LOCAL i

   // Recuper el hwnd del menu del programa
   hmenu := ::GetMenu( hwnd )
   IF hmenu <> 0
      // cantidad de menúes
      nmenu := ::GetMenuItemCount( hmenu )
      IF nmenu > 0
         // Recorre todos los menú y los elimina
         FOR i := 1 To nmenu
            ::DeleteMenu( hmenu, 0, nor(MF_BYPOSITION, MF_REMOVE) )
         NEXT

         // Repinta la barra de menú
         ::DrawMenuBar( hwnd )
      ENDIF
   ENDIF

   RETURN NIL

/*******************************************************************/
// Cierra
METHOD Cerrar_Programa( hwnd )
   DEFAULT hwnd := ::hwndcalc

   // Cierra el programa abierto, en este caso la calculadora
   SendMessage( hwnd, WM_SYSCOMMAND, SC_CLOSE, 0& )

   RETURN .t.

/*******************************************************************/
// mete la ventana en el contenedor
METHOD incrustar_calculadora( ocontainer )
   LOCAL aRect := {}
   LOCAL nLoop := 0

   ::ocontainer := ocontainer

   // Handle de la aplicación
   ::hwndcalc := FindWindow( 0, ::cTitlecalculator )
   IF ::hwndcalc > 0
      ::Cerrar_Programa( ::hwndcalc )
      ::hwndcalc := NIL
   ENDIF

   // Abre el programa
   MSGRUN( "Ejecutando calculadora...",, ;
           {|| ShellExecute( ,,"calc.exe",,, )} )

   WHILE nLoop <= ::nTime
      // Handle de la aplicación
      ::hwndcalc := FindWindow( 0, ::cTitlecalculator )
      IF ::hwndcalc <> 0
         EXIT
      ENDIF
      SYSREFRESH()
      nLoop += 1
   ENDDO

   // Ocultando la calculadora
   ShowWindow( ::hwndcalc, 0 )

   // Recupera el ancho y alto del área cliente
   aRect := GetClientRect( ::hwndcalc )

   // Redimensiona el picturebox al ancho y alto del programa
   ::ocontainer:nWidth  := ( aRect[4] - aRect[2] ) + 25
   ::ocontainer:nHeight := ( aRect[3] - aRect[1] ) + 55

   // Elimina la barra de título, los menúes y lo incrusta
   ::Eliminar_Menu( ::hwndcalc )
   ::Barra_Titulo( ::hwndcalc, .t. )
   ::Incrustar( ::hwndcalc )
   ::ocontainer:refresh()

   RETURN NIL

/*******************************************************************/
METHOD Incrustar( hwnd )
   LOCAL nret

   // Lo metemos dentro del ocontainer
   SetParent( hwnd, ::ocontainer:hwnd )

   // Maximizamos la ventana incrustada dentro del contenedor, mediante el _
   // Api showWindow, pasándole la constante SHOWMAXIMIZED_eSW
   nret := ShowWindow( hwnd, SHOWMAXIMIZED_eSW )

   RETURN .t.

/*******************************************************************/
// Libera la ventana pasándole en el segundo
// parámetro el valor 0 y la cierra
METHOD liberar_programa( hwnd )
   // Libera el programa
   SetParent( hwnd, 0 )

   // Lo cierra
   ::Cerrar_Programa( hwnd )

   hwnd := 0

   RETURN NIL

/*******************************************************************/
// Recupera el Hwnd de un menú
METHOD GetMenu( hwnd )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;      // external DLL
                    DC_CALL_STD    , ;      // calling convention
                    "GetMenu" )             // external function

   nRet := DllExecuteCall( pCallTemplate, hwnd )

   RETURN nRet

/*******************************************************************/
// Elimina el menú de una aplicación
METHOD DeleteMenu( hmenu, nposition, wflags )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "DeleteMenu" )

   nRet := DllExecuteCall( pCallTemplate, hmenu, nposition, wflags )

   RETURN nRet

/*******************************************************************/
// Recupera la cantidad de Item de menúes para saber cuantos hay que eliminar
METHOD GetMenuItemCount( hmenu )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "GetMenuItemCount" )

   nRet := DllExecuteCall( pCallTemplate, hmenu )

   RETURN nRet

/*******************************************************************/
// Redibuja - repinta la barra de menú luego de eliminarlo
METHOD DrawMenuBar( hwnd )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "DrawMenuBar" )

   nRet := DllExecuteCall( pCallTemplate, hwnd )

   RETURN nRet

/*******************************************************************/
// Estas tres funciones es para eliminar la barra de título
// del programa que se va a incrustar
METHOD GetWindowLong( hwnd, nindex )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "GetWindowLongA" )

   nRet := DllExecuteCall( pCallTemplate, hwnd, nindex )

   RETURN nRet

/*******************************************************************/
METHOD SetWindowLong( hwnd, nindex, dwnewlong )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "SetWindowLongA" )

   nRet := DllExecuteCall( pCallTemplate, hwnd, nindex, dwnewlong )

   RETURN nRet

/*******************************************************************/
METHOD SetWindowPos( hwnd, hwndinsertafter, x, y, cx, cy, wflags )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "SetWindowPos" )

   nRet := DllExecuteCall( pCallTemplate, hwnd, hwndinsertafter, x, y, cx, cy, wflags )

   RETURN nRet

/*******************************************************************/


Espero ayuda y ojalá sea de ayuda para otros compañeros
William, Morales

Saludos



méxico.sureste
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Incrustar CALCULADORA en FWH
Posted: Fri Oct 31, 2008 08:55 AM

William,

Gracias! :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1076
Joined: Fri Oct 07, 2005 10:41 PM
Re: Incrustar CALCULADORA en FWH
Posted: Fri Oct 31, 2008 08:58 AM
Se me olvidaba,

En mi caso hice un dialogo con un bitmap.

aqui el código de la prueba.

/*
  - Autor: INCOS, wmormar
  - Fecha: 31 . octubre . 2008
  - Hora: 02.57
*/

#include "fivewin.ch"

FUNCTION main()
   LOCAL oBmp
   LOCAL tCalc32
   LOCAL this   := Self
   LOCAL lSalir := .f.

   IF ::oCalculator:classname() == "TDIALOG"
      ::oCalculator:restore()
      ::oCalculator:setfocus()
      RETURN NIL
   ENDIF

   tCalc32 := TCalculator()
   DEFINE DIALOG ::oCalculator RESOURCE "CALCULADORA" TITLE ".:: Calculadora ::." COLOR CLR_BLUE,CLR_WHITE
      REDEFINE BITMAP oBmp ID 401 OF ::oCalculator TRANSPARENT
      ::oCalculator:bLDblClick := {|| tCalc32:cerrar_programa(), lSalir := .t., ::oCalculator:END(), ::oCalculator := NIL}
      ::oCalculator:bRClicked  := {|| tCalc32:incrustar_calculadora( oBmp )}
   ACTIVATE DIALOG ::oCalculator ON INIT equis(this:oCalculator:hWnd) ;
            VALID lSalir

RETURN NIL


esperemos sus pruebas y comentarios; y desde luego la ayuda para detallar la clase.
William, Morales

Saludos



méxico.sureste
Posts: 1286
Joined: Mon Feb 25, 2008 02:54 PM
Incrustar CALCULADORA en FWH
Posted: Fri Oct 31, 2008 10:22 AM

UNRESOLVED EXTERNAL EQUIS ?

ubiratanmga@gmail.com

FWH24.04
BCC7.3
HARBOUR3.2
xMate
Pelles´C
TDolphin
Posts: 2064
Joined: Fri Jan 06, 2006 09:28 PM
Incrustar CALCULADORA en FWH
Posted: Fri Oct 31, 2008 01:39 PM

Willian, a lo que se refiera a prueba, estoy a la rden, descargo, creo y empiezo a probarl...y te aviso los detalles...si salen...saludos... :shock:

Dios no está muerto...



Gracias a mi Dios ante todo!
Posts: 1076
Joined: Fri Oct 07, 2005 10:41 PM
Incrustar CALCULADORA en FWH
Posted: Fri Oct 31, 2008 07:39 PM
SGS wrote:UNRESOLVED EXTERNAL EQUIS ?


elimina esa llamada a la función.

saludos
William, Morales

Saludos



méxico.sureste
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Incrustar CALCULADORA en FWH
Posted: Fri Oct 31, 2008 09:28 PM
Es un buen trabajo, lo probe y seguro lo uso, me encontre con estos inconvenientes, es seguro que esperas comentarios y experiencias con el uso de la misma....

la idea es que trabaje con cualquier calculadora, en espaniol - ingles u otro idioma, lo malo es que solo funciona para cuando la calculadora esta en espaniol por la data:
DATA cTitlecalculator AS CHARACTER INIT "Calculadora"
le agrege una nueva data
DATA ClassCal AS CHARACTER INIT "SciCalc"
esa es la misma clase para todas las calculadoras, lo probe con windows vista, xp, 98 en epaniol e ingles, todas funcionaron por el nombre de la clase, ya que me consegui con titulos como "CALCULATOR PLUS", "CALCULATOR", "CALCULADORA", "CALC", pero todos tenian en comun "SciCalc"
hice una modificaciones al metodo incrustar_calculadora
   ::hwndcalc := FindWindow( 0, ::cTitlecalculator )
   IF ::hwndcalc == 0
   		::hwndcalc := FindWindow( ::ClassCal, 0 ) // para que busque por el nombre de la clase
   ENDIF

//unas lineas mas abajo

   WHILE nLoop <= ::nTime
      // Handle de la aplicación
      ::hwndcalc := FindWindow( 0, ::cTitlecalculator )
      IF ::hwndcalc <> 0
         EXIT
      ELSE
      	::hwndcalc := FindWindow( ::ClassCal, 0 )
      ENDIF
      SYSREFRESH()
      nLoop += 1
   ENDDO


elimine del style en el metodo barra_titulo, SWP_NOMOVE porque nunca me quedaba en el tope


realmente no se si es la forma correcta pero me imagino que esto es lo que esperas de nosotros...
Posts: 1076
Joined: Fri Oct 07, 2005 10:41 PM
Incrustar CALCULADORA en FWH
Posted: Sat Nov 01, 2008 02:58 AM
mcfox,

gracias por hacer tus pruebas.

creo que la mopdificación iría en el test:

   tCalc32 := TCalculator()
   tCalc32:cTitleCalculator := "SciCalC"
   DEFINE DIALOG ::oCalculator RESOURCE "CALCULADORA" TITLE ".:: Calculadora ::." COLOR CLR_BLUE,CLR_WHITE
      REDEFINE BITMAP oBmp ID 401 OF ::oCalculator TRANSPARENT
      REDEFINE BUTTON oBtn ID 301 ACTION (oBtn:disable(), tCalc32:incrustar_calculadora( oBmp ) )
      REDEFINE BUTTON ID 302 ACTION (tCalc32:cerrar_programa(), lSalir := .t., ;
                                     ::oCalculator:END(), ::oCalculator := NIL)
      REDEFINE BUTTON ID 303 ACTION (UpdateWindow( tCalc32:hwndcalc ), oBmp:refresh())
   ACTIVATE DIALOG ::oCalculator NOWAIT ON INIT equis( this:oCalculator:hWnd ) ;
            VALID lSalir


Ahi no modificariamos la clase y se usaría cualquier calculadora.

en el caso de la clase también he modificado la clase quedando de la siguiente manera.

/*
   Tomado: Recursos visualbasic
   Fecha:  31 . octubre . 2008
   Hora:   02.48

   INCOS, wmormar
*/

#include "fivewin.ch"

   // Constante para la llamada dinámica del API
#define DC_CALL_STD            0x0020

#define SHOWMAXIMIZED_eSW      3
   // Constante para usar con el Api DeleteMenu
#define MF_BYPOSITION          0x400
#define MF_REMOVE              0x1000

   // Constante para usar con el Api SendMessage para cerrar
   // la aplicación ( en este caso La calculadora )
#define SC_CLOSE              61536
#define WM_SYSCOMMAND         274

   // Constante para usar con GetWindowLong y SetWindowLong
#define GWL_STYLE             -16

   // Constantes para SetWindowPos
#define SWP_FRAMECHANGED      0x0020
#define SWP_NOMOVE            0x0002
#define SWP_NOSIZE            0x0001
#define SWP_NOZORDER          0x0004
#define HWND_TOP              0

CLASS TCalculator
   // Mantiene el Handle del programa
   DATA hwnd
   DATA hwndcalc
   DATA cTitlecalculator     AS CHARACTER  INIT  "Calculadora"
   DATA ocontainer           AS OBJECT
   DATA nTime                AS NUMERIC    INIT 25000

   METHOD normal()
   METHOD barra_titulo( lErase )
   METHOD Eliminar_Menu( hwnd )
   METHOD Cerrar_Programa( hwnd )
   METHOD Cerrar_Programa( hwnd )
   METHOD incrustar_calculadora( ocontainer )
   METHOD Incrustar( hwnd )
   METHOD liberar_programa( hwnd )
   METHOD GetMenu( hwnd )
   METHOD DeleteMenu( hmenu, nposition, wflags )
   METHOD GetMenuItemCount( hmenu )
   METHOD DrawMenuBar( hwnd )
   METHOD GetWindowLong( hwnd, nindex )
   METHOD SetWindowLong( hwnd, nindex, dwnewlong )
   METHOD SetWindowPos( hwnd, hwndinsertafter, x, y, cx, cy, wflags )
   METHOD setfocus( hwnd )

ENDCLASS

/*******************************************************************/
// Cargando calculadora normal de windows
METHOD normal()
   ShellExecute( ::hwnd,,"calc.exe",,, )

   RETURN NIL

/*******************************************************************/
// Elimina y reestablece la barra de título de una ventana
METHOD barra_titulo( hwnd, lErase )
   LOCAL nStyle

   // Almacena en la variable el estilo actual
   nStyle := ::GetWindowLong( hwnd, GWL_STYLE )

   IF !lErase
      nStyle := nor( nStyle, WS_CAPTION )
   ELSE
      nStyle += nor( WS_CAPTION )
   ENDIF

   // Aplica el nuevo estilo
   ::SetWindowLong( hwnd, GWL_STYLE, nStyle )

   // Mueve de posición la calculadora
   ::SetWindowPos( ::hwndcalc, HWND_TOP, 0, 0, 0, 0 )

   RETURN NIL

/*******************************************************************/
//Elimina el menú de una ventana específica
METHOD Eliminar_Menu( hwnd )
   LOCAL hmenu
   LOCAL nmenu
   LOCAL i

   // Recuper el hwnd del menu del programa
   hmenu := ::GetMenu( hwnd )
   IF hmenu <> 0
      // cantidad de menúes
      nmenu := ::GetMenuItemCount( hmenu )
      IF nmenu > 0
         // Recorre todos los menú y los elimina
         FOR i := 1 To nmenu
            ::DeleteMenu( hmenu, 0, nor(MF_BYPOSITION, MF_REMOVE) )
         NEXT

         // Repinta la barra de menú
         ::DrawMenuBar( hwnd )
      ENDIF
   ENDIF

   RETURN NIL

/*******************************************************************/
// Cierra
METHOD Cerrar_Programa( hwnd )
   DEFAULT hwnd := ::hwndcalc

   // Cierra el programa abierto, en este caso la calculadora
   SendMessage( hwnd, WM_SYSCOMMAND, SC_CLOSE, 0& )

   RETURN .t.

/*******************************************************************/
// mete la ventana en el contenedor
METHOD incrustar_calculadora( ocontainer )
   LOCAL aRect := {}
   LOCAL nLoop := 0

   ::ocontainer := ocontainer

   // Handle de la aplicación
   ::hwndcalc := FindWindow( 0, ::cTitlecalculator )
   IF ::hwndcalc > 0
      ::Cerrar_Programa( ::hwndcalc )
      ::hwndcalc := NIL
   ENDIF

   // Abre el programa
   MSGRUN( "Ejecutando calculadora...",, ;
           {|| ShellExecute( ,,"calc.exe",,, )} )

   WHILE nLoop <= ::nTime
      // Handle de la aplicación
      ::hwndcalc := FindWindow( 0, ::cTitlecalculator )
      IF ::hwndcalc <> 0
         EXIT
      ENDIF
      SYSREFRESH()
      nLoop += 1
   ENDDO

   // Ocultando la calculadora
   ShowWindow( ::hwndcalc, 0 )

   // Recupera el ancho y alto del área cliente
   aRect := GetClientRect( ::hwndcalc )

   // Redimensiona el picturebox al ancho y alto del programa
   ::ocontainer:nWidth  := ( aRect[4] - aRect[2] ) // + 25
   ::ocontainer:nHeight := ( aRect[3] - aRect[1] ) // + 55

   // Elimina la barra de título, los menúes y lo incrusta
   ::Eliminar_Menu( ::hwndcalc )
   ::Barra_Titulo( ::hwndcalc, .t. )
   ::Incrustar( ::hwndcalc )
   UpdateWindow( ::hwndcalc )
   ::ocontainer:refresh()
   ::setfocus( ::hwndcalc )

   RETURN NIL

/*******************************************************************/
METHOD Incrustar( hwnd )
   LOCAL nret

   // Lo metemos dentro del ocontainer
   SetParent( hwnd, ::ocontainer:hwnd )

   // Maximizamos la ventana incrustada dentro del contenedor, mediante el _
   // Api showWindow, pasándole la constante SHOWMAXIMIZED_eSW
   nret := ShowWindow( hwnd, SHOWMAXIMIZED_eSW )

   RETURN .t.

/*******************************************************************/
// Libera la ventana pasándole en el segundo
// parámetro el valor 0 y la cierra
METHOD liberar_programa( hwnd )
   // Libera el programa
   SetParent( hwnd, 0 )

   // Lo cierra
   ::Cerrar_Programa( hwnd )

   hwnd := 0

   RETURN NIL

/*******************************************************************/
// Recupera el Hwnd de un menú
METHOD GetMenu( hwnd )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;      // external DLL
                    DC_CALL_STD    , ;      // calling convention
                    "GetMenu" )             // external function

   nRet := DllExecuteCall( pCallTemplate, hwnd )

   RETURN nRet

/*******************************************************************/
// Elimina el menú de una aplicación
METHOD DeleteMenu( hmenu, nposition, wflags )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "DeleteMenu" )

   nRet := DllExecuteCall( pCallTemplate, hmenu, nposition, wflags )

   RETURN nRet

/*******************************************************************/
// Recupera la cantidad de Item de menúes para saber cuantos hay que eliminar
METHOD GetMenuItemCount( hmenu )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "GetMenuItemCount" )

   nRet := DllExecuteCall( pCallTemplate, hmenu )

   RETURN nRet

/*******************************************************************/
// Redibuja - repinta la barra de menú luego de eliminarlo
METHOD DrawMenuBar( hwnd )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "DrawMenuBar" )

   nRet := DllExecuteCall( pCallTemplate, hwnd )

   RETURN nRet

/*******************************************************************/
// Estas tres funciones es para eliminar la barra de título
// del programa que se va a incrustar
METHOD GetWindowLong( hwnd, nindex )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "GetWindowLongA" )

   nRet := DllExecuteCall( pCallTemplate, hwnd, nindex )

   RETURN nRet

/*******************************************************************/
METHOD SetWindowLong( hwnd, nindex, dwnewlong )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "SetWindowLongA" )

   nRet := DllExecuteCall( pCallTemplate, hwnd, nindex, dwnewlong )

   RETURN nRet

/*******************************************************************/
METHOD SetWindowPos( hwnd, hwndinsertafter, x, y, cx, cy, wflags )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "SetWindowPos" )

   nRet := DllExecuteCall( pCallTemplate, hwnd, hwndinsertafter, x, y, cx, cy, wflags )

   RETURN nRet

/*******************************************************************/
METHOD setfocus( hwnd )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "SetFocus" )

   nRet := DllExecuteCall( pCallTemplate, hwnd )

   RETURN nRet

/*******************************************************************/


espero sus comentarios
William, Morales

Saludos



méxico.sureste
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Incrustar CALCULADORA en FWH
Posted: Sat Nov 01, 2008 11:14 AM

Me sigue generando el mismo error cuando ejecuto el programa en diferentes SO y/o idiomas.
La funcion FindWindow trabaja con 2 parametros:
FindWindow( Classname, WindowsName ), estas usando solo el 2do parametro (WindowsName) que es el que cambia, el 1er parametro siempre es el mismo (ClassName), por eso agrege una nueva data:
DATA ClassCal AS CHARACTER INIT "SciCalc"
y la busqueda de la calculadora la hice de las 2 formas, buscando primero por el titulo si no lo consigue por la clase ( personalmente la buscaria por la clase ):
::hwndcalc := FindWindow( 0, ::cTitlecalculator )
::hwndcalc := FindWindow( ::ClassCal, 0 )

Posts: 880
Joined: Fri Jan 12, 2007 08:35 PM
HOLA
Posted: Sat Nov 01, 2008 06:23 PM

Hola Willian

a mi me salen muchos - Warning W0001 Ambiguous reference: 'SELF'

Que podra ser :?

Saluditos

Aida :wink:

Que es mejor que programar? creo que nada :)
Atropellada pero aqui ando :P

I love Fivewin

séʌǝɹ ןɐ ɐʇsǝ opunɯ ǝʇsǝ
Posts: 1076
Joined: Fri Oct 07, 2005 10:41 PM
Incrustar CALCULADORA en FWH
Posted: Sat Nov 01, 2008 07:18 PM
mcfox,

las modificaciones serían de esta manera.

Agregar la data a la clase
...
...
   DATA cClassName           AS CHARACTER  INIT  "SciCalc"
...
...


En el metodo incrustar_calculadora( ... )
METHOD incrustar_calculadora( ocontainer )
   LOCAL aRect := {}
   LOCAL nLoop := 0

   ::ocontainer := ocontainer

   // Handle de la aplicación
   ::hwndcalc := FindWindow( 0, ::cTitlecalculator )
   IF ::hwndcalc > 0
      ::Cerrar_Programa( ::hwndcalc )
      ::hwndcalc := NIL
   ENDIF

   // Abre el programa
   MSGRUN( "Ejecutando calculadora...",, ;
           {|| ShellExecute( ,,"calc.exe",,, )} )

   WHILE nLoop <= ::nTime
      // Handle de la aplicación
      ::hwndcalc := FindWindow( 0, ::cTitlecalculator )
      IF ::hwndcalc <> 0
         EXIT
      ENDIF
      ::hwndcalc := FindWindow( ::cClassName, 0 )
      IF ::hwndcalc <> 0
         EXIT
      ENDIF
      SYSREFRESH()
      nLoop += 1
   ENDDO

   // Ocultando la calculadora
   ShowWindow( ::hwndcalc, 0 )

   // Recupera el ancho y alto del área cliente
   aRect := GetClientRect( ::hwndcalc )

   // Redimensiona el picturebox al ancho y alto del programa
   ::ocontainer:nWidth  := ( aRect[4] - aRect[2] ) // + 25
   ::ocontainer:nHeight := ( aRect[3] - aRect[1] ) // + 55

   // Elimina la barra de título, los menúes y lo incrusta
   ::Eliminar_Menu( ::hwndcalc )
   ::Barra_Titulo( ::hwndcalc, .t. )
   ::Incrustar( ::hwndcalc )
   UpdateWindow( ::hwndcalc )
   ::ocontainer:refresh()
   ::setfocus( ::hwndcalc )

   RETURN NIL

/*******************************************************************/


Esperemos ahora si funcione, espero tus comentarios
William, Morales

Saludos



méxico.sureste
Posts: 1076
Joined: Fri Oct 07, 2005 10:41 PM
Incrustar CALCULADORA en FWH
Posted: Sun Nov 02, 2008 12:46 AM
Amigos,

una actualización de la clase, pero ahora pudiendo incrustar cualquier aplicación de windows, coloco el ejemplo del TEST y la modificación de la propia clase.

espero sus comentarios, aquí los códigos correspondientes.

Primero el test.
#include "fivewin.ch"

FUNCTION main()
   LOCAL oBmp
   LOCAL tWExec32
   LOCAL lSalir := .f.
   LOCAL oBtn
   LOCAL oTest

   tWExec32 := TWExecute()
   tWExec32:cNameApplication  := "NOTEPAD.EXE"
   tWExec32:cTitleApplication := "Sin título - Bloc de notas"
   DEFINE DIALOG oDlg RESOURCE "RECURSOEXEC" TITLE ".:: Execute application ::." COLOR CLR_BLUE,CLR_WHITE
      REDEFINE BITMAP oBmp ID 401 OF oDlg TRANSPARENT
      REDEFINE BUTTON oBtn ID 301 ACTION (oBtn:disable(), tWExec32:incrustar( oBmp ) )
      REDEFINE BUTTON ID 302 ACTION (tWExec32:cerrar(), lSalir := .t., ;
                                     oDlg:END())
      REDEFINE BUTTON ID 303 ACTION (UpdateWindow( tWExec32:hwndexec ), oBmp:refresh())
   ACTIVATE DIALOG oDlg VALID lSalir

   RETURN NIL


Aquí la clase modificada.
/*
   Tomado: Recursos visualbasic
   Fecha:  31 . octubre . 2008
   Hora:   02.48

   INCOS, wmormar
*/

#include "fivewin.ch"

   // Constante para la llamada dinámica del API
#define DC_CALL_STD            0x0020

#define SHOWMAXIMIZED_eSW      3
   // Constante para usar con el Api DeleteMenu
#define MF_BYPOSITION          0x400
#define MF_REMOVE              0x1000

   // Constante para usar con el Api SendMessage para cerrar
   // la aplicación ( en este caso La calculadora )
#define SC_CLOSE              61536
#define WM_SYSCOMMAND         274

   // Constante para usar con GetWindowLong y SetWindowLong
#define GWL_STYLE             -16

   // Constantes para SetWindowPos
#define SWP_FRAMECHANGED      0x0020
#define SWP_NOMOVE            0x0002
#define SWP_NOSIZE            0x0001
#define SWP_NOZORDER          0x0004
#define HWND_TOP              0

CLASS TWExecute
   // Mantiene el Handle del programa
   DATA hwnd                 AS NUMERIC    INIT NIL
   DATA hwndexec             AS NUMERIC    INIT NIL
   DATA cNameApplication     AS CHARACTER  INIT  "calc.exe"
   DATA cTitleApplication    AS CHARACTER  INIT  "Calculadora"
   DATA cClassName           AS CHARACTER  INIT  "SciCalc"
   DATA ocontainer           AS OBJECT     INIT NIL
   DATA nTime                AS NUMERIC    INIT 25000

   METHOD normal()
   METHOD barra_titulo( lErase )
   METHOD Eliminar_Menu( hwnd )
   METHOD Cerrar( hwnd )
   METHOD incrustar( ocontainer )
   METHOD Incrustar_Application( hwnd )
   METHOD GetMenu( hwnd )
   METHOD DeleteMenu( hmenu, nposition, wflags )
   METHOD GetMenuItemCount( hmenu )
   METHOD DrawMenuBar( hwnd )
   METHOD GetWindowLong( hwnd, nindex )
   METHOD SetWindowLong( hwnd, nindex, dwnewlong )
   METHOD SetWindowPos( hwnd, hwndinsertafter, x, y, cx, cy, wflags )
   METHOD setfocus( hwnd )

ENDCLASS

/*******************************************************************/
// Cargando calculadora normal de windows
METHOD normal()
   ShellExecute( ::hwnd,,"calc.exe",,, )

   RETURN NIL

/*******************************************************************/
// Elimina y reestablece la barra de título de una ventana
METHOD barra_titulo( hwnd, lErase )
   LOCAL nStyle

   // Almacena en la variable el estilo actual
   nStyle := ::GetWindowLong( hwnd, GWL_STYLE )

   IF !lErase
      nStyle := nor( nStyle, WS_CAPTION )
   ELSE
      nStyle += nor( WS_CAPTION )
   ENDIF

   // Aplica el nuevo estilo
   ::SetWindowLong( hwnd, GWL_STYLE, nStyle )

   // Mueve de posición la calculadora
   ::SetWindowPos( ::hwndexec, HWND_TOP, 0, 0, 0, 0 )

   RETURN NIL

/*******************************************************************/
//Elimina el menú de una ventana específica
METHOD Eliminar_Menu( hwnd )
   LOCAL hmenu
   LOCAL nmenu
   LOCAL i

   // Recuper el hwnd del menu del programa
   hmenu := ::GetMenu( hwnd )
   IF hmenu <> 0
      // cantidad de menúes
      nmenu := ::GetMenuItemCount( hmenu )
      IF nmenu > 0
         // Recorre todos los menú y los elimina
         FOR i := 1 To nmenu
            ::DeleteMenu( hmenu, 0, nor(MF_BYPOSITION, MF_REMOVE) )
         NEXT

         // Repinta la barra de menú
         ::DrawMenuBar( hwnd )
      ENDIF
   ENDIF

   RETURN NIL

/*******************************************************************/
// Cierra
METHOD Cerrar( hwnd )
   DEFAULT hwnd := ::hwndexec

   // Libera el programa
   SetParent( hwnd, 0 )

   // Cierra el programa abierto, en este caso la calculadora
   SendMessage( hwnd, WM_SYSCOMMAND, SC_CLOSE, 0& )

   // Coloca los Handle a NIL
   hwnd := NIL

   RETURN .t.

/*******************************************************************/
// mete la ventana en el contenedor
METHOD incrustar( ocontainer )
   LOCAL aRect := {}
   LOCAL nLoop := 0

   ::ocontainer := ocontainer

   // Handle de la aplicación
   ::hwndexec := FindWindow( 0, ::cTitleApplication )
   IF ::hwndexec > 0
      ::Cerrar( ::hwndexec )
      ::hwndexec := NIL
   ENDIF

   // Abre el programa
   MSGRUN( "Ejecutando aplicación...",, ;
           {|| ShellExecute( ,,::cNameApplication,,, )} )

   WHILE nLoop <= ::nTime
      // Handle de la aplicación
      ::hwndexec := FindWindow( 0, ::cTitleApplication )
      IF ::hwndexec <> 0
         EXIT
      ENDIF
      ::hwndexec := FindWindow( ::cClassName, 0 )
      IF ::hwndexec <> 0
         EXIT
      ENDIF
      SYSREFRESH()
      nLoop += 1
   ENDDO

   // Ocultando la calculadora
   ShowWindow( ::hwndexec, 0 )

   // Recupera el ancho y alto del área cliente
   aRect := GetClientRect( ::hwndexec )

   // Redimensiona el picturebox al ancho y alto del programa
   ::ocontainer:nWidth  := ( aRect[4] - aRect[2] )
   ::ocontainer:nHeight := ( aRect[3] - aRect[1] )

   // Elimina la barra de título, los menúes y lo incrusta
   ::Eliminar_Menu( ::hwndexec )
   ::Barra_Titulo( ::hwndexec, .t. )
   ::Incrustar_Application( ::hwndexec )
   UpdateWindow( ::hwndexec )
   ::ocontainer:refresh()
   ::setfocus( ::hwndexec )

   RETURN NIL

/*******************************************************************/
METHOD Incrustar_Application( hwnd )
   LOCAL nret

   // Lo metemos dentro del ocontainer
   SetParent( hwnd, ::ocontainer:hwnd )

   // Maximizamos la ventana incrustada dentro del contenedor, mediante el _
   // Api showWindow, pasándole la constante SHOWMAXIMIZED_eSW
   nret := ShowWindow( hwnd, SHOWMAXIMIZED_eSW )

   RETURN .t.

/*******************************************************************/
// Recupera el Hwnd de un menú
METHOD GetMenu( hwnd )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;      // external DLL
                    DC_CALL_STD    , ;      // calling convention
                    "GetMenu" )             // external function

   nRet := DllExecuteCall( pCallTemplate, hwnd )

   RETURN nRet

/*******************************************************************/
// Elimina el menú de una aplicación
METHOD DeleteMenu( hmenu, nposition, wflags )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "DeleteMenu" )

   nRet := DllExecuteCall( pCallTemplate, hmenu, nposition, wflags )

   RETURN nRet

/*******************************************************************/
// Recupera la cantidad de Item de menúes para saber cuantos hay que eliminar
METHOD GetMenuItemCount( hmenu )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "GetMenuItemCount" )

   nRet := DllExecuteCall( pCallTemplate, hmenu )

   RETURN nRet

/*******************************************************************/
// Redibuja - repinta la barra de menú luego de eliminarlo
METHOD DrawMenuBar( hwnd )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "DrawMenuBar" )

   nRet := DllExecuteCall( pCallTemplate, hwnd )

   RETURN nRet

/*******************************************************************/
// Estas tres funciones es para eliminar la barra de título
// del programa que se va a incrustar
METHOD GetWindowLong( hwnd, nindex )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "GetWindowLongA" )

   nRet := DllExecuteCall( pCallTemplate, hwnd, nindex )

   RETURN nRet

/*******************************************************************/
METHOD SetWindowLong( hwnd, nindex, dwnewlong )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "SetWindowLongA" )

   nRet := DllExecuteCall( pCallTemplate, hwnd, nindex, dwnewlong )

   RETURN nRet

/*******************************************************************/
METHOD SetWindowPos( hwnd, hwndinsertafter, x, y, cx, cy, wflags )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "SetWindowPos" )

   nRet := DllExecuteCall( pCallTemplate, hwnd, hwndinsertafter, x, y, cx, cy, wflags )

   RETURN nRet

/*******************************************************************/
METHOD setfocus( hwnd )
   LOCAL pCallTemplate
   LOCAL nRet

   // create call template on first call
   pCallTemplate := DllPrepareCall(  ;
                    "user32.dll"   , ;
                    DC_CALL_STD    , ;
                    "SetFocus" )

   nRet := DllExecuteCall( pCallTemplate, hwnd )

   RETURN nRet

/*******************************************************************/


Bueno, espero comentarios.
William, Morales

Saludos



méxico.sureste

Continue the discussion