MessageBox


Message Box

A simple way to show messages in a program is by using a Message Box. The message box has an image or icon to indicate: Error, Warning, Question or Information. The Message Box may include some buttons, such as: OK, Cancel, Yes, No, Abort, etc. The figure below shows a common Message Box to display an error.
Una forma simple de mostrar mensajes en un programa es usando una Caja de Mensajes. La caja de mensajes tiene una imagen o un icono para indicar: Error, Advertencia, Pregunta o Información. La caja de mensajes puede incluir algunos botones, tales como: Aceptar, Cancelar, Si, No, Abortar, etc. La figura debajo muestra una caja de mensajes común para mostrar un error.

MessageBox

Problem 1
Indicate whether the following statement is true or false: The Message Box is useful because begins a dialog with the user and allows the user to continue with his work without forcing him to answer.
Diga si el siguiente enunciado es cierto o falso: La Message Box es muy útil porque inicia un diálogo con el usuario y deja al usuario continuar con su trabajo sin obligarlo a responder.

Problem 2
Open Microsoft Visual Studio and execute the commands as shown:

File > New > Project > Visual C++ >Wintempla
Select: Dialog Application
Set the project name: Program
Press: Finish
Write the code below inside the function Window_Open.
Execute the code: Debug > Start debugging
A message box will be displayed as shown in the figure below.

If you are using Microsoft Visual Studio 2019, select "Create New Project" on the welcome screen and select "Dialog Application".
Abre Microsoft Visual Studio y ejecute los comando como se muestra:

File > New > Project > Visual C++ >Wintempla
Selecciona: Dialog Application
Fija el nombre del projecto: Program
Presiona: Finish
Escribe el código mostrado debajo dentro de la función Window_Open.
Ejecuta el código: Depuración > Iniciar Depuración
Una caja de mensaje se mostrará como se observa en la figura debajo.

Si usted está usando Microsoft Visual Studio 2019, seleccione "Create New Project" en la pantalla de bienvenida y seleccione "Dialog Application".

MicrosoftVisualStudio2019

Program.cpp
void Program::Window_Open(Win::Event& e)
{
     this->MessageBox(L"Hello World", L"Wintempla", MB_OK);
}


CppHelloWorld

Problem 3
Open Microsoft Visual Studio and execute the commands as shown:
  1. File > New > Project > Visual C# > Windows Classic Desktop > Windows Forms Application
  2. Set the project name: ProgramS
  3. Press: Finish
  4. Open Solution Explorer, then open and edit the Program.cs file as shown
  5. Execute the code: Debug > Start debugging
A message box similar to the one of the last problem will be shown.
Abre Microsoft Visual Studio y ejecuta los comandos como se muestra:
  1. File > New > Project > Visual C# > Windows Classic Desktop > Windows Forms Application
  2. Fije el nombre del projecto: ProgramS
  3. Presione: Finish
  4. Abra Solution Explorer, entonces abra y edite el archivo Program.cs como se muestra
  5. Ejecuta el código: Depuración > Iniciar Depuración
Una caja de mensaje como la del problema anterior se mostrará.

NewCS

Program

Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProgramS
{
     static class Program
     {
          /// <summary>
          /// The main entry point for the application.
          /// </summary>
          [STAThread]
          static void Main()
          {
               Application.EnableVisualStyles();
               Application.SetCompatibleTextRenderingDefault(false);
               //Application.Run(new Form1());
               MessageBox.Show("Hello World", "C Sharp");
          }
     }
}


ProgramSRun

Problem 4
Open Netbeans and execute the commands as shown:
File > New > Project > Java > Java Desktop Application
Set the project name: ProgramJ
Press: Finish
Use the Navigator and the files Tabs to edit the file ProgramJ.java as shown
Execute the code: Click the debug button
A message box similar to the one of the last problem will be shown.

Abre Netbeans y ejecuta los comando como se muestra:
File > New > Project > Java > Java Desktop Application
Fija el nombre del projecto: ProgramJ
Presiona: Finish
Usar el Navigator y los tabs de archivos para editar el archivo ProgramJ.java
Ejecuta el código: Presiona el butón de depuración o ejecución
Una caja de mensaje como la del problema anterior se mostrará.

ProgramJ.java
public class Main
{
     public static void main(String[] args)
     {
          javax.swing.JOptionPane.showMessageDialog(null,"Hello World");
     }
}


Tip
In C++ the button in the message box can be any of: MB_OK, MB_OKCANCEL, MB_ABORTRETRYIGNORE, MB_YESNOCANCEL, MB_YESNO, MB_RETRYCANCEL.
En C++ los botones de la caja de mensajes pueden ser: MB_OK, MB_OKCANCEL, MB_ABORTRETRYIGNORE, MB_YESNOCANCEL, MB_YESNO, MB_RETRYCANCEL.

Tip
In C++ the icon in the message box can be any of: MB_ICONQUESTION, MB_ICONWARNING, MB_ICONERROR, MB_ICONINFORMATION.
En C++ el icono de la caja de mensajes pueden ser: MB_ICONQUESTION, MB_ICONWARNING, MB_ICONERROR, MB_ICONINFORMATION.

Problem 5
Create a project called Question using Wintempla following the steps of Problem 2. Write the code shown below.
Cree un proyecto llamado Question usando Wintempla siguiendo los pasos del Problema 2. Escriba el código mostrado debajo.

Program.cpp
void Program::Window_Open(Win::Event& e)
{
     const int answer = this->MessageBox(L"Do you want to close?", L"Wintempla", MB_YESNO | MB_ICONQUESTION);
     //if (answer == IDYES)
     //{
     //}
     //else if (answer == IDNO)
     //{
     //}
}


CppQuestion

Tip
A program is a sequence of computer commands. A program is similar to a task list: the computer is given this list, then, it starts executing the orders in the list until it reaches the end of the list.
Un programa es una secuencia de comando para la computadora. Un programa es similar a una lista de tareas: la computadora recibe esta lista, entonces, esta comienza a ejecutar las órdenes en la lista hasta que esta llega al final de la lista.

Problem 6
Create a project called Sequence using Wintempla to open two Message Boxes in sequence as shown below. Note that the second message box will open when the first is close.
Cree un proyecto llamado Sequence usando Wintempla para que se abran dos cajas de mensajes en secuencia como se muestra debajo. Note que la segunda caja de mensajes se abrirá cuando la primera se cierre.

Sequence

© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home