Using the Message Box Default Reply Component (Standard 2009)

4/24/2012

Microsoft Corporation

October 2009

Summary

This technical article provides an overview of the Message Box Default Reply component in Windows Embedded Standard 2009. It also explains how the feature is designed, and how developers can configure and use the component in their device.

Introduction

Feature Design Explained

Message Box Default Reply Component Configuration Options

Conclusion

Introduction

The Windows API has a MessageBox function that displays a dialog box that can contain text, buttons, and symbols. Message boxes can be informational, such as when they provide status or error information, and they can ask the user to select from a list of options.

Note

Dialog boxes are either modal or modeless. Users must close a modal dialog box before they can continue to work with the rest of the application. Modeless dialog boxes let users shift the focus between the initial dialog box and any other dialog boxes or applications, without having to close the initial dialog box. This article focuses on message boxes, which are modal.

The following figure shows a typical message box.

Ee832759.ca0c1181-1e80-4b3e-bf35-f83bfe1011d9(en-us,MSDN.10).gif

The MessageBox function returns an integer value that indicates which button the user clicked. Windows system components and third-party applications widely use the MessageBox function. Although message boxes are convenient for providing information to users and receiving user input, they might be unwanted in some devices, such as headless systems or set-top boxes, where the device has no interface for users to respond to message boxes, or in devices where message boxes interrupt the user experience.

By using the Message Box Default Reply component, Windows Embedded Standard 2009 developers can configure a device that intercepts all calls to the MessageBox function and that automatically chooses the default button. In this manner, end-users do not see message boxes. However, developers can also choose to track message boxes by logging events.

Feature Design Explained

When you add the Message Box Default Reply component to your image and enable it, the system automatically intercepts MessageBox function calls and provides the default reply. The developer who calls the MessageBox function sets the default button, which can be the first button on the message box, or a different button. For more information, see MessageBox Function.

The Message Box Default Reply component works by creating registry keys and values on the device that control whether the MessageBox function returns the default reply and whether the function logs replies in the Windows Event Viewer. The MessageBox function implements the automatic-reply and logging functionality by checking values in the registry. When you enable the Message Box Default Reply component, it sets the EnableDefaultReply value under the HKLM\System\CurrentControlSet\Control\Error Message Instrument registry key to 0x00000001. When the MessageBox function runs and the EnableDefaultReply value is set to 0x00000001, it returns the default button as the reply without awaiting response from the user; otherwise, it waits for the user’s response before it returns control to the parent application.

Automatic responses to message boxes can be logged in the Windows Event Viewer. The MessageBox function implements logging by checking whether the EnableLogging value under the KLM\System\CurrentControlSet\Control\Error Message Instrument registry key is set to 0x00000001. If the EnableLogging value is set to 0x00000001, the MessageBox function then checks the TypesSupported and EventMessage values under the HKLM\System\CurrentControlSet\Services\EventLog\Application\Error Instrument key that the Message Box Default Reply Component created. The TypesSupported and EventMessage keys register the event source on the device. As soon as these values are set, message box activity is logged if it falls into the preset log-severity level. The next section provides more details about the log-severity levels.

Message Box Default Reply Component Configuration Options

The following figure shows the settings for the Message Box Default Reply component in Target Designer.

Ee832759.58539341-7f10-4352-8ba6-197ce871d4e3(en-us,MSDN.10).gif

By default, the Message Box Default Reply component is enabled (the Disable MessageBox Popup check box is selected), and the system automatically replies to messages. You can disable default replies by clearing the Disable MessageBox Popup check box.

You can enable event logging by selecting the Log message information in event log check box and setting the severity of error messages that you want to log from the Severity log level list.

The following table shows a list of supported log-severity levels:

Severity log level Description

Log all events

All message box events are logged.

Log events with the dwStyle parameter defined

Message box events, with the dwStyle parameter defined, are logged, including MB_USERICON, MB_ICONASTERISK, MB_ICONQUESTION, MB_ICONEXCLAMATION, and MB_ICONHAND.

Log only errors, warnings, questions, and information

Errors, warnings, questions, and information are logged. Message box events with no dwStyle parameter or dwStyle = MB_ICONUSER are not logged

Log only errors and warnings

Only errors and warnings are logged.

Log only errors

Only errors are logged.

Important

Not all message boxes are produced through the standard MessageBox function. You can choose to develop your own custom message dialog box. Therefore, the default reply feature might not operate on all message dialog boxes.

Conclusion

What you have learned

In this technical article you learned what the Message Box Default Reply component does, and how to use it to automatically reply to message boxes.