Link to home
Start Free TrialLog in
Avatar of yongyih
yongyihFlag for Malaysia

asked on

Messagebox

HI All,
 
  I would like to know the easiest way to display a message box with 5 buttons.  Like
1. Yes
2. Yes to all
3. No.
4. Not to all.
5. Cancel.

  It is like the message when you copy paste a lot of files to a folder that containt same files.  Windows will ask you whether you want to overwrite or not.

  Any idea?

Regards,
YY
Avatar of Tarnge
Tarnge

If you have MS Visual Studio you can use the Insert > Resource (Ctrl + R). Then click Dialog, and drag and drop the icons onto your dialog box!!

Otherwise:
If you know how to, Create your a Window class (I presume you're doing this anyway to open your program) that resembles the dialog box you want to use. Then you create a window (CreateWindowEx()) based on your new window class. Using this new window (the handle for it) you can add buttons to it doing something like this: -

CreateWindowEx(NULL,
      "BUTTON",
      "Yes To All",
      WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
      16, 16,      // x, y
      100, 24,      // w, h
      hwnd,
      (HMENU)(100), // change this number for each control
      hinstance,
      NULL);

Where it says hwnd, replace this with the handle to your dialog, and it should attach to the dialiog box. (Lookup CreateWindowEx() in your online help for full info or see MSDN on the microsoft website cos it's all there).

You take care of the code when it's pressed by giving it a WinProc with an 'msg' variable (like the one for your main window), and use the WM_COMMAND message. When you've attached a number of buttons to your dialog window, the same WM_COMMAND message is used for all the messages, so you do something like this: -

switch (msg)
{
case WM_COMMAND:
      switch(LOWORD(wparam))
                {
            case 100: // The number entered in the CreateWindowEx() bit
                  MessageBox(hwnd, "Code for add button", "Add", MB_OK | MB_ICONASTERISK);
                  break;
            default:
                  break;
      }
      break;  // This must be here!
case WM_DESTROY:
      // Send a WM_QUIT Message
      PostQuitMessage(0);
      return (0);
      break;

default:
      break;
}

If you're not this comfortable with Windows API say and I'll try to explain a bit simpler.
Hi yongyih:
Will help if you inform us what your programming/application environmnet you are using

Dabas
Avatar of yongyih

ASKER

Oh! Sorry. I think I posted my question to the wrong area.  Haha.. I am using Visual Basic 6.0.
Sorry.

yongyih:
In VB6, it is not difficult to create a new form with exactly the buttons you want.
You then just show the form Modally

Dabas
Avatar of yongyih

ASKER

But how about the return value?  May be I need to use it in a lot of forms.  How to make the flexible enough to call from different forms and get the returned value?
ASKER CERTIFIED SOLUTION
Avatar of Dabas
Dabas
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yongyih

ASKER

What if I want to set the message box message? How to make the form accept parameters from other forms?
yongyih:
You can set up the form before you show it.

frmMessage.Text1 = "This is my message"
frmMessage.Show, vbModal


Dabas
try using
msgbox "text",vbok & vbcancel & vbokonly, "title"

you get the idea.
Avatar of yongyih

ASKER

hi,

  I think that will not get what I want.  What I want is "Yes to all" and "No to all" button.

  Thanks.

Then in that case, follow dabas' suggestion as that will work perfectly and basically solves all your queries.