Strictly speaking this snippet isn’t even code however it did come up in a code review and I’ve made use of it often. Lots of times when an error message appears I need to be able to get the text from an error message dialog, either I want to find the text in source code or to use it to search the internet.

It turns out that as long as the developer has used the standard Message Box, either using Windows unmanaged API or the .NET managed MessageBox wrappers then you can use CTRL C while the message box has focus and the text from the dialog will be placed on the clipboard.

Taking a completely random example of starting up Google Earth without an internet connection available the following message is displayed

image

In the past I have retyped phrases from the message and looked for them but this is obviously quite error prone. However by using CTRL C the following text is placed on the clipboard.

---------------------------
Warning
---------------------------
<html>Google Earth could not contact the authentication server to activate
your session.The application will continue to operate but will only display
data available locally (in cache).<p>For information about how to resolve
the problem, would you like to run a diagnostic test? This test attempts
to detect settings on your computer that might prevent Google Earth from
functioning properly.</html>
---------------------------
&Yes   &No   
---------------------------

Enjoy.