Results 1 to 8 of 8

Thread: Is it possible to subclass the MsgBox?

  1. #1

    Thread Starter
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Arrow Is it possible to subclass the MsgBox?

    I need the msgbox just with captions of buttons changed.
    I want to avoid creating a new form as it would need a lot of efforts to make it behave it like msgbox.

    e.g.
    VB Code:
    1. resp = MsgBox("What do you want to Print?", vbYesNoCancel + vbQuestion, "Choose an option")
    But instead of the Yes, No , Cancel buttons, I want Print Current, Print All, Cancel Printing

    Pradeep
    Last edited by Pradeep1210; Oct 11th, 2005 at 10:17 AM.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Is it possible to subclass the MsgBox?

    Quote Originally Posted by Pradeep1210
    I need the msgbox just with captions of buttons changed.
    I want to avoid creating a new form as it would need a lot of efforts to make it behave it like msgbox.
    And you think it won't take a lot of effort to subclass a message box and add the buttons, and the functionality behind the buttons, to a standard message box????

    I found one example through Google, and it does, work, but it is nasty, and the results, even though it does add a new button, is kind of nasty.

    If you want it, I'll post it, but I think you should rethink your position on not using a Form of your own for this.

  3. #3
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: Is it possible to subclass the MsgBox?

    hi I agree with the above. it's whould take far more time and effot, tho if you really want to you can have a look at an example I made.

    Now note this does not subclass a messagebox but a inputbox box, but it can be changed to a message box, just replace in the code that calls to the inputbox function with a messagebox name. and it will work

    anyway this inputbox replacement has many chnages, background, text color, automatic closeing timer, and alphablending o and also finding out what button was pressed.

    ps all code is commented.

    http://www.pscode.com/vb/scripts/Sho...62548&lngWId=1

    hope if may give you an idea
    When your dreams come true.
    On error resume pulling hair out.

  4. #4

    Thread Starter
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Is it possible to subclass the MsgBox?

    Hack:
    This was just an example. I have many places in my app were I feel a MsgBox would suffice if just the captions of the buttons were different.
    I could make my own form but it takes a lot of efforts to positon the buttons (1/2/3 buttons), set the default button, set the icon on the left, automatically adjust the label caption and the form and many more things the msgbox does. So my form doesn't look that professional as it would have looked with a standard Msgbox. What I need to do is just change the Captions of buttons being desplayed.

    Why I asked this question is that the Msgbox has been implemented as a function in VB and I don't know how to subclass functions.

    DreamVB:
    Your solution seems to be the perfect thing for what I was looking (bonus - I would know how to subclass the inputbox also). I'll just have a look at your code and get back here.

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  5. #5
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Is it possible to subclass the MsgBox?

    If all he wants to do is change the captions then the solution is alot simpler than adding a completely new button to the messagebox.

    PSCode has 2 or 3 examples of changing the captions (1 of them I've seen must have been dreamvb's), and on the forums people have asked a few times before.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  6. #6
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Is it possible to subclass the MsgBox?


    Visual Studio 6, Visual Studio.NET 2005, MASM

  7. #7

  8. #8

    Thread Starter
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Is it possible to subclass the MsgBox?

    Chem & Marty:

    It looks great and the solution to my problems. But how do I add the icons to the MsgBoxEx like vbInformation, vbQuestion etc. ?

    Thanks,

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width