GeneM
asked on
Need a MsgBox with 3 buttons
Hi Experts,
I need a MsgBox with 3 buttons: Yes, No, & Print.
Of course, I could build my own form with those 3 buttons, but I thought there might be a way of doing it without adding another form.
Does anyone know how to do something like this?
GeneM
I need a MsgBox with 3 buttons: Yes, No, & Print.
Of course, I could build my own form with those 3 buttons, but I thought there might be a way of doing it without adding another form.
Does anyone know how to do something like this?
GeneM
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i would have to agree. you should just create a simple vb form to act as your messagebox.
it is pretty simple anyway.
it is pretty simple anyway.
Here is a solution, but it takes 2 files to accomplish it...
1) compile exe that can change the cancel button text to print
2) run your code and right before your call the msgbox, shell your exe created in step 1.
1)
Option Explicit
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, _
ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" _
(ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch 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 Const WM_SETTEXT = &HC
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDLAST = 1
Private Const GW_HWNDNEXT = 2
Private Const GW_HWNDPREV = 3
Private Const GW_OWNER = 4
Private Const GW_CHILD = 5
Private Sub Form_Load()
Dim lTimer As Long
Dim hWindow As Long
lTimer = Timer()
Do
hWindow = FindFirstWindowLike(0&, "Cancel")
DoEvents
Loop Until hWindow <> 0 Or Timer() - lTimer > 10000
Call SendMessage(hWindow, WM_SETTEXT, 0&, ByVal "Print")
Unload Me
End Sub
Public Function FindFirstWindowLike(ByVal hwndStart As Long, _
ByVal WindowText As String) As Long
Dim hwnd As Long
Dim hwnd2 As Long
Dim sWindowText As String
Dim sClassname As String
Dim r As Long
'Hold the level of recursion and hold the number of matching windows
Static level As Integer
'Initialize if necessary. This is only executed when level = 0
'and hWndStart = 0, normally only on the first call to the routine.
If level = 0 Then
If hwndStart = 0 Then hwndStart = GetDesktopWindow()
End If
'Increase recursion counter
level = level + 1
'Get first child window
hwnd = GetWindow(hwndStart, GW_CHILD)
Do Until hwnd = 0
'Search children by recursion
hwnd2 = FindFirstWindowLike(hwnd, WindowText)
If hwnd2 <> 0 Then
FindFirstWindowLike = hwnd2
Exit Do
End If
'Get the window text and class name
sWindowText = Space$(255)
r = GetWindowText(hwnd, sWindowText, 255)
sWindowText = Left(sWindowText, r)
'Check if window found matches the search parameters
If (sWindowText Like WindowText) Then
FindFirstWindowLike = hwnd
Exit Do
End If
'Get next child window
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Loop
'Reduce the recursion counter
level = level - 1
End Function
2) In your program to display msgbox..
Option Explicit
Private Sub Form_Load()
Shell "c:\cmdprint.exe"
If MsgBox("Hello", vbYesNoCancel, "My MsgBox") = vbCancel Then
MsgBox "You Clicked Print"
End If
Unload Me
End Sub
1) compile exe that can change the cancel button text to print
2) run your code and right before your call the msgbox, shell your exe created in step 1.
1)
Option Explicit
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, _
ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" _
(ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch 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 Const WM_SETTEXT = &HC
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDLAST = 1
Private Const GW_HWNDNEXT = 2
Private Const GW_HWNDPREV = 3
Private Const GW_OWNER = 4
Private Const GW_CHILD = 5
Private Sub Form_Load()
Dim lTimer As Long
Dim hWindow As Long
lTimer = Timer()
Do
hWindow = FindFirstWindowLike(0&, "Cancel")
DoEvents
Loop Until hWindow <> 0 Or Timer() - lTimer > 10000
Call SendMessage(hWindow, WM_SETTEXT, 0&, ByVal "Print")
Unload Me
End Sub
Public Function FindFirstWindowLike(ByVal hwndStart As Long, _
ByVal WindowText As String) As Long
Dim hwnd As Long
Dim hwnd2 As Long
Dim sWindowText As String
Dim sClassname As String
Dim r As Long
'Hold the level of recursion and hold the number of matching windows
Static level As Integer
'Initialize if necessary. This is only executed when level = 0
'and hWndStart = 0, normally only on the first call to the routine.
If level = 0 Then
If hwndStart = 0 Then hwndStart = GetDesktopWindow()
End If
'Increase recursion counter
level = level + 1
'Get first child window
hwnd = GetWindow(hwndStart, GW_CHILD)
Do Until hwnd = 0
'Search children by recursion
hwnd2 = FindFirstWindowLike(hwnd, WindowText)
If hwnd2 <> 0 Then
FindFirstWindowLike = hwnd2
Exit Do
End If
'Get the window text and class name
sWindowText = Space$(255)
r = GetWindowText(hwnd, sWindowText, 255)
sWindowText = Left(sWindowText, r)
'Check if window found matches the search parameters
If (sWindowText Like WindowText) Then
FindFirstWindowLike = hwnd
Exit Do
End If
'Get next child window
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Loop
'Reduce the recursion counter
level = level - 1
End Function
2) In your program to display msgbox..
Option Explicit
Private Sub Form_Load()
Shell "c:\cmdprint.exe"
If MsgBox("Hello", vbYesNoCancel, "My MsgBox") = vbCancel Then
MsgBox "You Clicked Print"
End If
Unload Me
End Sub
ASKER
Hi all,
Thanks to all who participated. It looks like the simple way is to code the additional form, which I have done. I gave the points to advapp because he was first out of the chute to recommend that. He also said something about hooking the message box, but I am not a hooker!
bukko had a very good suggestion. However, I had trouble getting in contact with the Grand Council of the English Language, so I had to give up on his idea! In case you have forgotten, he recommended changing the meaning of the word "Cancel" to mean print.
emoreau pointed me to a good solution, but I just thought it was a little too complex for me.
aaklund, where did all that code come from?? I just didn't want to make a simple problem that complex!!
Anyway, thanks to all who participated.
GeneM
Thanks to all who participated. It looks like the simple way is to code the additional form, which I have done. I gave the points to advapp because he was first out of the chute to recommend that. He also said something about hooking the message box, but I am not a hooker!
bukko had a very good suggestion. However, I had trouble getting in contact with the Grand Council of the English Language, so I had to give up on his idea! In case you have forgotten, he recommended changing the meaning of the word "Cancel" to mean print.
emoreau pointed me to a good solution, but I just thought it was a little too complex for me.
aaklund, where did all that code come from?? I just didn't want to make a simple problem that complex!!
Anyway, thanks to all who participated.
GeneM
There is another way to do it.
1) Persuade the grand council of the English Language to transpose the meanings of the words "Cancel" and "Print".
2) Response = MsgBox( "Prompt", vbYesNoCancel, "Title" )
Regards
bukko
:)