En esta ocasión envío un pequeño programa que nos permite habilitar /deshabilitar cualquier ventana buscándola por medio de su Caption, y también podemos cambiar el Caption de cualquier ventana!!!
Al Deshabilitar una ventana no podremos dar Click ni escribir nada en esa ventana, ni siquiera restaurarla o maximizarla, cerrarla, moverla, minimizarla, etc. (útil si queremos que no puedan cerrar X ventana mientras corremos un proceso)
Solo hay que tener cuidado cuando busquen la ventana, tiene que ir exactamente igual que como aparece en el título de la misma, mayúsculas y minúsculas.
Aquí el código:
Public oFormulario
oFormulario=Newobject("Ventanas")
oFormulario.Show
Return
Define Class Ventanas As Form
Top = 118
Left = 121
Height = 177
Width = 465
DoCreate = .T.
Caption = "Manipulando Ventanas desde VFP"
Name = "Manipula_Ventanas"
Add Object deshabilita As CommandButton With ;
Top = 136, ;
Left = 24, ;
Height = 27, ;
Width = 84, ;
Caption = "Deshabilitar", ;
TabIndex = 5, ;
Name = "deshabilita"
Add Object Titulo_ventana As TextBox With ;
BackStyle = 1, ;
Height = 23, ;
Left = 24, ;
TabIndex = 2, ;
Top = 30, ;
Width = 420, ;
Name = "Titulo_ventana"
Add Object Habilitar As CommandButton With ;
Top = 136, ;
Left = 108, ;
Height = 27, ;
Width = 84, ;
Caption = "Habilitar", ;
TabIndex = 6, ;
Name = "Habilitar"
Add Object label1 As Label With ;
AutoSize = .T., ;
FontBold = .T., ;
BackStyle = 0, ;
Caption = "Titulo de La Ventana ", ;
Height = 17, ;
Left = 24, ;
Top = 6, ;
Width = 120, ;
TabIndex = 1, ;
Name = "Label1"
Add Object Nuevo_Titulo As TextBox With ;
BackStyle = 1, ;
Height = 23, ;
Left = 24, ;
TabIndex = 3, ;
Top = 77, ;
Width = 420, ;
Name = "Nuevo_Titulo"
Add Object Cambiar As CommandButton With ;
Top = 136, ;
Left = 192, ;
Height = 27, ;
Width = 84, ;
Caption = "Cambiar", ;
TabIndex = 7, ;
Name = "Cambiar"
Add Object Estado As Label With ;
AutoSize = .T., ;
BackStyle = 0, ;
Caption = "Estado de la Ventana:", ;
Height = 17, ;
Left = 24, ;
Top = 112, ;
Width = 122, ;
TabIndex = 4, ;
Name = "Estado",;
Tag ="Estado de la Ventana:"
Add Object label3 As Label With ;
AutoSize = .T., ;
FontBold = .T., ;
BackStyle = 0, ;
Caption = "Nuevo Titulo para la Ventana ", ;
Height = 17, ;
Left = 24, ;
Top = 58, ;
Width = 166, ;
TabIndex = 1, ;
Name = "Label3"
Procedure Load
Declare Long IsWindowEnabled In "user32" Long handle
Declare Long EnableWindow In "user32" Long handle, Long fEnable
Declare Integer FindWindow In WIN32API String cNULL, String cWinName
Declare Long SetWindowText In "user32" Long handel, String lpString
Endproc
Procedure deshabilita.Click
Local Estado, retval As Long, handle As Long
handle = FindWindow(.Null.,Alltrim(Thisform.Titulo_ventana.Value))
If handle=0 Or Empty(Thisform.Titulo_ventana.Text)
Wait Window 'Ventana no Encontrada'
Return
Endif
retval = EnableWindow(handle, 0)
Estado= IsWindowEnabled(handle)
If Estado=0
Thisform.Estado.Caption =Alltrim(Thisform.Estado.Tag)+' Deshabilitada'
Else
Thisform.Estado.Caption =Alltrim(Thisform.Estado.Tag)+' Habilitada'
Endif
Endproc
Procedure Habilitar.Click
Local Estado, retval As Long, handle As Long
handle = FindWindow(.Null.,Alltrim(Thisform.Titulo_ventana.Value))
If handle=0 Or Empty(Thisform.Titulo_ventana.Text)
Wait Window 'Ventana no Encontrada'
Return
Endif
retval = EnableWindow(handle, 1)
Estado= IsWindowEnabled(handle)
If Estado=0
Thisform.Estado.Caption =Alltrim(Thisform.Estado.Tag)+' Deshabilitada'
Else
Thisform.Estado.Caption =Alltrim(Thisform.Estado.Tag)+' Habilitada'
Endif
Endproc
Procedure Cambiar.Click
Local Estado, retval As Long, handle As Long
handle = FindWindow(.Null.,Alltrim(Thisform.Titulo_ventana.Value))
If handle=0
Wait Window 'Ventana no Encontrada'
Return
Endif
If Empty(Thisform.Nuevo_Titulo.Text) Or Empty(Thisform.Titulo_ventana.Text)
Wait Window 'Debe escribir un Caption valido'
Return
Endif
SetWindowText(handle, Alltrim(Thisform.Nuevo_Titulo.Text))
Estado= IsWindowEnabled(handle)
If Estado=0
Thisform.Estado.Caption =Alltrim(Thisform.Estado.Tag)+' Deshabilitada'
Else
Thisform.Estado.Caption =Alltrim(Thisform.Estado.Tag)+' Habilitada'
Endif
Endproc
Enddefine
Saludos.
Jorge Mota
No hay comentarios. :
Publicar un comentario
Los comentarios son moderados, por lo que pueden demorar varias horas para su publicación.