-
Mar 16th, 2005, 07:50 PM
#1
-
Mar 21st, 2005, 10:32 PM
#2
Re: MsgBoxEx - Extended Message Box
Very nice additional features! Will you be fixing the button and text positioning when the msgbox is sized?
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
-
Mar 24th, 2005, 05:57 AM
#3
-
Mar 25th, 2005, 07:34 AM
#4
Re: MsgBoxEx - Extended Message Box
I concur with RobDog. Very nice! In fact, when you finish I think I'll pop this into a modMsgBox.bas file and make it standard module for all new projects.
-
Mar 29th, 2005, 10:49 AM
#5
-
May 19th, 2005, 10:48 AM
#6
Re: MsgBoxEx - Extended Message Box
In a standard module :
VB Code:
'*************************************************************
'* MsgBoxEx() - Written by Aaron Young, February 7th 2000
'* - Edited by Philip Manavopoulos, May 19th 2005
'*************************************************************
Option Explicit
Private Type CWPSTRUCT
lParam As Long
wParam As Long
message As Long
hwnd As Long
End Type
'Added by manavo11
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type LOGBRUSH
lbStyle As Long
lbColor As Long
lbHatch As Long
End Type
'Added by manavo11
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private 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
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
'Added by manavo11
Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function CreateBrushIndirect Lib "gdi32" (lpLogBrush As LOGBRUSH) As Long
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function SetFocus Lib "user32" (ByVal hwnd As Long) 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
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
'Added by manavo11
Private Const WH_CALLWNDPROC = 4
Private Const GWL_WNDPROC = (-4)
Private Const WM_CTLCOLORBTN = &H135
Private Const WM_DESTROY = &H2
Private Const WM_SETTEXT = &HC
Private Const WM_CREATE = &H1
'Added by manavo11
' System Color Constants
Private Const COLOR_BTNFACE = 15
Private Const COLOR_BTNTEXT = 18
' Windows Messages
Private Const WM_CTLCOLORSTATIC = &H138
Private Const WM_CTLCOLORDLG = &H136
Private Const WM_SHOWWINDOW As Long = &H18
'Added by manavo11
Private lHook As Long
Private lPrevWnd As Long
Private bCustom As Boolean
Private sButtons() As String
Private lButton As Long
Private sHwnd As String
'Added by manavo11
Private lForecolor As Long
Private lBackcolor As Long
Private sDefaultButton As String
Private iX As String
Private iY As String
Private iWidth As String
Private iHeight As String
Private iButtonCount As Integer
Private iButtonWidth As Integer
'Added by manavo11
Public Function SubMsgBox(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim sText As String
Select Case Msg
'Added by manavo11
Case WM_SHOWWINDOW
Dim MsgBoxRect As RECT
GetWindowRect hwnd, MsgBoxRect
If StrPtr(iX) = 0 Then
iX = MsgBoxRect.Left
End If
If StrPtr(iY) = 0 Then
iY = MsgBoxRect.Top
End If
If StrPtr(iWidth) = 0 Then
iWidth = MsgBoxRect.Right - MsgBoxRect.Left
Else
Dim i As Integer
Dim h As Long
Dim ButtonRECT As RECT
For i = 0 To iButtonCount
h = FindWindowEx(hwnd, h, "Button", vbNullString)
GetWindowRect h, ButtonRECT
MoveWindow h, 14 + (iButtonWidth * i) + (6 * i), iHeight - (ButtonRECT.Bottom - ButtonRECT.Top) - 40, iButtonWidth, ButtonRECT.Bottom - ButtonRECT.Top, 1
Next
End If
If StrPtr(iHeight) = 0 Then
iHeight = MsgBoxRect.Bottom - MsgBoxRect.Top
End If
MoveWindow hwnd, iX, iY, iWidth, iHeight, 1
Case WM_CTLCOLORDLG, WM_CTLCOLORSTATIC
Dim tLB As LOGBRUSH
'Debug.Print wParam
Call SetTextColor(wParam, lForecolor)
Call SetBkColor(wParam, lBackcolor)
tLB.lbColor = lBackcolor
SubMsgBox = CreateBrushIndirect(tLB)
Exit Function
'Added by manavo11
Case WM_CTLCOLORBTN
'Customize the MessageBox Buttons if neccessary..
'First Process the Default Action of the Message (Draw the Button)
SubMsgBox = CallWindowProc(lPrevWnd, hwnd, Msg, wParam, ByVal lParam)
'Now Change the Button Text if Required
If Not bCustom Then Exit Function
If lButton = 0 Then sHwnd = ""
'If this Button has Been Modified Already then Exit
If InStr(sHwnd, " " & Trim(Str(lParam)) & " ") Then Exit Function
sText = sButtons(lButton)
sHwnd = sHwnd & " " & Trim(Str(lParam)) & " "
lButton = lButton + 1
'Modify the Button Text
SendMessage lParam, WM_SETTEXT, Len(sText), ByVal sText
'Added by manavo11
If sText = sDefaultButton Then
SetFocus lParam
End If
'Added by manavo11
Exit Function
Case WM_DESTROY
'Remove the MsgBox Subclassing
Call SetWindowLong(hwnd, GWL_WNDPROC, lPrevWnd)
End Select
SubMsgBox = CallWindowProc(lPrevWnd, hwnd, Msg, wParam, ByVal lParam)
End Function
Private Function HookWindow(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim tCWP As CWPSTRUCT
Dim sClass As String
'This is where you need to Hook the Messagebox
CopyMemory tCWP, ByVal lParam, Len(tCWP)
If tCWP.message = WM_CREATE Then
sClass = Space(255)
sClass = Left(sClass, GetClassName(tCWP.hwnd, ByVal sClass, 255))
If sClass = "#32770" Then
'Subclass the Messagebox as it's created
lPrevWnd = SetWindowLong(tCWP.hwnd, GWL_WNDPROC, AddressOf SubMsgBox)
End If
End If
HookWindow = CallNextHookEx(lHook, nCode, wParam, ByVal lParam)
End Function
Public Function MsgBoxEx(ByVal Prompt As String, Optional ByVal Buttons As Long = vbOKOnly, Optional ByVal Title As String, Optional ByVal HelpFile As String, Optional ByVal Context As Long, Optional ByRef CustomButtons As Variant, Optional DefaultButton As String, Optional X As String, Optional Y As String, Optional Width As String, Optional Height As String, Optional ByVal ForeColor As ColorConstants = -1, Optional ByVal BackColor As ColorConstants = -1) As Long
Dim lReturn As Long
bCustom = (Buttons = vbCustom)
If bCustom And IsMissing(CustomButtons) Then
MsgBox "When using the Custom option you need to supply some Buttons in the ""CustomButtons"" Argument.", vbExclamation + vbOKOnly, "Error"
Exit Function
End If
lHook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf HookWindow, App.hInstance, App.ThreadID)
'Set the Defaults
If Len(Title) = 0 Then Title = App.Title
If bCustom Then
'User wants to use own Button Titles..
If TypeName(CustomButtons) = "String" Then
ReDim sButtons(0)
sButtons(0) = CustomButtons
Buttons = 0
Else
sButtons = CustomButtons
Buttons = UBound(sButtons)
End If
End If
'Added by manavo11
lForecolor = GetSysColor(COLOR_BTNTEXT)
lBackcolor = GetSysColor(COLOR_BTNFACE)
If ForeColor >= 0 Then lForecolor = ForeColor
If BackColor >= 0 Then lBackcolor = BackColor
sDefaultButton = DefaultButton
iX = X
iY = Y
iWidth = Width
iHeight = Height
iButtonCount = UBound(sButtons)
iButtonWidth = (iWidth - (2 * 14) - (6 * (Buttons + 1))) / (Buttons + 1)
'Added by manavo11
lButton = 0
'Show the Modified MsgBox
lReturn = MsgBox(Prompt, Buttons, Title, HelpFile, Context)
Call UnhookWindowsHookEx(lHook)
'If it's a Custom Button MsgBox, Alter the Return Value
If bCustom Then lReturn = lReturn - (UBound(CustomButtons) + 1)
bCustom = False
MsgBoxEx = lReturn
End Function
Has someone helped you? Then you can Rate their helpful post.
-
May 19th, 2005, 10:52 AM
#7
Re: MsgBoxEx - Extended Message Box
Example :
VB Code:
Private Sub Command1_Click()
Dim aButtons(2) As String
aButtons(0) = "Go"
aButtons(1) = "Come"
aButtons(2) = "???"
Caption = aButtons(MsgBoxEx("Text" & vbCrLf & "More Text" & vbCrLf & "Even More Text", vbCustom, "Title", , , aButtons, aButtons(1), 0, 0, 200, 300, vbWhite, vbBlue))
End Sub
Has someone helped you? Then you can Rate their helpful post.
-
Sep 23rd, 2007, 12:22 PM
#8
New Member
Re: MsgBoxEx - Extended Message Box
Can we have a background picture on it ?
-
Sep 28th, 2007, 05:12 PM
#9
-
Dec 28th, 2007, 08:56 PM
#10
Frenzied Member
Re: MsgBoxEx - Extended Message Box
manavo11, if you get a chance, can you post your code in VB tags? When I copy your code and past it to a module, it is all bunch up on couple lines.
Thank You
I'll Be Back!
T-1000
Microsoft .Net 2005
Microsoft Visual Basic 6
Prefer using API
-
Dec 28th, 2007, 11:55 PM
#11
Re: MsgBoxEx - Extended Message Box
Liquid Metal, I read a post that said to copy code (within VB tags) click the 'Quote' button which removes all the line numbers allowing you to copy and paste the code into your project
-
Dec 29th, 2007, 02:23 AM
#12
Re: MsgBoxEx - Extended Message Box
Or check out MartinLiss' signature for his VB Code Copier fix.
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
-
Dec 29th, 2007, 12:51 PM
#13
Re: MsgBoxEx - Extended Message Box
How close does it get us to TaskDialog()'s functionality?
So long MessageBox and thanks for all the memories
-
Dec 29th, 2007, 03:46 PM
#14
Frenzied Member
Re: MsgBoxEx - Extended Message Box
I'll Be Back!
T-1000
Microsoft .Net 2005
Microsoft Visual Basic 6
Prefer using API
-
Dec 29th, 2007, 04:15 PM
#15
Re: MsgBoxEx - Extended Message Box
Glad to help
-
Jan 4th, 2008, 11:47 PM
#16
Frenzied Member
Re: MsgBoxEx - Extended Message Box
I got a question:
Code:
Public Function MsgBoxEx(ByVal Prompt As String, Optional ByVal Buttons As Long = vbOKOnly, Optional ByVal Title As String, Optional ByVal HelpFile As String, Optional ByVal Context As Long, Optional ByRef CustomButtons As Variant, Optional DefaultButton As String, Optional X As String, Optional Y As String, Optional Width As String, Optional Height As String, Optional ByVal ForeColor As ColorConstants = -1, Optional ByVal BackColor As ColorConstants = -1) As Long
Can't the bolded strings be integers?
-
Jan 5th, 2008, 12:14 AM
#17
Re: MsgBoxEx - Extended Message Box
Where is the bolded parts? It doesnt show.
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
-
Jan 5th, 2008, 02:33 AM
#18
Re: MsgBoxEx - Extended Message Box
I think it was in ref to this part ( the bold is hard to see, so I also changed the color)
Code:
Optional X As String, Optional Y As String, Optional Width As String, Optional Height As String
Doesn't it make sense to make those Longs instead?
-tg
-
Jan 5th, 2008, 02:38 AM
#19
Re: MsgBoxEx - Extended Message Box
Yes, if your passing numerical data all the time, as in coordinates, then it does make logical sense to change the signature to Integer or Long instead.
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
-
Jan 5th, 2008, 02:50 AM
#20
Re: MsgBoxEx - Extended Message Box
Well, I'm think that until VB recognizes "four hundred fifty-eight" as a number.... it's pretty safe (possibly safer) to change it to longs to allow 458...
-tg
-
Jul 29th, 2010, 05:00 AM
#21
New Member
Re: MsgBoxEx - Extended Message Box
nice coding but cant we increase the font size......please
-
Jul 31st, 2010, 09:08 PM
#22
Lively Member
Re: MsgBoxEx - Extended Message Box
Dear All,
These code can not show the Unicode message.
LVD
-
Aug 7th, 2021, 05:59 PM
#23
New Member
Re: MsgBoxEx - Extended Message Box
vb6 & win 10
Tried code and have problems
1)The left lower corner of the msgbox is grey, and not color selected
2)Sub Script out of range error after pressing btn #1
Thanks for any HELP
NO HELP!!
So I took some ones advise and created my own.
Size, location, backcolor, forecolor, 1 to 3 buttons
button size, color & location
Message text size, color & location
Last edited by khkv8; Aug 12th, 2021 at 06:13 PM.
Reason: Up Date
-
Jul 13th, 2024, 06:56 PM
#24
Addicted Member
Re: MsgBoxEx - Extended Message Box
Late to the party !
I need to change the Font for the Message Text and the BUTTONS.
How do i do that ?
Or is there a newer VB6 MsgBox code that has that feature?
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
|