Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

tg2003 (IS/IT--Management)
24 Jul 08 3:06
Hi,

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!
HughLerwill (Programmer)
24 Jul 08 4:40
>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.
Helpful Member!  Hypetia (Programmer)
24 Jul 08 5:00
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
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

___

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.
strongm (MIS)
24 Jul 08 6:52
Yep, I've got much the same code. No need to post it now, though ... smile
tg2003 (IS/IT--Management)
24 Jul 08 10:55
Thank you all!
GeodesicDragon (Vendor)
17 Aug 08 9:43
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?
 

HughLerwill (Programmer)
17 Aug 08 12:10
GeodesicDragon,

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.

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