Autor Tema: Posicion del Msgbox  (Leído 4931 veces)

0 Usuarios y 1 Visitante están viendo este tema.

YAcosta

  • Moderador Global
  • Exabyte
  • *****
  • Mensajes: 2853
  • Reputación: +160/-38
  • Daddy de Qüentas y QüeryFull
    • Ver Perfil
    • Personal
Posicion del Msgbox
« en: Octubre 18, 2011, 01:30:53 pm »
Alguien sabe como hacer para que la ventana que invoca el Msgbox salga en las coordenadas de pantalla que yo desee? Quiero evitar usar un form propio.

Gracias
Me encuentras en YAcosta.com

xkiz ™

  • Moderador Global
  • Gigabyte
  • *****
  • Mensajes: 283
  • Reputación: +30/-11
    • Ver Perfil
    • xkiz ™
Re:Posicion del Msgbox
« Respuesta #1 en: Octubre 18, 2011, 01:49:54 pm »
podrías probar con MessageBoxIndirect MSGBOXPARAMS
pero no estoy muy seguro así que es solo una sugerencia, investigalo vos...

YAcosta

  • Moderador Global
  • Exabyte
  • *****
  • Mensajes: 2853
  • Reputación: +160/-38
  • Daddy de Qüentas y QüeryFull
    • Ver Perfil
    • Personal
Re:Posicion del Msgbox
« Respuesta #2 en: Octubre 18, 2011, 02:07:15 pm »
Gracias, revise las paginas, me queda un poco grande el saco, si ese es el único camino... creo que mas fácil me sera usar un form propio.

Saludos.
Me encuentras en YAcosta.com

E N T E R

  • Petabyte
  • ******
  • Mensajes: 1062
  • Reputación: +57/-13
  • www.enterpy.com
    • Ver Perfil
    • www.enterpy.com
Re:Posicion del Msgbox
« Respuesta #3 en: Octubre 18, 2011, 02:32:28 pm »

En un Modulo esto:


Código: [Seleccionar]
Type RECT
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type

Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

Public Const GWL_HINSTANCE = (-6)
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOZORDER = &H4
Public Const SWP_NOACTIVATE = &H10
Public Const HCBT_ACTIVATE = 5
Public Const WH_CBT = 5

Public hHook As Long

Function WinProc1(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

   If lMsg = HCBT_ACTIVATE Then
      'Show the MsgBox at a fixed location (0,0)

      'ACA LE CAMBIAS LA POSICION EL 100 Y EL 200 ES

      SetWindowPos wParam, 0, 100, 200, 0, 0, SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE
      'Release the CBT hook
      UnhookWindowsHookEx hHook
   End If
   WinProc1 = False

End Function

Function WinProc2(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

    Dim rectForm As RECT, rectMsg As RECT
    Dim x As Long, y As Long
   
    'On HCBT_ACTIVATE, show the MsgBox centered over Form1
    If lMsg = HCBT_ACTIVATE Then
       'Get the coordinates of the form and the message box so that
       'you can determine where the center of the form is located
       GetWindowRect Form1.hwnd, rectForm
       GetWindowRect wParam, rectMsg
       
       x = (rectForm.Left + (rectForm.Right - rectForm.Left) / 2) - ((rectMsg.Right - rectMsg.Left) / 2)
       y = (rectForm.Top + (rectForm.Bottom - rectForm.Top) / 2) - ((rectMsg.Bottom - rectMsg.Top) / 2)
       'Position the msgbox
       SetWindowPos wParam, 0, x, y, 0, 0, SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE
       'Release the CBT hook
       UnhookWindowsHookEx hHook
       
    End If
   
    WinProc2 = False

End Function


Esto en un Command1 y Command2


Código: [Seleccionar]
Private Sub Command1_Click()
   
    Dim hInst As Long
    Dim Thread As Long
   
    'Set up the CBT hook
    hInst = GetWindowLong(Me.hwnd, GWL_HINSTANCE)
    Thread = GetCurrentThreadId()
    hHook = SetWindowsHookEx(WH_CBT, AddressOf WinProc1, hInst, Thread)
   
    'Display the message box
    MsgBox "This message box has been positioned at (0,0)."

End Sub

Private Sub Command2_Click()
    Dim hInst As Long
    Dim Thread As Long
   
    'Set up the CBT hook
    hInst = GetWindowLong(Me.hwnd, GWL_HINSTANCE)
    Thread = GetCurrentThreadId()
    hHook = SetWindowsHookEx(WH_CBT, AddressOf WinProc2, hInst, Thread)
   
    'Display the message box
    MsgBox "This message box is centered over Form1."
End Sub
CIBER GOOGLE - CONCEPCIÓN PARAGUAY
www.enterpy.com
Primera regla de la programacion, para que vas a hacerlo complicado si lo puedes hacer sencillo

YAcosta

  • Moderador Global
  • Exabyte
  • *****
  • Mensajes: 2853
  • Reputación: +160/-38
  • Daddy de Qüentas y QüeryFull
    • Ver Perfil
    • Personal
Re:Posicion del Msgbox
« Respuesta #4 en: Octubre 18, 2011, 03:02:08 pm »
Bestial!!! Funciona bien, al principio no sabia como modificar las coordenadas pero ya lo encontre. Gracias doc.
Me encuentras en YAcosta.com

ssccaann43

  • Terabyte
  • *****
  • Mensajes: 970
  • Reputación: +97/-58
    • Ver Perfil
    • Sistemas Nuñez, Consultores y Soporte, C.A.
Re:Posicion del Msgbox
« Respuesta #5 en: Octubre 20, 2011, 02:11:12 pm »

En un Modulo esto:


Código: [Seleccionar]
Type RECT
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type

Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

Public Const GWL_HINSTANCE = (-6)
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOZORDER = &H4
Public Const SWP_NOACTIVATE = &H10
Public Const HCBT_ACTIVATE = 5
Public Const WH_CBT = 5

Public hHook As Long

Function WinProc1(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

   If lMsg = HCBT_ACTIVATE Then
      'Show the MsgBox at a fixed location (0,0)

      'ACA LE CAMBIAS LA POSICION EL 100 Y EL 200 ES

      SetWindowPos wParam, 0, 100, 200, 0, 0, SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE
      'Release the CBT hook
      UnhookWindowsHookEx hHook
   End If
   WinProc1 = False

End Function

Function WinProc2(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

    Dim rectForm As RECT, rectMsg As RECT
    Dim x As Long, y As Long
   
    'On HCBT_ACTIVATE, show the MsgBox centered over Form1
    If lMsg = HCBT_ACTIVATE Then
       'Get the coordinates of the form and the message box so that
       'you can determine where the center of the form is located
       GetWindowRect Form1.hwnd, rectForm
       GetWindowRect wParam, rectMsg
       
       x = (rectForm.Left + (rectForm.Right - rectForm.Left) / 2) - ((rectMsg.Right - rectMsg.Left) / 2)
       y = (rectForm.Top + (rectForm.Bottom - rectForm.Top) / 2) - ((rectMsg.Bottom - rectMsg.Top) / 2)
       'Position the msgbox
       SetWindowPos wParam, 0, x, y, 0, 0, SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE
       'Release the CBT hook
       UnhookWindowsHookEx hHook
       
    End If
   
    WinProc2 = False

End Function


Esto en un Command1 y Command2


Código: [Seleccionar]
Private Sub Command1_Click()
   
    Dim hInst As Long
    Dim Thread As Long
   
    'Set up the CBT hook
    hInst = GetWindowLong(Me.hwnd, GWL_HINSTANCE)
    Thread = GetCurrentThreadId()
    hHook = SetWindowsHookEx(WH_CBT, AddressOf WinProc1, hInst, Thread)
   
    'Display the message box
    MsgBox "This message box has been positioned at (0,0)."

End Sub

Private Sub Command2_Click()
    Dim hInst As Long
    Dim Thread As Long
   
    'Set up the CBT hook
    hInst = GetWindowLong(Me.hwnd, GWL_HINSTANCE)
    Thread = GetCurrentThreadId()
    hHook = SetWindowsHookEx(WH_CBT, AddressOf WinProc2, hInst, Thread)
   
    'Display the message box
    MsgBox "This message box is centered over Form1."
End Sub

Que bueno esta esto...! =)
Miguel Núñez.