MessageBoxIndirect API function offers a feature to display a custom icon. This custom icon must be loaded from an EXE or DLL resource. You can use your own resource from application's EXE/DLL file or load an external resource using LoadLibrary or LoadLibraryEx function.
If you want to display a custom icon, you must add it to your application's resource. You can use VB's Resource Editor add-in for this purpose. Alternatively, you can use icons embedded in an external DLL file.
See the following code. The wrapper function MsgBoxEx has most of the features of MsgBox function, in addition to displaying custom icons if you want.
___
[tt]
Private Declare Function MessageBoxIndirect Lib "user32" Alias "MessageBoxIndirectA" (lpMsgBoxParams As MSGBOXPARAMS) As Long
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Type MSGBOXPARAMS
cbSize As Long
hwndOwner As Long
hInstance As Long
lpszText As String
lpszCaption As String
dwStyle As Long
lpszIcon As Long
dwContextHelpId As Long
lpfnMsgBoxCallback As Long
dwLanguageId As Long
End Type
Const MB_USERICON = &H80&
Private Function MsgBoxEx(Prompt As String, Optional Buttons As VbMsgBoxStyle, Optional Title As String, Optional hResource As Long, Optional IconResource As Long) As VbMsgBoxResult
Dim mbp As MSGBOXPARAMS
mbp.cbSize = Len(mbp)
mbp.lpszText = Prompt
mbp.dwStyle = Buttons
mbp.hwndOwner = GetActiveWindow()
mbp.lpszIcon = IconResource
mbp.hInstance = IIf(hResource, hResource, App.hInstance)
mbp.lpszCaption = IIf(Len(Title), Title, App.Title)
mbp.dwStyle = IIf(IconResource, Buttons Or MB_USERICON, Buttons)
MsgBoxEx = MessageBoxIndirect(mbp)
End Function
Private Sub Form_Load()
MsgBoxEx "Standard message box, like MsgBox.", vbInformation
'---
MsgBoxEx "Message box with custom icon from application's own resource (in this case, VB6.EXE).", , "Palette", , 1257
'---
Dim hLib As Long
hLib = LoadLibrary("shell32.dll")
MsgBoxEx "Message box with custom icon loaded from an external resource (shell32.dll).", , "Tree", hLib, 42
FreeLibrary hLib
'---
Unload Me
End Sub[/tt]
___
Note that when you use custom icon from your own application resource, the correct icon is not displayed in IDE because App.hInstance returns the instance handle of VB6.EXE. To check if the icon is correctly displayed, you need to compile your app and run the EXE.