Debugging improvements. Started using Dave Hinton's dmemdump
[sgt/putty] / window.c
index ec27dc8..62e4be7 100644 (file)
--- a/window.c
+++ b/window.c
@@ -1,6 +1,7 @@
 #include <windows.h>
 #include <imm.h>
 #include <commctrl.h>
+#include <mmsystem.h>
 #ifndef AUTO_WINSOCK
 #ifdef WINSOCK_TWO
 #include <winsock2.h>
@@ -444,7 +445,9 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) {
 
        error = back->init (cfg.host, cfg.port, &realhost);
        if (error) {
-           sprintf(msg, "Unable to open connection:\n%s", error);
+           sprintf(msg, "Unable to open connection to\n"
+                   "%.800s\n"
+                   "%s", cfg.host, error);
            MessageBox(NULL, msg, "PuTTY Error", MB_ICONERROR | MB_OK);
            return 0;
        }
@@ -1662,7 +1665,8 @@ static LRESULT CALLBACK WndProc (HWND hwnd, UINT message,
  * have one.)
  */
 void sys_cursor(int x, int y) {
-    SetCaretPos(x * font_width, y * font_height);
+    if (has_focus)
+       SetCaretPos(x * font_width, y * font_height);
 }
 
 /*
@@ -2661,7 +2665,21 @@ void fatalbox(char *fmt, ...) {
  */
 void beep(int mode) {
     if (mode == BELL_DEFAULT) {
+       /*
+        * For MessageBeep style bells, we want to be careful of
+        * timing, because they don't have the nice property of
+        * PlaySound bells that each one cancels the previous
+        * active one. So we limit the rate to one per 50ms or so.
+        */
+       static long lastbeep = 0;
+       long now, beepdiff;
+
+       now = GetTickCount();
+       beepdiff = now - lastbeep;
+       if (beepdiff >= 0 && beepdiff < 50)
+           return;
        MessageBeep(MB_OK);
+       lastbeep = now;
     } else if (mode == BELL_WAVEFILE) {
        if (!PlaySound(cfg.bell_wavefile, NULL, SND_ASYNC | SND_FILENAME)) {
            char buf[sizeof(cfg.bell_wavefile)+80];