Add to Google

How To Customize Msgbox?

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > VB Programming

How To Customize Msgbox?

whitewind
can i insert other picture in msgbox in VB???,change the font ? dry.gif

Reply

Galahad
Hi

I can't tell you exactly,but maybe there is a way to use subclassing to achieve this.Since you are asking this question,you are probably new to Visual Basic,and I actualy didn't help at all.But try looking on the internet,and search for "MsgBox subclassing",or something similar.

Cheers

Reply

TPFWebmaster
QUOTE(whitewind @ Nov 23 2005, 08:32 AM)
can i insert other picture in  msgbox in VB???,change the font ? dry.gif
*


here's the code for that.

Make a module, Module1, and type (or copy-paste) the following code in it:
CODE

Option Explicit

Private Type CWPSTRUCT
       lParam As Long
       wParam As Long
       message As Long
       hwnd As Long
End Type

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Private Const WH_CALLWNDPROC = 4
Private Const GWL_WNDPROC = (-4)
Private Const WM_CTLCOLORBTN = &H135
Private Const WM_DESTROY = &H2
Private Const WM_SETTEXT = &HC
Private Const WM_CREATE = &H1

Private lHook As Long
Private lPrevWnd As Long

Private bCustom As Boolean
Private sButtons() As String
Private lButton As Long
Private sHwnd As String

Public Function SubMsgBox(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
   Dim sText As String
   
   Select Case Msg
   Case WM_CTLCOLORBTN
       'Customize the MessageBox Buttons if neccessary..
       'First Process the Default Action of the Message (Draw the Button)
       SubMsgBox = CallWindowProc(lPrevWnd, hwnd, Msg, wParam, ByVal lParam)
       'Now Change the Button Text if Required
       If Not bCustom Then Exit Function
       If lButton = 0 Then sHwnd = ""
       'If this Button has Been Modified Already then Exit
       If InStr(sHwnd, " " & Trim(Str(lParam)) & " ") Then Exit Function
       sText = sButtons(lButton)
       sHwnd = sHwnd & " " & Trim(Str(lParam)) & " "
       lButton = lButton + 1
       'Modify the Button Text
       SendMessage lParam, WM_SETTEXT, Len(sText), ByVal sText
       Exit Function
       
   Case WM_DESTROY
       'Remove the MsgBox Subclassing
       Call SetWindowLong(hwnd, GWL_WNDPROC, lPrevWnd)
   End Select
   SubMsgBox = CallWindowProc(lPrevWnd, hwnd, Msg, wParam, ByVal lParam)
End Function

Private Function HookWindow(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
   Dim tCWP As CWPSTRUCT
   Dim sClass As String
   'This is where you need to Hook the Messagebox
   CopyMemory tCWP, ByVal lParam, Len(tCWP)
   If tCWP.message = WM_CREATE Then
       sClass = Space(255)
       sClass = Left(sClass, GetClassName(tCWP.hwnd, ByVal sClass, 255))
       If sClass = "#32770" Then
           'Subclass the Messagebox as it's created
           lPrevWnd = SetWindowLong(tCWP.hwnd, GWL_WNDPROC, AddressOf SubMsgBox)
       End If
   End If
   HookWindow = CallNextHookEx(lHook, nCode, wParam, ByVal lParam)
End Function

Public Function MsgBoxEx(ByVal Prompt As String, Optional ByVal Buttons As Long = vbOKOnly, Optional ByVal Title As String, Optional ByVal HelpFile As String, Optional ByVal Context As Long, Optional ByRef CustomButtons As Variant) As Long
   Dim lReturn As Long
   
   bCustom = (Buttons = vbCustom)
   If bCustom And IsMissing(CustomButtons) Then
       MsgBox "When using the Custom option you need to supply some Buttons in the ""CustomButtons"" Argument.", vbExclamation + vbOKOnly, "Error"
       Exit Function
   End If
   lHook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf HookWindow, App.hInstance, App.ThreadID)
   'Set the Defaults
   If Len(Title) = 0 Then Title = App.Title
   If bCustom Then
       'User wants to use own Button Titles..
       If TypeName(CustomButtons) = "String" Then
           ReDim sButtons(0)
           sButtons(0) = CustomButtons
           Buttons = 0
       Else
           sButtons = CustomButtons
           Buttons = UBound(sButtons)
       End If
   End If
   lButton = 0
   
   'Show the Modified MsgBox
   lReturn = MsgBox(Prompt, Buttons, Title, HelpFile, Context)
   Call UnhookWindowsHookEx(lHook)
   'If it's a Custom Button MsgBox, Alter the Return Value
   If bCustom Then lReturn = lReturn - (UBound(CustomButtons) + 1)
   bCustom = False
   MsgBoxEx = lReturn
End Function


The code for creating the custom button will be:
CODE

Dim aButtons(0) As String
   aButtons(0) = "Go"
z = aButtons(MsgBoxEx("Text", vbCustom, "Title", , , aButtons))

Do whatever you feel like with that 'z' in the code.

 

 

 


Reply

Inspiron
Refer to this ..
http://www.trap17.com/forums/index.php?sho...st=10&p=206370&

QUOTE(Inspiron)
You can change the caption, or the title, of any messagebox. The only thing you cannot change is the text of the buttons in a messagebox.

However if you want to have a customised button text, you can make another form that opens as a dialog, to imitate the effects of a messagebox. This way, not even you can customise the button text of the messagebox, you can also add background pictures, sound effects, colors, and even add a customised icon.

Basically just treat the form as a messagebox and customise it..

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. vb6 msgbox remove icon - 5.05 hr back. (1)
  2. vbs msgbox customise - 5.92 hr back. (1)
  3. msgbox customise - 5.97 hr back. (1)
  4. custom buttons msgbox vb 2005 - 8.02 hr back. (1)
  5. messagebox, customized buttons - 8.67 hr back. (1)
  6. mesage box customizations - 10.23 hr back. (1)
  7. msgbox button name - 15.44 hr back. (1)
  8. msgbox subclassed class - 15.79 hr back. (1)
  9. vb6 msgbox button labels - 19.43 hr back. (1)
  10. how to customize the button using php - 21.32 hr back. (1)
  11. customize msgbox font vbscript - 25.04 hr back. (1)
  12. customize vbscript buttons - 32.51 hr back. (1)
  13. excel msgbox tekst in de knoppen aanpassen - 32.88 hr back. (1)
  14. add custom buttons to msgbox - 35.53 hr back. (1)
Similar Topics

Keywords : customize, msgbox

  1. Msgbox
    Here is a simple way and lists of MsgBoxes. (17)


      Looking for customize, msgbox






*SIMILAR VIDEOS*
Searching Video's for customize, msgbox

*MORE FROM TRAP17.COM*
advertisement



How To Customize Msgbox?



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE