Thread overview
Any WinAPI experts here?
Sep 05, 2011
Andrej Mitrovic
Sep 05, 2011
Vladimir Panteleev
Sep 05, 2011
Andrej Mitrovic
September 05, 2011
This is breaking my neck right now. I have two separate windows, window #2 hides and then shows window #1 whenever it detects the mouse has moved in window #2. So, if the mouse stops moving, it should stop doing that.

But instead what I get is an infinite loop. Somehow, the hiding and showing of window #1 ends up triggering the WM_MOUSEMOVE message for window #2. Here's the code:

http://codepad.org/U956e2u6

The idea of using mosemove to hide/show a window is from an attempt to simulate menus in some other code, but anyway I can't figure out why MOSEMOVE is retriggered for window #2 all the time even if the mouse is stationary. If you comment out either of the ShowWindow() calls, there will be no infinite loop.

I'm hoping someone here has better knowledge than me about WinAPI before I reach for MSDN forums.
September 05, 2011
On Mon, 05 Sep 2011 23:10:05 +0300, Andrej Mitrovic <andrej.mitrovich@gmail.com> wrote:

> This is breaking my neck right now. I have two separate windows,
> window #2 hides and then shows window #1 whenever it detects the mouse
> has moved in window #2. So, if the mouse stops moving, it should stop
> doing that.


diff --git a/raw.d b/raw.d
index 6ce0256..8ea7c7c 100644
--- a/raw.d
+++ b/raw.d
@@ -114,10 +114,15 @@ LRESULT WndProc2(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
     switch (message)
     {
         case WM_MOUSEMOVE:
-            static ulong count;
-            writeln(count++);
-            ShowWindow(hWindow1, SW_HIDE);
-            ShowWindow(hWindow1, SW_SHOW);
+            static LPARAM oldPosition;
+            if (lParam != oldPosition)
+            {
+                static ulong count;
+                writeln(count++);
+                ShowWindow(hWindow1, SW_HIDE);
+                ShowWindow(hWindow1, SW_SHOW);
+                oldPosition = lParam;
+            }
             return 0;

         case WM_DESTROY:


I wouldn't think too much about it, the Windows GUI does a lot of weird things for the sake of compatibility etc.

-- 
Best regards,
 Vladimir                            mailto:vladimir@thecybershadow.net
September 05, 2011
Thanks, Vladimir. :)

I'm trying to use a minimal subset of the API (ironically, to avoid winapi bugs) for experimenting with Cairo. It's nice having the boilerplate of features already implemented such as clipped drawing and moving windows relative to their parent instead of relative to the screen.