Cobol Foro
Navegación en el Foro
Retroceder   Cobol Foro Entornos de desarrollo y compiladores Cobol Fujitsu COBOL PowerCOBOL (ActiveX, v4 - v11)
PowerCOBOL (ActiveX, v4 - v11) Versiones del IDE basadas en ActiveX
 
Otros temas que te pueden interesar
Tema Autor Foro Respuestas Último post
[Sintaxis] Cerrar .dbf desde power Breew PowerCOBOL (ActiveX, v4 - v11) 9 15 de septiembre de 2021 15:45
[Duda] Minimizar ventana padre desde la ventana hijo Roger PowerCOBOL (ActiveX, v4 - v11) 7 7 de julio de 2017 22:06
[Programa] SMS_CMD : Utilidad para enviar SMS por consola Dasije Compra-Venta 0 21 de marzo de 2017 17:21
[Sintaxis] Desactivar la [X] de cerrar ventana Ciro PowerCOBOL (ActiveX, v4 - v11) 3 28 de octubre de 2015 13:26
[Duda] Problemas al cerrar el PREVIEW -SOLUCIONADO- Josber PowerFORM 6 3 de agosto de 2015 09:32

Respuesta
 
Herramientas

  #1
Antiguo 14 de junio de 2019, 14:10
Fito
Guardián del Foro
Agradecimientos: Por muchos agradecimientos de parte de los Foreros - Issue reason: Por muchos agradecimientos de parte de los Foreros Guardián del Foro: Guardián del espíritu y clima del Foro - Issue reason: Por el Avatar Activista del Foro: Activista del Foro - Issue reason: Por aportar ideas 
Última Actividad 19.09.2026 13:19
Posts Posts: 458
Likes enviados Enviados: 267
Likes recibidos Recibidos: 243
Tableta Cerrar ventana de consola...
0 Inactivo Inactivo

Hola Amigos:

Para ciertos procesos me queda muy cómodo hacer display y que me vaya mostrando en la consola. Hay alguna manera de poder decirle por programa que la consola se cierre?

Saludos.

Fito...
Fito is offline   Responder Con Cita
  #2
Antiguo 14 de junio de 2019, 20:19
Kuk
Administrador
Última Actividad 19.09.2026 20:11
Posts Posts: 2.500
Likes enviados Enviados: 1037
Likes recibidos Recibidos: 1207

Fito, por programa no se puede.

Puedes intentarlo vía WinAPI, con la función FindWindow y luego pasarle WM_CLOSE por CallWindowProc.



NORMAS DEL FORO - para garantizar el buen funcionamiento del Foro.
¿Te han ayudado? NO TE OLVIDES de darle a
¿Quieres dirigirte a alguien en tu post? Notifícale haciendo clic en su Nick
Kuk is offline   Responder Con Cita
  #3
Antiguo 27 de agosto de 2019, 20:45
dmosca
Forero
Última Actividad 07.07.2022 13:19
Posts Posts: 69
Likes enviados Enviados: 32
Likes recibidos Recibidos: 3

Kuk buenas tardes.

tambien necesito cerrar la consola, pero no tengo experiencia con WinApi...

por favor podrias explicar como hacer el cierre de consola o donde tengo info para investigar

muchas gracias
saludos
dmosca is offline   Responder Con Cita
  #4
Antiguo 29 de agosto de 2019, 15:28
fastpho
El Foro es mi casa
Innovación: Por aportar innovaciones - Issue reason: SQLite + OO Cobol class Concurso: Primer puesto: Ganador/a del Primer puesto en un concurso - Issue reason: Acceso a datos Cobol vía web 
Última Actividad 21.08.2026 18:08
Posts Posts: 365
Likes enviados Enviados: 252
Likes recibidos Recibidos: 243

Buenas voy a subir un ejemplo de como cerrar programas abierto , por ejemplo la calculadora de windows , la idea era para ver si se podia cerrar la consola de cobol , pero al interntar cerrarla fuerza la salida
Special-Name
Código COBOL:
  1.         symbolic constant
  2.             gw_hwndfirst    is 0
  3.             gw_hwndnext     is 2
  4.         .
Código COBOL:
  1. Working
  2. *
  3. * You must pass this subroutine 4 parameters:
  4. *
  5. *       TITLE-BAR-STRING = PIC X(1024) = The text of the title bar of the window to locate
  6. *
  7. *
  8. *       FOUND-WINDOW-SW PIC 9(4) COMP-5 = 0 = Did not find the window
  9. *                                       = 1 = Found the window
  10. *
  11. *       FOUND-WINDOW-HANDLE PIC S(9) COMP-5 = If the window is found, this is the handle to it
  12. *
  13. *       RETURN-VALUE PIC S9(9) COMP-5 = Success or failure
  14. *                                     = 0 = Normal completion
  15. *                                     = 1 = Did not pass a title bar string
  16. *                                     = 2 = Could not get the handle to this window
  17. *                                     = 3 = Could not get the handle of the first window
  18.  
  19.  01 get-this-window-handle is global.
  20.         05  this-window-handle          pic s9(9)   comp-5  value 0.
  21.         05  filler                      pic x(12)           value spaces.
  22.        
  23.  01 title-bar-search-string         pic x(1025)         value spaces is global.
  24.  01 title-bar-index                 pic 9(9)    comp-5  value 0 is global.
  25.  
  26.  01 child-window-handle             pic s9(9)   comp-5  value 0 is global.
  27.  01 parent-window-handle            pic s9(9)   comp-5  value 0 is global.
  28.  
  29.  01 length-of-title-bar-buffer      pic s9(9)   comp-5 is global.
  30.  01 title-bar-buffer-max            pic s9(9)   comp-5 is global.
  31.  01 title-bar-buffer                pic x(1025)         value spaces is global.            
  32.        
  33.  01 hwnd-type                       pic 9(9)    comp-5 is global.
  34.            
  35.  01     null-value                      pic s9(9)   comp-5  value 0 is global.
  36. *----------
  37.  01 title-bar-string                pic x(1024) is global external.
  38.  01 found-window-sw                 pic 9(4)    comp-5 is global external.
  39.  01 found-window-handle             pic s9(9)   comp-5 is global external.
  40.  01 return-value                    pic s9(9)   comp-5 is global external.
  41.    
Código COBOL:
  1. WORKING-STORAGE SECTION.
  2. * You must pass this subroutine 4 parameters:
  3. *
  4. *       TITLE-BAR-STRING = PIC X(1024) = The text of the title bar of the window to locate
  5. *
  6. *
  7. *       FOUND-WINDOW-SW PIC 9(4) COMP-5 = 0 = Did not find the window
  8. *                       = 1 = Found the window
  9. *
  10. *       FOUND-WINDOW-HANDLE PIC S(9) COMP-5 = If the window is found, this is the handle to it
  11. *
  12. *       RETURN-VALUE PIC S9(9) COMP-5 = Success or failure
  13. *                         = 0 = Normal completion
  14. *                     = 1 = Did not pass a title bar string
  15. *                         = 2 = Could not get the handle to this window
  16. *                         = 3 = Could not get the handle of the first window
  17.  
  18.  PROCEDURE       DIVISION.
  19.           move 0 to return-value
  20.         move 0 to found-window-sw
  21.         move 0 to found-window-handle
  22.        
  23.         compute title-bar-buffer-max = function length(title-bar-buffer)
  24.           MOVE  title-bar-string TO "Caption" OF CmStatic1
  25.           INVOKE CmStatic1 "Refresh"
  26. * Let's make sure they passed the title bar string
  27. *
  28.         if title-bar-string not > " "
  29.             move 1 to return-value
  30.                   INVOKE    POW-SELF "CloseForm"
  31.             exit program
  32.         end-if
  33. *
  34. * Let's get the handle of this window
  35. *
  36.         call "GetTopWindow" with STDCALL using
  37.             by value null-value
  38.             returning this-window-handle
  39. *
  40. * Now, let's find the length of the search string
  41. *
  42.         move title-bar-string to title-bar-search-string
  43.         perform varying title-bar-index from 1025 by -1
  44.                 until title-bar-search-string(title-bar-index:1) not = " "
  45.             continue
  46.         end-perform
  47. *
  48. * Now, let's get the first window
  49. *
  50.         move gw_hwndfirst to hwnd-type
  51.         call "GetWindow" with STDCALL using
  52.             by value this-window-handle
  53.             by value hwnd-type
  54.             returning child-window-handle
  55.         if child-window-handle = 0
  56.             move 3 to return-value
  57.                   INVOKE    POW-SELF "CloseForm"           
  58.             exit program
  59.         end-if
  60.        
  61.         move gw_hwndnext to hwnd-type  
  62. *
  63. * Now, let's see if this is the target window, if not, loop through all open windows
  64. *
  65.         perform until child-window-handle = 0
  66. *
  67. * Let's get the title bar text of this window
  68. *
  69.             call "GetWindowTextA" with STDCALL using
  70.                 by value child-window-handle
  71.                 by reference title-bar-buffer              
  72.                 by value title-bar-buffer-max
  73.                 returning length-of-title-bar-buffer        *> Note, the length returned does NOT include the NULL byte
  74. *
  75. * If the window has a title bar, is it the one we're looking for?
  76. *              
  77.             if length-of-title-bar-buffer > 0
  78.                 if title-bar-search-string(1:title-bar-index) = title-bar-buffer(1:title-bar-index)
  79.                     move 1 to found-window-sw
  80.                     move child-window-handle to found-window-handle
  81.                     move "encontrado" to "Caption" OF CmStatic2
  82.                     INVOKE CmStatic2 "Refresh"
  83.                         move 0 to return-value
  84.                             INVOKE  POW-SELF "CloseForm"                   
  85.                     exit program
  86.                 end-if
  87.             end-if
  88. *
  89. * Get the next window
  90. *
  91.             move child-window-handle to this-window-handle
  92.            
  93.             call "GetWindow" with STDCALL using
  94.                 by value this-window-handle
  95.                 by value hwnd-type
  96.                 returning child-window-handle
  97.        
  98.         end-perform
  99. *
  100. * Didn't find the window
  101. *
  102.                     move "no encontrado" to "Caption" OF CmStatic2
  103.                     INVOKE CmStatic2 "Refresh"
  104.  
  105.         move 0 to return-value
  106.     move 0 to found-window-sw
  107.         move 0 to found-window-handle
  108.           INVOKE    POW-SELF "CloseForm"       
  109.           exit program
  110.         .                                  
  111.                                    
Estas lineas deberian ir en prg que in mi caso se llama findwindow.dll
y lo que hace es buscar el titulo de la ventana a buscar en el parametro title-bar-string
Luego desde otro programa lleno esa variable y en un timer sale a buscar si existe tal programa.
objeto timer coloco estas lineas
Código COBOL:
  1.          move 0 to found-window-sw
  2.         move 0 to found-window-handle
  3.         move 0 to return-value
  4. *         MOVE "Console : PRUEBA" TO title-bar-string
  5.           MOVE "Calculadora" TO title-bar-string       
  6.           INVOKE POW-SELF "OpenForm" USING "FINDWINDOW" "FINDWINDOW.DLL".
  7.          
  8.            
  9.         if return-value not = 0
  10. *           display "Error - FINDWINDOW failed"
  11.             move return-value to display-return-value
  12. *           display "Return-value = " , display-return-value
  13.            
  14.                   EXIT PROGRAM
  15.         end-if.
  16.         if found-window-sw = 1
  17.                 display "EL PROGRAMA SE ESTA EJECUTANDO"
  18.             display "found-window-handle" , found-window-handle
  19.             EXIT PROGRAM
  20.            
  21.         end-if.
  22.         if found-window-sw = 0
  23.             display "EL PROGRAMA NO  SE ESTA EJECUTANDO"
  24.             display "found-window-handle" , found-window-handle
  25.             EXIT PROGRAM
  26.            
  27.         end-if.
Genero un boton que cierra tal programa
Código COBOL:
  1.  ENVIRONMENT     DIVISION.
  2.  DATA            DIVISION.
  3.  WORKING-STORAGE SECTION.
  4. *private Const SC_CLOSE = &HF060&
  5. *Private Const WM_SYSCOMMAND = &H112
  6.  01     null-value  pic s9(9)   comp-5  value 0 .
  7.  PROCEDURE       DIVISION.
  8. *cierro el programa
  9.  
  10.        call "SendMessageA" with STDCALL using
  11.                 by value found-window-handle
  12.                 by value WM_SYSCOMMAND             
  13.                 by value SC_CLOSE
  14.                           by value null-value.
  15.                          
Espero haber sido claro ....
Saludos
fastpho is offline   Responder Con Cita
  #5
Antiguo 29 de agosto de 2019, 20:34
dmosca
Forero
Última Actividad 07.07.2022 13:19
Posts Posts: 69
Likes enviados Enviados: 32
Likes recibidos Recibidos: 3

Gracias por responder

voy a aplicarlo...

informo como resulta.

saludos

---------- Post añadido : 15:34 ---------- Post anterior : 14:43 ----------

1ª consulta

que libreria debo cargar para poder compilar?
dmosca is offline   Responder Con Cita
  #6
Antiguo 29 de agosto de 2019, 22:20
fastpho
El Foro es mi casa
Innovación: Por aportar innovaciones - Issue reason: SQLite + OO Cobol class Concurso: Primer puesto: Ganador/a del Primer puesto en un concurso - Issue reason: Acceso a datos Cobol vía web 
Última Actividad 21.08.2026 18:08
Posts Posts: 365
Likes enviados Enviados: 252
Likes recibidos Recibidos: 243

dmosca, La libreria es user32.lib y me olvide de poner el valor
de
Código COBOL:
  1.     symbolic constant
  2.                SC_CLOSE                         is 61536
  3.             WM_SYSCOMMAND       is 274
  4.         .
fastpho is offline   Responder Con Cita
  #7
Antiguo 29 de agosto de 2019, 22:30
dmosca
Forero
Última Actividad 07.07.2022 13:19
Posts Posts: 69
Likes enviados Enviados: 32
Likes recibidos Recibidos: 3

fastpho: este es el error:

Código:
Compile resource C:\Cuadros\Main\Debug\Main.rc ...

Linking C:\Cuadros\Debug\Main.exe ...
Cerrar.obj : error LNK2001: unresolved external symbol _GETWINDOWTEXTA@12
Cerrar.obj : error LNK2001: unresolved external symbol _GETWINDOW@8
Cerrar.obj : error LNK2001: unresolved external symbol _GETTOPWINDOW@4
C:\Cuadros\Debug\Main.exe : fatal error LNK1120: 3 unresolved externals

** The build has failed **
dmosca is offline   Responder Con Cita
  #8
Antiguo 29 de agosto de 2019, 23:48
fastpho
El Foro es mi casa
Innovación: Por aportar innovaciones - Issue reason: SQLite + OO Cobol class Concurso: Primer puesto: Ganador/a del Primer puesto en un concurso - Issue reason: Acceso a datos Cobol vía web 
Última Actividad 21.08.2026 18:08
Posts Posts: 365
Likes enviados Enviados: 252
Likes recibidos Recibidos: 243

dmosca, en las opcion de compilacion te debe faltar ALPHAL(WORD)
fastpho is offline   Responder Con Cita
Respuesta



Derechos de Publicación
No puedes publicar nuevos temas
No puedes publicar posts/responder
No puedes adjuntar archivos
No puedes editar tus posts

BB code is habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado

Saltar a Foro


La franja horaria es GMT +2. Ahora son las 15:01.
Powered by: vBulletin, Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.