Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

custom-made msgbox ? 1

Status
Not open for further replies.

tg2003

IS-IT--Management
Joined
Feb 6, 2003
Messages
270
Location
IL
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!
 
>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.
 
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.
 
Yep, I've got much the same code. No need to post it now, though ... :-)
 
Thank you all!
 
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?


 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top