none
Need to translate the yes/no button in a message box to a different language without creating custom message box in c# RRS feed

  • Question

  • Hi All,

    I've a requirement where I have to change the language of the message box "Yes/No" buttons !So far I've not found any property for message box that can change the text of the buttons . Also I don't want to create a custom message box and change language.

    Also is it possible to make the message box not have the close button, instead of disabled close button on the message box ?

    Please help!!

    Thanks,

    Vidya


    Vidya Suryanarayana


    • Edited by vidya_01 Monday, July 23, 2012 11:17 AM
    • Changed type Mike FengModerator Tuesday, July 24, 2012 9:19 AM This is a question.
    Monday, July 23, 2012 11:15 AM

Answers

All replies

  • You don't mention your programming language or framework, so I'll assume it is C# and Windows Forms.

    There are two ways to obtain the desired results, I would say:

    1. A CBT hook that monitors dialog box creation.  When the dialog box is created, the window style WS_SYSMENU is removed.  this should get rid of the close button in the upper right corner.
    2. A new thread is created that attempts to find the dialog box via FindWindow().  When it is found, the same technique is applied to remove the close button.

    In both cases I would attempt a WM_SETTEXT message to rename the buttons.  Since this message number is below WM_USER, the system will handle marshaling of pointer data if the message crosses the process boundaries, so no worries there, but I must say I have never done this before.  Do your testing.

    If you don't understand any of the concepts touched in this reply, let me know.  I might be able to explain further or direct you to documentation.


    Jose R. MCP
    Code Samples

    Monday, July 23, 2012 1:50 PM
  • Hi Jose,

    Thank you very much. I'm working on c# windows application, .net f/w 3.5 sp1.

    Can you please explain further, on how i can use these WS_SYSMENU and other such things from my code??

    Thanks,

    Vidya


    Vidya Suryanarayana

    Tuesday, July 24, 2012 4:00 AM
  • Hi Vidya,

    Welcome to the MSDN Forum.

    Please take a look at this project: http://www.codeproject.com/Articles/18399/Localizing-System-MessageBox

      It shows what webjose suggested.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by vidya_01 Wednesday, July 25, 2012 10:21 AM
    Tuesday, July 24, 2012 9:18 AM
    Moderator
  • Thanks Mike!

    I checked out the link and tried using the MessageBoxManager.dll in my App. I referenced it and the dll was not recognized in the namespace and failed to compile.

    I'm not sure how well I can use the native code that is used in the codeproject app.

    Dunno what to do at the moment.

    Regards,

    Vidya


    Vidya Suryanarayana

    Wednesday, July 25, 2012 6:52 AM
  • Hi Vidya,

    The code in the codeproject is not native code. It is a managed reference, you can add it as the same as your other .net reference, exception the difference which you need to find the reference with "Browse" tab, rather than ".Net".

    If it still doesn't work, please show me the details of the exceptions or errors. Thank you.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 25, 2012 8:53 AM
    Moderator
  • Of course i did that. But during compilation, it throws an error telling it was not able to recognize the dll referenced.

    Thanks,

    Vidya


    Vidya Suryanarayana

    Wednesday, July 25, 2012 8:57 AM
  • Hi Vidya,

    If so, please delete it and add it again.

    Thank you.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 25, 2012 9:03 AM
    Moderator
  • It is working great!

    Actually i was trying to reference it in the class file as well after adding the reference dll.

    It was not required.

     Btw, it is working fine and I appreciate your help very much.Thanks :)

    Just one more thing, how can i remove the close option in the messagebox?Is there a way to show the messagebox without the "X" button? As of now it is disabled.

    Thanks and Regards,

    Vidya


    Vidya Suryanarayana

    Wednesday, July 25, 2012 10:24 AM
  • Hi Vidya,

    Why do you intend to remove the "X" button?

    When the user click on the X button, you can handle it as the same as OK or cancel button as you wish. Anyway, here is the code to disable the close button:

    1. Declare such APIs and const:

            [DllImport("User32.dll")]
            private static extern int RemoveMenu(IntPtr hMenu, int nPosition, int wFlags);
            
            [DllImport("User32.dll")]
            private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
    
            [DllImport("User32.dll")]
            private static extern int GetMenuItemCount(IntPtr hWnd);
    
            [DllImport("User32.dll")]
            private static extern bool DrawMenuBar(IntPtr hWnd);
    
    
            private const int MF_BYPOSITION = 0x400;

    2. Change the if block in the MessageBoxHookProc method:

                if (msg.message == WM_INITDIALOG)
                {
                    int nLength = GetWindowTextLength(msg.hwnd);
                    StringBuilder className = new StringBuilder(10);
                    GetClassName(msg.hwnd, className, className.Capacity);
                    if (className.ToString() == "#32770")
                    {
                        nButton = 0;
                        EnumChildWindows(msg.hwnd, enumProc, IntPtr.Zero);
                        if (nButton == 1)
                        {
                            IntPtr hButton = GetDlgItem(msg.hwnd, MBCancel);
                            if (hButton != IntPtr.Zero)
                                SetWindowText(hButton, OK);
                        }
                    }
                    IntPtr hwnd = GetSystemMenu(msg.hwnd, false);
                    int count = GetMenuItemCount(hwnd);
                    RemoveMenu(hwnd, count - 1, MF_BYPOSITION);                
                    DrawMenuBar(hwnd);
                }

    Actually, I have added four lines code in the block.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Thursday, July 26, 2012 2:24 AM
    Moderator
  • Thanks Mike! The "x" button is disabled as of now.

    The testers have issue with it being seen!!!!! It shouldn't be enabled also.

    So i have to remove the "x" button from the message box.

    Best Regards,

    Vidya


    Vidya Suryanarayana

    Thursday, July 26, 2012 4:00 AM
  • Hi Vidya,

    >>The testers have issue with it being seen!!!!! It shouldn't be enabled also.

    When I found it, I will post it here.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, July 27, 2012 5:39 AM
    Moderator