|
|
#1 |
|
VB6, XHTML & CSS hobbyist
Join Date: Oct 02
Location: Finland
Posts: 6,440
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
VB6 UniMsgBox - Unicode message box class
To make things clear from the beginning, by nature this class is used in a very different way than the default message box. The default message box is just a rather simple function that doesn't remember any settings.
This class however can be created and it'll remember the settings you give it. This changes the usage of the message box quite a lot and if you're just looking for Unicode MsgBox function replacement, this does not do that in a syntax compatible way. Now that this is clear, here are the list of features:
The class does hooking to change the texts of the buttons. This means if you're an advanced coder you can use the hWnd to customize the window further, subclass it if you like and as a result control it much more. Usage sample: Code:
Option Explicit
Private Sub Form_Load()
Dim MessageBox As UniMsgBox
Set MessageBox = New UniMsgBox
With MessageBox
.ButtonYes = "Oh yeah!"
.ButtonNo = "NO! NEVER!"
If .Show( _
"Bill Gates is cool?", _
"Just a simple question", _
[Yes / No], _
[Default Button 2], _
[Icon Question] _
) = [Result Yes] Then
.Show "You're hired!", "Windows will not crash anymore", , , [Icon Critical]
Else
.Show "Dear user, the following blue screen is sponsored but not endorsed by Microsoft.", "Revenge!"
End If
End With
Set MessageBox = Nothing
Unload Me
End Sub
__________________
Unicode classes, functions... in Visual Basic 6
VB6 in occasional use. I'm mostly HTML, CSS & JavaScript these days. « Antec Sonata II: Core 2 Duo E7400, ASRock P45TS, Asus EN9600GT 512 MB, 4 GB, 1.25 TB » « OS: Windows 7 | Laptop: Amilo Pi 2530-12P| Netbook: Asus EEE 901 » Last edited by Merri; Aug 1st, 2010 at 06:00 PM. |
|
|
|
|
|
#2 |
|
VB6, XHTML & CSS hobbyist
Join Date: Oct 02
Location: Finland
Posts: 6,440
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: VB6 UniMsgBox - Unicode message box class
If you want a simple Unicode aware replacement of the MsgBox function, here is that too:
Code:
Option Explicit
Private Const MB_USERICON = &H80&
Private Type MsgBoxParams
cbSize As Long
hWndOwner As Long
hInstance As Long
lpszText As Long
lpszCaption As Long
dwStyle As Long
lpszIcon As Long
dwContextHelpId As Long
lpfnMsgBoxCallback As Long
dwLanguageId As Long
End Type
Private Declare Function MessageBoxIndirectW Lib "user32" (lpMsgBoxParams As MsgBoxParams) As Long
' note: I didn't bother to go ahead and start hacking with HelpFile and Context
Public Function MsgBox(ByVal Prompt As String, Optional ByVal Buttons As VbMsgBoxStyle = vbOKOnly, Optional ByVal Title As String, Optional ByVal ResourceIcon As String, Optional ByVal hWndOwner As Long) As VbMsgBoxResult
Dim udtMsgBox As MsgBoxParams
' if no owner is specified, try to use the active form
If hWndOwner = 0 Then If Not Screen.ActiveForm Is Nothing Then hWndOwner = Screen.ActiveForm.hWnd
With udtMsgBox
.cbSize = Len(udtMsgBox)
' important to set owner to get behavior similar to the native MsgBox
.hWndOwner = hWndOwner
.hInstance = App.hInstance
' set the message
.lpszText = StrPtr(Prompt)
' if no title is given, use the application title like the native MsgBox
If LenB(Title) = 0 Then Title = App.Title
.lpszCaption = StrPtr(Title)
' thought this would be a nice feature addition
If LenB(ResourceIcon) = 0& Then
.dwStyle = Buttons
Else
.dwStyle = (Buttons Or MB_USERICON) And Not (&H70&)
.lpszIcon = StrPtr(ResourceIcon)
End If
End With
' show the message box
MsgBox = MessageBoxIndirectW(udtMsgBox)
End Function
__________________
Unicode classes, functions... in Visual Basic 6
VB6 in occasional use. I'm mostly HTML, CSS & JavaScript these days. « Antec Sonata II: Core 2 Duo E7400, ASRock P45TS, Asus EN9600GT 512 MB, 4 GB, 1.25 TB » « OS: Windows 7 | Laptop: Amilo Pi 2530-12P| Netbook: Asus EEE 901 » Last edited by Merri; Oct 12th, 2008 at 02:50 AM. |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Sep 08
Posts: 26
![]() |
Re: VB6 UniMsgBox - Unicode message box class
Nice, I'm using second one, it really good and handy!!!
|
|
|
|
|
|
#4 |
|
Junior Member
Join Date: Feb 06
Posts: 24
![]() |
Re: VB6 UniMsgBox - Unicode message box class
Excelent UniMsgBox!
I use to change Msgbox Button Caption it is very small. Can you send an sample-Attached Files how to load res file?...and how to use all other properties. I tried with icon resource....but....something not work. Thank you |
|
|
|
|
|
#5 |
|
VB6, XHTML & CSS hobbyist
Join Date: Oct 02
Location: Finland
Posts: 6,440
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: VB6 UniMsgBox - Unicode message box class
A resource icon will only work with a compiled application.
__________________
Unicode classes, functions... in Visual Basic 6
VB6 in occasional use. I'm mostly HTML, CSS & JavaScript these days. « Antec Sonata II: Core 2 Duo E7400, ASRock P45TS, Asus EN9600GT 512 MB, 4 GB, 1.25 TB » « OS: Windows 7 | Laptop: Amilo Pi 2530-12P| Netbook: Asus EEE 901 » |
|
|
|
|
|
#6 |
|
Junior Member
Join Date: Feb 06
Posts: 24
![]() |
Re: VB6 UniMsgBox - Unicode message box class
Thank you for quick answer. I never use resource file until now.
Can you send me a sample how to display an icon from resource? Than you! |
|
|
|
|
|
#7 |
|
VB6, XHTML & CSS hobbyist
Join Date: Oct 02
Location: Finland
Posts: 6,440
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: VB6 UniMsgBox - Unicode message box class
I have this piece of code at http://kontu.selfip.info/vb6/projects/Unicode – extracted from the main project.
Code:
Option Explicit
' Icon extraction for UniMsgBox sample
Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Private Sub Command1_Click()
Dim Test As New UniMsgBox, lngIcon As Long
Test.AlwaysOnTop = True
lngIcon = ExtractIcon(App.hInstance, "shell32.dll", 46)
Test.SetButtons , , , , "Restart &Later", , , , "Restart &Now"
If Test.Show("Updating your computer is almost complete. You must restart your computer for the updates to take effect." & _
vbNewLine & vbNewLine & "Do you want to restart your computer now?", "Automatic Updates", _
[Yes / No], [Default Button 1], [Icon None], lngIcon) = [Result Yes] Then
MsgBox "Oh behave!"
End If
If lngIcon Then DestroyIcon lngIcon
End Sub
Wrong icon, I guess. This sets the icon of the window, not the icon to be displayed alongside the message.
__________________
Unicode classes, functions... in Visual Basic 6
VB6 in occasional use. I'm mostly HTML, CSS & JavaScript these days. « Antec Sonata II: Core 2 Duo E7400, ASRock P45TS, Asus EN9600GT 512 MB, 4 GB, 1.25 TB » « OS: Windows 7 | Laptop: Amilo Pi 2530-12P| Netbook: Asus EEE 901 » Last edited by Merri; Nov 22nd, 2008 at 07:14 AM. |
|
|
|
|
|
#8 |
|
Junior Member
Join Date: Feb 06
Posts: 24
![]() |
Re: VB6 UniMsgBox - Unicode message box class
Ok! Thank you....But my question still remain!
Can you send me a sample HOW TO SET ICON DISPAYED ALONGSIDE THE MESSAGE? Not icon of the windows is my problem, but message icon. HOW CAN I SET THIS ICON? |
|
|
|
|
|
#9 | |
|
Frenzied Member
Join Date: Mar 01
Location: Mars base one Username: Jim Davis Password: yCrm33
Posts: 1,284
![]() ![]() |
Re: VB6 UniMsgBox - Unicode message box class
Quote:
|
|
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|