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

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Cambiar la posición de un msgbox
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Cambiar la posición de un msgbox  (Leído 6,320 veces)
karmany
Colaborador
***
Desconectado Desconectado

Mensajes: 1.614


Sueñas que sueñas


Ver Perfil WWW
Cambiar la posición de un msgbox
« en: 8 Septiembre 2006, 20:30 pm »

Hola..

Por defecto, cuando utilizamos un msgbox, éste aparece centrado en la pantalla.
El problema es que necesito el msgbox en la parte inferior derecha,

¿Alguien sabe cómo hacerlo?

PD. La idea es no utilizar formularios


En línea

soplo
Ex-Staff
*
Desconectado Desconectado

Mensajes: 3.592

Debian rool'z


Ver Perfil
Re: Cambiar la posición de un msgbox
« Respuesta #1 en: 8 Septiembre 2006, 21:43 pm »

Hola
Citar
PD. La idea es no utilizar formularios
Un msgbox es una clase de un formulario modal y centrado.

Si quieres hacerte uno a medida solo tienes que hacerte una clase a tu medida con las propiedades que te plazcan y situado donde quieras.

 ;D


En línea

Callar es asentir ¡No te dejes llevar!
Sancho.Mazorka


Desconectado Desconectado

Mensajes: 480


Gamer & Programador


Ver Perfil WWW
Re: Cambiar la posición de un msgbox
« Respuesta #2 en: 9 Septiembre 2006, 01:54 am »

toma esto talvez que te sirve!

Código:
Añade el siguiente código al módulo BAS:
Nota: He dejado los comentarios originales en inglés, ya que no necesitan demasiada traducción... espero...

'------------------------------------------------------------------
'Ejemplo para posicionar un MsgBox                      (15/Jun/98)
'
'Microsoft TechNet Knowledge Base, PSS ID Number: Q180936
'HOWTO: Position a MsgBox Using a Windows Hook Procedure
'
'©Guillermo 'guille Som, 1998
'------------------------------------------------------------------
Option Explicit

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)
      SetWindowPos wParam, 0, 0, 0, 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

Este es el código que hay que añadir al formulario:

'
'------------------------------------------------------------------
'Ejemplo para posicionar un MsgBox                      (15/Jun/98)
'
'Microsoft TechNet Knowledge Base, PSS ID Number: Q180936
'HOWTO: Position a MsgBox Using a Windows Hook Procedure
'
'©Guillermo 'guille Som, 1998
'------------------------------------------------------------------
Option Explicit

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


Sancho.Mazorka    :P
En línea

Ganador Xeon Web Server ! ! !    Sancho.Mazorka :D
http://foro.elhacker.net/index.php/topic,171903.75.html


karmany
Colaborador
***
Desconectado Desconectado

Mensajes: 1.614


Sueñas que sueñas


Ver Perfil WWW
Re: Cambiar la posición de un msgbox
« Respuesta #3 en: 9 Septiembre 2006, 12:30 pm »

Gracias a los dos..

El código funciona perfectamente, pero, después de probarlo, pienso que es mucho mejor definir un nuevo objeto (clase), ya que es muchísimo más sencillo de utilizarlo.
Un saludo a los 2.
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
¿Mod cambiar la posición de las aplicaciones abiertas en KDE?
GNU/Linux
Servia 2 2,420 Último mensaje 5 Marzo 2012, 18:16 pm
por Servia
CAMBIAR POSICION EN INICIO DEL PROGRAMA « 1 2 »
Windows
FCOSTA 11 6,266 Último mensaje 4 Octubre 2014, 00:38 am
por FCOSTA
Cambiar posicion en inicio del programa
.NET (C#, VB.NET, ASP)
FCOSTA 1 1,810 Último mensaje 4 Octubre 2014, 22:28 pm
por Eleкtro
Cambiar la posición inicial de un Form
Programación Visual Basic
Monkeykiller_vb 2 2,163 Último mensaje 2 Octubre 2019, 06:18 am
por Monkeykiller_vb
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines