Results 1 to 7 of 7

Thread: msg box positioning

Hybrid View

  1. #1
    Addicted Member
    Join Date
    Nov 2005
    Posts
    152

    Re: msg box positioning

    hi all,

    i had posted same question yesterday, and i got the answer of this question

    create one Module (basMsgBoxEx.bas) as follows
    VB Code:
    1. ''''''''''''Start Of basMsgBoxEx.bas file ''''''''''
    2. ' MsgBoxEx.bas
    3. '
    4. Option Explicit
    5.  
    6. Private Const NV_CLOSEMSGBOX = &H5000&
    7. Private Const NV_MOVEMSGBOX = &H5001&
    8. Private Const HWND_TOPMOST = -1
    9. Private Const SWP_NOSIZE = &H1
    10.  
    11. Private Type RECT
    12.     Left As Long
    13.     Top As Long
    14.     Right As Long
    15.     Bottom As Long
    16. End Type
    17. Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, _
    18.     ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
    19. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    20.     (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    21. Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
    22.     ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
    23.     ByVal cy As Long, ByVal wFlags As Long) As Long
    24. Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    25. Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, _
    26.     ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    27. Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, _
    28.     ByVal nIDEvent As Long) As Long
    29. Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    30.  
    31. Private mTitle As String
    32. Private mX As Long
    33. Private mY As Long
    34. Private mPause As Long
    35. Private mHandle As Long
    36.  
    37. Public Function MsgBoxMove(ByVal hwnd As Long, ByVal inPrompt As String, _
    38.         ByVal inTitle As String, ByVal inButtons As Long, _
    39.                ByVal inX As Long, ByVal inY As Long) As Integer
    40.      mTitle = inTitle: mX = inX:  mY = inY
    41.      SetTimer hwnd, NV_MOVEMSGBOX, 0&, AddressOf NewTimerProc
    42.      MsgBoxMove = MessageBox(hwnd, inPrompt, inTitle, inButtons)
    43. End Function
    44.  
    45. Public Function MsgBoxPause(ByVal hwnd As Long, ByVal inPrompt As String, _
    46.         ByVal inTitle As String, ByVal inButtons As Long, _
    47.         ByVal inPause As Integer) As Integer
    48.      mTitle = inTitle: mPause = inPause * 1000
    49.      SetTimer hwnd, NV_CLOSEMSGBOX, mPause, AddressOf NewTimerProc
    50.      MsgBoxPause = MessageBox(hwnd, inPrompt, inTitle, inButtons)
    51. End Function
    52.  
    53. Public Function NewTimerProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wparam As Long, _
    54.         ByVal lparam As Long) As Long
    55.     KillTimer hwnd, wparam
    56.     Select Case wparam
    57.          Case NV_CLOSEMSGBOX
    58.               ' A system class is a window class registered by the system which cannot
    59.               ' be destroyed by a processed, e.g. #32768 (a menu), #32769 (desktop
    60.               ' window), #32770 (dialog box), #32771 (task switch window).
    61.              mHandle = FindWindow("#32770", mTitle)
    62.              If mHandle <> 0 Then
    63.                   SetForegroundWindow mHandle
    64.                   SendKeys "{enter}"
    65.              End If
    66.              
    67.         Case NV_MOVEMSGBOX
    68.              mHandle = FindWindow("#32770", mTitle)
    69.              If mHandle <> 0 Then
    70.                   Dim w As Single, h As Single
    71.                   Dim mBox As RECT
    72.                   w = Screen.Width / Screen.TwipsPerPixelX
    73.                   h = Screen.Height / Screen.TwipsPerPixelY
    74.                   GetWindowRect mHandle, mBox
    75.                   If mX > (w - (mBox.Right - mBox.Left) - 1) Then mX = (w - (mBox.Right - mBox.Left) - 1)
    76.                   If mY > (h - (mBox.Bottom - mBox.Top) - 1) Then mY = (h - (mBox.Bottom - mBox.Top) - 1)
    77.                   If mX < 1 Then mX = 1: If mY < 1 Then mY = 1
    78.                     ' SWP_NOSIZE is to use current size, ignoring 3rd & 4th parameters.
    79.                   SetWindowPos mHandle, HWND_TOPMOST, mX, mY, 0, 0, SWP_NOSIZE
    80.              End If
    81.     End Select
    82. End Function
    Now use this code where you want

    suppose if you want to use the message box on your form then add this basMsgBoxEx.bas file in module and write following code.
    VB Code:
    1. mResult = MsgBoxMove(hwnd, "Message which you want to show on messagebox ", "Header of MsgBox ", vbOKOnly + vbInformation, x( Xposition), y (Yposition))

    enjoy,











    Edit: Added [vbcode][/vbcode] tags for more clarity. - Hack
    Last edited by Hack; Jan 12th, 2006 at 07:05 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width