|
-
Jan 11th, 2006, 08:31 AM
#1
Thread Starter
Member
msg box positioning
hi, total newbie here but when i make a command button and it pops up the msg box is always in the center, is there a way i can change the coordinates or positioning on the msgbox? Any help would be appreciated thankyou
-
Jan 11th, 2006, 08:33 AM
#2
Re: msg box positioning
Welcome to the forums. 
Right beneath this thread is another thread with the exact same question. (Kind of odd having the same question posted by two different people almost at the same time. )
Basically, the easiest and quickest way is to make your own msgbox out of a standard VB form (I haven't acutally used the VB msgbox is years). You have a lot more control over every aspect of it including what you want for buttons.
-
Jan 11th, 2006, 08:59 AM
#3
-
Jan 11th, 2006, 01:39 PM
#4
Re: msg box positioning
 Originally Posted by jcis
LOL...I kind of figured the code would be pretty savage. Making your own is much easier and gives you a lot more flexibility.
-
Jan 12th, 2006, 06:57 AM
#5
Addicted Member
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:
''''''''''''Start Of basMsgBoxEx.bas file ''''''''''
' MsgBoxEx.bas
'
Option Explicit
Private Const NV_CLOSEMSGBOX = &H5000&
Private Const NV_MOVEMSGBOX = &H5001&
Private Const HWND_TOPMOST = -1
Private Const SWP_NOSIZE = &H1
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, _
ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private 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
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private mTitle As String
Private mX As Long
Private mY As Long
Private mPause As Long
Private mHandle As Long
Public Function MsgBoxMove(ByVal hwnd As Long, ByVal inPrompt As String, _
ByVal inTitle As String, ByVal inButtons As Long, _
ByVal inX As Long, ByVal inY As Long) As Integer
mTitle = inTitle: mX = inX: mY = inY
SetTimer hwnd, NV_MOVEMSGBOX, 0&, AddressOf NewTimerProc
MsgBoxMove = MessageBox(hwnd, inPrompt, inTitle, inButtons)
End Function
Public Function MsgBoxPause(ByVal hwnd As Long, ByVal inPrompt As String, _
ByVal inTitle As String, ByVal inButtons As Long, _
ByVal inPause As Integer) As Integer
mTitle = inTitle: mPause = inPause * 1000
SetTimer hwnd, NV_CLOSEMSGBOX, mPause, AddressOf NewTimerProc
MsgBoxPause = MessageBox(hwnd, inPrompt, inTitle, inButtons)
End Function
Public Function NewTimerProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wparam As Long, _
ByVal lparam As Long) As Long
KillTimer hwnd, wparam
Select Case wparam
Case NV_CLOSEMSGBOX
' A system class is a window class registered by the system which cannot
' be destroyed by a processed, e.g. #32768 (a menu), #32769 (desktop
' window), #32770 (dialog box), #32771 (task switch window).
mHandle = FindWindow("#32770", mTitle)
If mHandle <> 0 Then
SetForegroundWindow mHandle
SendKeys "{enter}"
End If
Case NV_MOVEMSGBOX
mHandle = FindWindow("#32770", mTitle)
If mHandle <> 0 Then
Dim w As Single, h As Single
Dim mBox As RECT
w = Screen.Width / Screen.TwipsPerPixelX
h = Screen.Height / Screen.TwipsPerPixelY
GetWindowRect mHandle, mBox
If mX > (w - (mBox.Right - mBox.Left) - 1) Then mX = (w - (mBox.Right - mBox.Left) - 1)
If mY > (h - (mBox.Bottom - mBox.Top) - 1) Then mY = (h - (mBox.Bottom - mBox.Top) - 1)
If mX < 1 Then mX = 1: If mY < 1 Then mY = 1
' SWP_NOSIZE is to use current size, ignoring 3rd & 4th parameters.
SetWindowPos mHandle, HWND_TOPMOST, mX, mY, 0, 0, SWP_NOSIZE
End If
End Select
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:
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.
-
Jan 12th, 2006, 07:07 AM
#6
Re: msg box positioning
I saw This on Google by CodeGuru. I haven't tried it but I'm going to. Looks fairly short and simple and has an example project with it.
edited:
I tried it out. It is similar to what was already posted and there is a lot of code behind it.
Last edited by TysonLPrice; Jan 12th, 2006 at 07:22 AM.
-
Feb 12th, 2006, 04:42 PM
#7
Re: msg box positioning
Even though its a little late, may be helpful. Aaron Young posted that same code on VBF 4 years before the CG article 
http://www.vbforums.com/showpost.php...58&postcount=4
And extended by manavo11 here -
http://www.vbforums.com/showthread.php?t=329373
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|