+/* Message functions. */
+
+#ifdef WINDOWSNT
+/* I first tried to check for STDOUT. The check did not work,
+ I get a valid handle also in nonconsole apps.
+ Instead I test for console title, which seems to work. */
+int
+w32_window_app()
+{
+ static int window_app = -1;
+ char szTitle[MAX_PATH];
+
+ if (window_app < 0)
+ window_app = (GetConsoleTitleA (szTitle, MAX_PATH) == 0);
+
+ return window_app;
+}
+#endif
+
+void
+message (int is_error, char *message, ...)
+{
+ char buf [2048];
+ char *msg = buf;
+ va_list args;
+
+ va_start (args, message);
+
+ if (is_error)
+ {
+ sprintf (buf, "%s: ", progname);
+ msg = strchr (buf, '\0');
+ }
+
+ vsprintf (msg, message, args);
+ va_end (args);
+
+#ifdef WINDOWSNT
+ if (w32_window_app ())
+ {
+ if (is_error)
+ MessageBox (NULL, msg, "Emacsclient ERROR", MB_ICONERROR);
+ else
+ MessageBox (NULL, msg, "Emacsclient", MB_ICONINFORMATION);
+ }
+ else
+#endif
+ fprintf (is_error ? stderr : stdout, msg);
+}
+