?
Solved

Need a MsgBox with 3 buttons

Posted on 2003-03-25
6
Medium Priority
?
283 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:GeneM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Accepted Solution

by:
advapp earned 600 total points
ID: 8206629
Well, you probably won't like this answer but...
There are only two ways I know of to accomplish this:  1) create a simple form to do this, and 2) use the Win32 API to hook the message box and add a third button.

I'm not sure why you wouldn't just want to create the form because it really is the logical way to do this.  Truth is, I only listed the 2nd option to emphasize that the best and easiest way to do this is the 1st way.
0
 
LVL 8

Expert Comment

by:bukko
ID: 8206839

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

:)

0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 8207096
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Expert Comment

by:Sandwich
ID: 8207627
i would have to agree. you should just create a simple vb form to act as your messagebox.
it is pretty simple anyway.
0
 
LVL 10

Expert Comment

by:aeklund
ID: 8207691
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
0
 
LVL 3

Author Comment

by:GeneM
ID: 8214650
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
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question