elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
29 Mayo 2012, 09:06  


Tema destacado: Recuperar cuenta de Google, GMail, Youtube

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo, raul338)
| | |-+  [Source] WinCenterIn ( Centrar Objetos con respecto a otros ).
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [Source] WinCenterIn ( Centrar Objetos con respecto a otros ).  (Leído 700 veces)
BlackZeroX (Astaroth)
Wiki

Desconectado Desconectado

Mensajes: 2.832


I'Love...!¡.


Ver Perfil WWW
[Source] WinCenterIn ( Centrar Objetos con respecto a otros ).
« en: 9 Marzo 2011, 04:31 »

.
mmm en lugar de solo criticar la funcion pondre una de mi tutela que uso para esto, es decir centrar las cosas por medio de su hWnd, Sirve con:

* Objetos del form ( Botones, frames, etc... ).
* Ventanas ( de la aplicacion o externas ).
* Pantalla  ( Centra el objeto con restecto a la pantalla ).
* Funciona con TODO lo que tenga un hWnd valido.

Codigo Actualizado:

Código
 
'
' ////////////////////////////////////////////////////////////////
' // Autor: BlackZeroX ( Ortega Avila Miguel Angel )            //
' //                                                            //
' // Web: http://InfrAngeluX.Sytes.Net/                         //
' //                                                            //
' // |-> Pueden Distribuir Este Código siempre y cuando         //
' // no se eliminen los créditos originales de este código      //
' // No importando que sea modificado/editado o engrandecido    //
' // o achicado, si es en base a este código                    //
' ////////////////////////////////////////////////////////////////
' //
' ////////////////////////////////////////////////////////////////

Option Explicit
 
Private Type POINTAPI
   x       As Long
   y       As Long
End Type
Private Type RECT
   Left    As Long
   Top     As Long
   Right   As Long
   Bottom  As Long
End Type
 
Enum WS_InCenterOpt
   InScreen = 0
   InObject = 1
   InParent = 2
   InWinExtern = 3
End Enum
 
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
 
Public Function WinCenterIn(ByVal hwnd As Long, Optional ByVal InhWnd As Long = 0, Optional ByVal Opt As WS_InCenterOpt = InParent)
Dim st_retm         As RECT
Dim st_retd         As RECT
Dim st_pt           As POINTAPI
 
   If GetWindowRect(hwnd, st_retm) <> 0 Then
 
       Select Case Opt
 
           Case InObject, InParent, InWinExtern
               If Opt = InParent Then
                   InhWnd = GetParent(hwnd)
                   If InhWnd = 0 Then
                       WinCenterIn = WinCenterIn(hwnd, 0, InScreen)
                   End If
               End If
               If GetWindowRect(InhWnd, st_retd) = 0 Then
                   Exit Function
               End If
 
           Case InScreen
               st_retd.Bottom = GetSystemMetrics(&H1)
               st_retd.Right = GetSystemMetrics(&H0)
 
           Case Else
               Exit Function
 
       End Select
 
       st_pt.x = st_retd.Left + ((st_retd.Right - st_retd.Left) - (st_retm.Right - st_retm.Left)) \ 2
       st_pt.y = st_retd.Top + ((st_retd.Bottom - st_retd.Top) - (st_retm.Bottom - st_retm.Top)) \ 2
 
       If Opt <> InWinExtern Then
           Call ScreenToClient(InhWnd, st_pt)
       End If
 
       WinCenterIn = MoveWindow(hwnd, st_pt.x, st_pt.y, (st_retm.Right - st_retm.Left), (st_retm.Bottom - st_retm.Top), 1) <> 0
 
   End If
 
End Function
 
 

Ejemplo:

Código
 
Option Explicit
 
Private Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
 
Private Sub Command2_Click()
   WinCenterIn Me.hwnd
   WinCenterIn FindWindowA(vbNullString, "Administrador de tareas de Windows"), Me.hwnd, InWinExtern
   'WinCenterIn Me.hwnd, FindWindowA(vbNullString, "Administrador de tareas de Windows"), InWinExtern
End Sub
 
 

Version Anterior:

Código:

'
' ////////////////////////////////////////////////////////////////
' // Autor: BlackZeroX ( Ortega Avila Miguel Angel )            //
' //                                                            //
' // Web: http://InfrAngeluX.Sytes.Net/                         //
' //                                                            //
' // |-> Pueden Distribuir Este Código siempre y cuando         //
' // no se eliminen los créditos originales de este código      //
' // No importando que sea modificado/editado o engrandecido    //
' // o achicado, si es en base a este código                    //
' ////////////////////////////////////////////////////////////////
' //
' ////////////////////////////////////////////////////////////////

Option Explicit

Private Type POINTAPI
    x       As Long
    y       As Long
End Type
Private Type RECT
    Left    As Long
    Top     As Long
    Right   As Long
    Bottom  As Long
End Type

Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long

Public Function WinCenterIn(ByVal hwnd As Long, Optional ByVal InhWnd As Long = 0, Optional ByVal WinExterna As Boolean)
Dim st_retm         As RECT
Dim st_retd         As RECT
Dim st_pt           As POINTAPI


    If GetWindowRect(hwnd, st_retm) = 0 Then
        Exit Function
    End If
   
    If InhWnd = 0 Then
        st_retd.Bottom = GetSystemMetrics(&H1)
        st_retd.Right = GetSystemMetrics(&H0)
    Else
        If GetWindowRect(InhWnd, st_retd) = 0 Then
            Exit Function
        End If
    End If
   
    st_pt.x = st_retd.Left + (Abs((st_retd.Right - st_retd.Left) - (st_retm.Right - st_retm.Left))) \ 2
    st_pt.y = st_retd.Top + (Abs((st_retd.Bottom - st_retd.Top) - (st_retm.Bottom - st_retm.Top))) \ 2
   
    If Not WinExterna And InhWnd = 0 Then
        Call ScreenToClient(InhWnd, st_pt)
    Else
        Call ScreenToClient(InhWnd, st_pt)
        st_pt.x = st_pta.x + st_pt.x
        st_pt.y = st_pta.y + st_pt.y
    End If
    WinCenterIn = MoveWindow(hwnd, st_pt.x, st_pt.y, (st_retm.Right - st_retm.Left), (st_retm.Bottom - st_retm.Top), 1) <> 0
   
End Function


La implementacion es bastante sencilla.

Código
 
WinCenterIn Command1.hwnd, Me.hwnd
WinCenterIn Command1.hwnd, 0
WinCenterIn me.hwnd, 0
 
 

Temibles Lunas!¡.


« Última modificación: 10 Marzo 2011, 02:23 por BlackZeroX▓▓▒▒░░ » En línea

Web Principal-->[ Blog(VB6) | Host File (Public & Private) | Scan Port | (New)MyInfraPC (Descubre mi Contraseña venefi. $) ]



The Dark Shadow is my passion.
El infierno es mi Hogar, mi novia es Lilith y el metal mi
Elemental Code


Desconectado Desconectado

Mensajes: 499


Im beyond the system


Ver Perfil
Re: [Source] WinCenterIn ( Centrar Objetos con rectecto a otros ).
« Respuesta #1 en: 9 Marzo 2011, 18:55 »

se esfuerzan en hacerme quedar como pelotud* ustedes  :xD :xD :xD

Bien ahi por un codigo que ande  ;)


En línea

raul338
Moderador
***
Desconectado Desconectado

Mensajes: 2.372


La sonrisa es la mejor forma de afrontar las cosas


Ver Perfil WWW
Re: [Source] WinCenterIn ( Centrar Objetos con rectecto a otros ).
« Respuesta #2 en: 9 Marzo 2011, 19:29 »

Código
... en un segundo lo ponmgo jaja puse uno erroneo.
 
Última modificación: Hoy a las 00:46

Que segundos mas laargos :xD

se esfuerzan en hacerme quedar como pelotud* ustedes  :xD :xD :xD
jajajaj :xD siempre queremos darle el toque "codigo reutilizable cueste lo que cueste" (caphishi)
En línea

BlackZeroX (Astaroth)
Wiki

Desconectado Desconectado

Mensajes: 2.832


I'Love...!¡.


Ver Perfil WWW
Re: [Source] WinCenterIn ( Centrar Objetos con rectecto a otros ).
« Respuesta #3 en: 10 Marzo 2011, 01:35 »


@Elemental Code

lo que pasa que tu codigo me dejo mucho que desear, dejo uno pero aun le falta unos toques extras, pero bueno.

Temibles Lunas!¡.
En línea

Web Principal-->[ Blog(VB6) | Host File (Public & Private) | Scan Port | (New)MyInfraPC (Descubre mi Contraseña venefi. $) ]



The Dark Shadow is my passion.
El infierno es mi Hogar, mi novia es Lilith y el metal mi
BlackZeroX (Astaroth)
Wiki

Desconectado Desconectado

Mensajes: 2.832


I'Love...!¡.


Ver Perfil WWW
Re: [Source] WinCenterIn ( Centrar Objetos con rectecto a otros ).
« Respuesta #4 en: 10 Marzo 2011, 02:01 »

.
Dejo otra version en el hilo principal, esta mas depurada y mas funcional que la primera.

Temibles Lunas!¡.
« Última modificación: 10 Marzo 2011, 02:16 por BlackZeroX▓▓▒▒░░ » En línea

Web Principal-->[ Blog(VB6) | Host File (Public & Private) | Scan Port | (New)MyInfraPC (Descubre mi Contraseña venefi. $) ]



The Dark Shadow is my passion.
El infierno es mi Hogar, mi novia es Lilith y el metal mi
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines