elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  [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 2,318 veces)
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


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

.
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
  1.  
  2. '
  3. ' ////////////////////////////////////////////////////////////////
  4. ' // Autor: BlackZeroX ( Ortega Avila Miguel Angel )            //
  5. ' //                                                            //
  6. ' // Web: http://InfrAngeluX.Sytes.Net/                         //
  7. ' //                                                            //
  8. ' // |-> Pueden Distribuir Este Código siempre y cuando         //
  9. ' // no se eliminen los créditos originales de este código      //
  10. ' // No importando que sea modificado/editado o engrandecido    //
  11. ' // o achicado, si es en base a este código                    //
  12. ' ////////////////////////////////////////////////////////////////
  13. ' //
  14. ' ////////////////////////////////////////////////////////////////
  15.  
  16. Option Explicit
  17.  
  18. Private Type POINTAPI
  19.    x       As Long
  20.    y       As Long
  21. End Type
  22. Private Type RECT
  23.    Left    As Long
  24.    Top     As Long
  25.    Right   As Long
  26.    Bottom  As Long
  27. End Type
  28.  
  29. Enum WS_InCenterOpt
  30.    InScreen = 0
  31.    InObject = 1
  32.    InParent = 2
  33.    InWinExtern = 3
  34. End Enum
  35.  
  36. Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
  37. Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
  38. Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
  39. Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
  40. 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
  41.  
  42. Public Function WinCenterIn(ByVal hwnd As Long, Optional ByVal InhWnd As Long = 0, Optional ByVal Opt As WS_InCenterOpt = InParent)
  43. Dim st_retm         As RECT
  44. Dim st_retd         As RECT
  45. Dim st_pt           As POINTAPI
  46.  
  47.    If GetWindowRect(hwnd, st_retm) <> 0 Then
  48.  
  49.        Select Case Opt
  50.  
  51.            Case InObject, InParent, InWinExtern
  52.                If Opt = InParent Then
  53.                    InhWnd = GetParent(hwnd)
  54.                    If InhWnd = 0 Then
  55.                        WinCenterIn = WinCenterIn(hwnd, 0, InScreen)
  56.                    End If
  57.                End If
  58.                If GetWindowRect(InhWnd, st_retd) = 0 Then
  59.                    Exit Function
  60.                End If
  61.  
  62.            Case InScreen
  63.                st_retd.Bottom = GetSystemMetrics(&H1)
  64.                st_retd.Right = GetSystemMetrics(&H0)
  65.  
  66.            Case Else
  67.                Exit Function
  68.  
  69.        End Select
  70.  
  71.        st_pt.x = st_retd.Left + ((st_retd.Right - st_retd.Left) - (st_retm.Right - st_retm.Left)) \ 2
  72.        st_pt.y = st_retd.Top + ((st_retd.Bottom - st_retd.Top) - (st_retm.Bottom - st_retm.Top)) \ 2
  73.  
  74.        If Opt <> InWinExtern Then
  75.            Call ScreenToClient(InhWnd, st_pt)
  76.        End If
  77.  
  78.        WinCenterIn = MoveWindow(hwnd, st_pt.x, st_pt.y, (st_retm.Right - st_retm.Left), (st_retm.Bottom - st_retm.Top), 1) <> 0
  79.  
  80.    End If
  81.  
  82. End Function
  83.  
  84.  

Ejemplo:

Código
  1.  
  2. Option Explicit
  3.  
  4. Private Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  5.  
  6. Private Sub Command2_Click()
  7.    WinCenterIn Me.hwnd
  8.    WinCenterIn FindWindowA(vbNullString, "Administrador de tareas de Windows"), Me.hwnd, InWinExtern
  9.    'WinCenterIn Me.hwnd, FindWindowA(vbNullString, "Administrador de tareas de Windows"), InWinExtern
  10. End Sub
  11.  
  12.  

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
  1.  
  2. WinCenterIn Command1.hwnd, Me.hwnd
  3. WinCenterIn Command1.hwnd, 0
  4. WinCenterIn me.hwnd, 0
  5.  
  6.  

Temibles Lunas!¡.


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

The Dark Shadow is my passion.
Elemental Code


Desconectado Desconectado

Mensajes: 622


Im beyond the system


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

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

Bien ahi por un codigo que ande  ;)


En línea

I CODE FOR $$$
Programo por $$$
Hago tareas, trabajos para la facultad, lo que sea en VB6.0

Mis programas
raul338


Desconectado Desconectado

Mensajes: 2.633


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 pm »

Código
  1. ... en un segundo lo ponmgo jaja puse uno erroneo.
  2.  
Ú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
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


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


@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

The Dark Shadow is my passion.
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


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

.
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 am por BlackZeroX▓▓▒▒░░ » En línea

The Dark Shadow is my passion.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Restricciones en WordPress respecto a otros CMS?
Desarrollo Web
T0p1t0 4 3,077 Último mensaje 13 Julio 2013, 01:29 am
por fr3d8
Servidores y JS, entre otros, con respecto a HTTP
Programación C/C++
Usuario887 3 2,298 Último mensaje 17 Abril 2021, 20:27 pm
por @XSStringManolo
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines