18 de junio de 2018

Manipular Ventanas desde VFP - Parte 2

En Esta Ocasion envio un Formulario que permite modificar el tamaño y la posicion de una ventana cualquiera desde VFP, y para variar por medio de APIs.

DEFINE CLASS cambia_ventanas AS form
 Height = 158
 Width = 351
 ShowWindow = 2
 DoCreate = .T.
 AutoCenter = .T.
 BorderStyle = 2
 Caption = "Manipulando Ventanas 2"
 TitleBar = 0
 Name = "Cambia_Ventanas"

 ADD OBJECT salir AS commandbutton WITH ;
  Top = 120, ;
  Left = 176, ;
  Height = 27, ;
  Width = 84, ;
  FontBold = .T., ;
  Caption = "Salir", ;
  TabIndex = 13, ;
  ForeColor = RGB(239,58,58), ;
  Name = "Salir"

 ADD OBJECT texto AS textbox WITH ;
  Height = 23, ;
  Left = 98, ;
  TabIndex = 3, ;
  Top = 36, ;
  Width = 240, ;
  Name = "texto"

 ADD OBJECT label1 AS label WITH ;
  AutoSize = .T., ;
  FontBold = .T., ;
  Caption = "Caption", ;
  Height = 17, ;
  Left = 14, ;
  Top = 39, ;
  Width = 45, ;
  TabIndex = 2, ;
  ForeColor = RGB(50,41,218), ;
  Name = "Label1"

 ADD OBJECT cx AS textbox WITH ;
  Alignment = 3, ;
  Value = 0, ;
  Format = "k", ;
  Height = 23, ;
  InputMask = "999,999", ;
  Left = 98, ;
  TabIndex = 5, ;
  Top = 60, ;
  Width = 72, ;
  Name = "cX"

 ADD OBJECT label2 AS label WITH ;
  AutoSize = .T., ;
  FontBold = .T., ;
  Caption = "Posicicion X", ;
  Height = 17, ;
  Left = 14, ;
  Top = 63, ;
  Width = 72, ;
  TabIndex = 4, ;
  ForeColor = RGB(50,41,218), ;
  Name = "Label2"

 ADD OBJECT cy AS textbox WITH ;
  Alignment = 3, ;
  Value = 0, ;
  Format = "k", ;
  Height = 23, ;
  InputMask = "999,999", ;
  Left = 266, ;
  TabIndex = 7, ;
  Top = 60, ;
  Width = 72, ;
  Name = "cY"

 ADD OBJECT label4 AS label WITH ;
  AutoSize = .T., ;
  FontBold = .T., ;
  Caption = "Posicicion Y", ;
  Height = 17, ;
  Left = 194, ;
  Top = 63, ;
  Width = 71, ;
  TabIndex = 6, ;
  ForeColor = RGB(50,41,218), ;
  Name = "Label4"

 ADD OBJECT ancho AS textbox WITH ;
  Alignment = 3, ;
  Value = 0, ;
  Format = "k", ;
  Height = 23, ;
  InputMask = "999,999", ;
  Left = 98, ;
  TabIndex = 9, ;
  Top = 86, ;
  Width = 72, ;
  Name = "ancho"

 ADD OBJECT label3 AS label WITH ;
  AutoSize = .T., ;
  FontBold = .T., ;
  Caption = "Ancho", ;
  Height = 17, ;
  Left = 14, ;
  Top = 89, ;
  Width = 38, ;
  TabIndex = 8, ;
  ForeColor = RGB(50,41,218), ;
  Name = "Label3"

 ADD OBJECT alto AS textbox WITH ;
  Alignment = 3, ;
  Value = 0, ;
  Format = "k", ;
  Height = 23, ;
  InputMask = "999,999", ;
  Left = 266, ;
  TabIndex = 11, ;
  Top = 86, ;
  Width = 72, ;
  Name = "alto"

 ADD OBJECT label5 AS label WITH ;
  AutoSize = .T., ;
  FontBold = .T., ;
  Caption = "Alto", ;
  Height = 17, ;
  Left = 194, ;
  Top = 89, ;
  Width = 24, ;
  TabIndex = 10, ;
  ForeColor = RGB(50,41,218), ;
  Name = "Label5"

 ADD OBJECT label6 AS label WITH ;
  FontBold = .T., ;
  FontSize = 12, ;
  Alignment = 2, ;
  BackStyle = 0, ;
  Caption = "Manipulando Ventanas 2", ;
  Height = 26, ;
  Left = 3, ;
  Top = 4, ;
  Width = 346, ;
  TabIndex = 1, ;
  ColorSource = 0, ;
  ForeColor = RGB(26,62,206), ;
  BackColor = (thisform.backcolor), ;
  Name = "Label6"

 ADD OBJECT cambiar AS commandbutton WITH ;
  Top = 120, ;
  Left = 90, ;
  Height = 27, ;
  Width = 84, ;
  FontBold = .T., ;
  Caption = "Cambiar", ;
  TabIndex = 12, ;
  ForeColor = RGB(239,58,58), ;
  Name = "Cambiar"

 PROCEDURE salir.Click
  thisform.Release
 ENDPROC

 PROCEDURE cambiar.Click
  Local handle As Long
  Declare Long MoveWindow In "user32" Long HWnd, Long x, Long Y, Long nWidth, Long nHeight, Long bRepaint
  Declare Long FindWindow In "User32" String Clase, String texto
  Declare long IsWindowEnabled IN "user32" long HWnd 
  With Thisform
   handle = FindWindow(.Null.,Alltrim(.texto.Value))
   If handle =0
    Wait Window "Ventana No Encontrada..."
    Return
   Endif
   MoveWindow(handle, .cX.Value, .cY.Value, .ancho.Value, .alto.Value, 1)
   IsWindowEnabled(handle)
  Endwith
 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.