|
|
|
|
![]() ![]() |
Nov 23 2005, 03:02 AM
Post
#1
|
|
|
Newbie ![]() Group: Members Posts: 1 Joined: 23-November 05 Member No.: 14,766 |
can i insert other picture in msgbox in VB???,change the font ?
|
|
|
|
Nov 24 2005, 11:49 AM
Post
#2
|
|
|
Neurotical Squirrel ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 590 Joined: 4-November 04 From: Novi Sad, Vojvodina Member No.: 2,127 |
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 |
|
|
|
Nov 24 2005, 02:21 PM
Post
#3
|
|
|
Newbie [Level 1] ![]() Group: Members Posts: 13 Joined: 15-September 05 Member No.: 11,892 |
QUOTE(whitewind @ Nov 23 2005, 08:32 AM) 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. |
|
|
|
Nov 24 2005, 02:40 PM
Post
#4
|
|
|
Trap Grand Marshal Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 1,203 Joined: 25-March 05 Member No.: 4,883 |
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.. |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 12th October 2008 - 05:14 PM |