Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


custom-made msgbox ?

custom-made msgbox ?

custom-made msgbox ?


Can I put my own icons and pictures on msgbox message?

I found no relevant information in the manuals. Is there any trick that do that, or should I custom a msgbox form by myself?

Thanks in advance!

RE: custom-made msgbox ?

>Can I put my own icons and pictures on msgbox message?
Not in vb. There may be ways using APIs but not easily.

>should I custom a msgbox form by myself?
That's the way.

RE: custom-made msgbox ?

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.

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
    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
    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


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.

RE: custom-made msgbox ?

Yep, I've got much the same code. No need to post it now, though ... smile

RE: custom-made msgbox ?

Thank you all!

RE: custom-made msgbox ?

I am the creator of a (very popular) program that allows users to create their own Windows-based message boxes. In order to make said program better, I am updating it to allow the user to create messages using icons from a certain list I've created (thus, using a .RES file).

The following code creates the message box:

If MsgBoxEx((msgtext), (msgtype), (msgtitle), , lstCustomIcons.ListIndex) = vbAbort Or vbCancel Or vbIgnore Or vbNo Or vbOK Or vbRetry Or vbYes Then

msgtext = Text in message box.
msgtype = Depends on what type of box the user wants to create. Example: vbInformation or vbOKonly
msgtitle = Obvious.

lstCustomIcons.ListIndex refers to the ID number of the icon in the .RES file.

msgtext, msgtype and msgtitle are in brackets because every time I tried to compile the program, I got a message saying 'ByRef argument type mismatch'.

So, I wrapped them in the brackets, and that fixed it, but now the custom icons are not showing. What am I doing wrong?

RE: custom-made msgbox ?


Policy around here is generally one questioner per thread so please begin a new thread for your question. You may reference this thread in it if you wish.

When you do that we are going to need a little information about your MsgBoxEx function; e.g. is it something you have written, an alias for an API call etc.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close