?
Solved

Need a MsgBox with 3 buttons

Posted on 2003-03-25
6
Medium Priority
?
286 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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

580 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