Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Custom messagebox

princeofabyssprinceofabyss Posts: 12Member
Can anyone help me to slightly alter a Yes/No Messagebox, in a way that buttons' captions are Agree/Disagree, instead of Yes/No?

I did a thorough search on the net on similar problems, but the only one that was close to my problem can be found in http://vbnet.mvps.org/index.html?code/hooks/messageboxhook.htm, which is also for VB6, while I want to find a solution (since I can't create it myself) for VB.NET.

Please, if anyone is interested in helping me, don't tell me to create a DialoxBox form. I just want to customize a messagebox. Thanks.

Petros.
«1

Comments

  • iwilld0itiwilld0it Posts: 1,134Member
    : Can anyone help me to slightly alter a Yes/No Messagebox, in a way that buttons' captions are Agree/Disagree, instead of Yes/No?
    :
    : I did a thorough search on the net on similar problems, but the only one that was close to my problem can be found in http://vbnet.mvps.org/index.html?code/hooks/messageboxhook.htm, which is also for VB6, while I want to find a solution (since I can't create it myself) for VB.NET.
    :
    : Please, if anyone is interested in helping me, don't tell me to create a DialoxBox form. I just want to customize a messagebox. Thanks.
    :
    : Petros.
    :

    I belive you can accompolish this with the MessageBoxEx() Win32 API function.
  • princeofabyssprinceofabyss Posts: 12Member
    : I belive you can accompolish this with the MessageBoxEx() Win32 API function.
    :

    But how do I use this API in VB.NET? Can you give me an example plz?
  • rlcrlc Posts: 448Member
    Depending on what for, and how often you use this message box you can make a form and call the function to show as dialog, which will replace the functionality of a message box. But it will take more resources to create a form.

    ~rlc
  • princeofabyssprinceofabyss Posts: 12Member
    : Depending on what for, and how often you use this message box you can make a form and call the function to show as dialog, which will replace the functionality of a message box. But it will take more resources to create a form.
    :
    : ~rlc
    :
    I think I made it clear that I don't want a dialog form. Can you give me instead an example of how to feature a MessaboxEx for my app?
  • kainsworthkainsworth Posts: 200Member
    What's the big deal with the messagebox?

    It's perfectly possible to create a form that looks to the user *exactly* like a messagebox but with a lot of additional functionality - far more than the minor tweak you have in mind.

    Why are you so set on using the built-in messagebox (butchered via API) when there is an easy workaround available?

    =================================================================


    : :
    : I think I made it clear that I don't want a dialog form. Can you give me instead an example of how to feature a MessaboxEx for my app?
    :

  • iwilld0itiwilld0it Posts: 1,134Member
    : Can anyone help me to slightly alter a Yes/No Messagebox, in a way that buttons' captions are Agree/Disagree, instead of Yes/No?
    :
    : I did a thorough search on the net on similar problems, but the only one that was close to my problem can be found in http://vbnet.mvps.org/index.html?code/hooks/messageboxhook.htm, which is also for VB6, while I want to find a solution (since I can't create it myself) for VB.NET.
    :
    : Please, if anyone is interested in helping me, don't tell me to create a DialoxBox form. I just want to customize a messagebox. Thanks.
    :
    : Petros.
    :

    First off, here is the Win32 API documentation for MessageBoxEx()

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/dialogboxreference/dialogboxfunctions/messageboxex.asp

    Second, here is hat the VB.NET declaration of the function looks like ...

    [code]
    Declare Function MessageBoxEx Lib "user32" Alias "MessageBoxExA" ( _
    ByVal hwnd As IntPtr, _
    ByVal lpText As String, _
    ByVal lpCaption As String, _
    ByVal uType As Integer, _
    ByVal wLanguageId As Integer) As Integer
    [/code]

    Here is a .NET article that shows an example, but the code is in C#. But the code should not be hard to convert to VB.NET.

    http://www.knowdotnet.com/articles/advancedapicalls.html

    There is isn't much more documentation in the web. I do recommend taking a look at the book ...

    .NET Framework Solutions: In Search of the Lost Win32 API

    Check it out at Amazon ...

    http://www.amazon.com/exec/obidos/tg/detail/-/078214134X/qid=1097069248/sr=1-1/ref=sr_1_1/002-5776929-6086441?v=glance&s=books

    The book has a detailed example of the MessageBoxEx function in both vb and c#



  • rlcrlc Posts: 448Member
    [b][red]This message was edited by rlc at 2004-10-6 8:2:22[/red][/b][hr]
    Yes it can be done, but why is a good question? I would think it would be preferable to use managed code when possible... Going to the API function will circumvent this, the framework will need to use the interop service to create a wrapper to the messagebox and its objects from the api. Obviously for some toolkits components previously developed this is great. But for a simple form, other than being comfortable using the API from past work, I am not sure what the benefit is.

    ~rlc


  • princeofabyssprinceofabyss Posts: 12Member
    First of all I'd like to thank you for answering on my question instead of arguing on my choice to use a Messagebox (MessageBoxEx in the case) like all the others did...

    But, are you sure that one can actually change the buttons' captions using a MessageBoxEx? I went to the link you gave me, and also studied the MessageBoxEx API, but it didn't say anywhere that you can change the captions of the buttons. What was pretty clear to me is that it can show captions in a pre-selected language set, rather than change them to whatever else the user would like to. Additionally, it can display a Help button passing the correct error id to the program to show the appropriate help.

    Can you supply a better example maybe, showing exactly that you can change the captions to Whatever you like, such as 'Agree/Disagree' ?

    I'll be grateful if you do so. Anyway, thanks for your time.

    Petros.
  • princeofabyssprinceofabyss Posts: 12Member
    : : Can anyone help me to slightly alter a Yes/No Messagebox, in a way that buttons' captions are Agree/Disagree, instead of Yes/No?
    : :
    : : I did a thorough search on the net on similar problems, but the only one that was close to my problem can be found in http://vbnet.mvps.org/index.html?code/hooks/messageboxhook.htm, which is also for VB6, while I want to find a solution (since I can't create it myself) for VB.NET.
    : :
    : : Please, if anyone is interested in helping me, don't tell me to create a DialoxBox form. I just want to customize a messagebox. Thanks.
    : :
    : : Petros.
    : :
    :

    If you go to http://vbnet.mvps.org/index.html?code/main/tocbyuse.htm you will see EXACTLY what I want. The only problem is that it is VB6. I managed to convert it into VB.NET except for the AddressOf expression that is somewhere in the code. Can you please revise the code apropriately so that it works in VB.NET?

    I NEED so much to customise the buttons' captions in my app, but I can't use a DialogBox form, as there are dozens of similar messagebox, and it will be a hell to create a DialogBox form for each one of them...

    Thanks,
    Petros.
    : First off, here is the Win32 API documentation for MessageBoxEx()
    :
    : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/dialogboxreference/dialogboxfunctions/messageboxex.asp
    :
    : Second, here is hat the VB.NET declaration of the function looks like ...
    :
    : [code]
    : Declare Function MessageBoxEx Lib "user32" Alias "MessageBoxExA" ( _
    : ByVal hwnd As IntPtr, _
    : ByVal lpText As String, _
    : ByVal lpCaption As String, _
    : ByVal uType As Integer, _
    : ByVal wLanguageId As Integer) As Integer
    : [/code]
    :
    : Here is a .NET article that shows an example, but the code is in C#. But the code should not be hard to convert to VB.NET.
    :
    : http://www.knowdotnet.com/articles/advancedapicalls.html
    :
    : There is isn't much more documentation in the web. I do recommend taking a look at the book ...
    :
    : .NET Framework Solutions: In Search of the Lost Win32 API
    :
    : Check it out at Amazon ...
    :
    : http://www.amazon.com/exec/obidos/tg/detail/-/078214134X/qid=1097069248/sr=1-1/ref=sr_1_1/002-5776929-6086441?v=glance&s=books
    :
    : The book has a detailed example of the MessageBoxEx function in both vb and c#
    :
    :
    :
    :

  • rlcrlc Posts: 448Member
    [b][red]This message was edited by rlc at 2004-10-8 7:35:53[/red][/b][hr]
    Easy Tiger, just trying to help you out. You should welcome advise from others, I do, part of learning more.

    Did you try importing, just like messagebox, the API function to change it like in VB6.0?


    Declare Function SetDlgItemText Lib "user32" Alias "SetDlgItemTextA" (ByVal hDlg As Integer, ByVal nIDDlgItem As Integer, ByVal lpString As String) As Integer

    !-----

    Missed that last part: addressof() is only for function addresses.

    try this maybe: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=463&lngWId=10

    ~rlc


«1
Sign In or Register to comment.