[KBSWITCH] Improve mouse events handling. By Joachim Henze. CORE-9883
[reactos.git] / reactos / base / applications / kbswitch / kbswitch.c
index 5d0849d..09534f6 100644 (file)
@@ -390,6 +390,7 @@ WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
 {
     static HMENU hRightPopupMenu;
     static TCHAR szLCID[MAX_PATH], szLangName[MAX_PATH];
+    static UINT s_uTaskbarRestart;
 
     switch (Message)
     {
@@ -400,6 +401,7 @@ WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
             hRightPopupMenu = GetSubMenu(LoadMenu(hInst, MAKEINTRESOURCE(IDR_POPUP)), 0);
 
             ActivateLayout(hwnd, ulCurrentLayoutNum);
+            s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
 
             return 0;
         }
@@ -432,18 +434,17 @@ WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
         case WM_NOTIFYICONMSG:
             switch (lParam)
             {
-                case WM_RBUTTONDOWN:
-                case WM_LBUTTONDOWN:
+                case WM_RBUTTONUP:
+                case WM_LBUTTONUP:
                 {
                     POINT pt;
 
                     GetCursorPos(&pt);
                     SetForegroundWindow(hwnd);
 
-                    if (lParam == WM_LBUTTONDOWN)
+                    if (lParam == WM_LBUTTONUP)
                     {
                         HMENU hLeftPopupMenu;
-
                         /* Rebuild the left popup menu on every click to take care of keyboard layout changes */
                         hLeftPopupMenu = BuildLeftPopupMenu();
                         TrackPopupMenu(hLeftPopupMenu, 0, pt.x, pt.y, 0, hwnd, NULL);
@@ -506,6 +507,11 @@ WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
 
             return 0;
         }
+
+        default:
+            if(Message == s_uTaskbarRestart)
+                AddTrayIcon(hwnd);
+            break;
     }
 
     return DefWindowProc(hwnd, Message, wParam, lParam);
@@ -541,7 +547,7 @@ _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPTSTR lpCmdLine, INT nCmdSh
     hProcessHeap = GetProcessHeap();
 
     WndClass.style = 0;
-    WndClass.lpfnWndProc   = (WNDPROC)WndProc;
+    WndClass.lpfnWndProc   = WndProc;
     WndClass.cbClsExtra    = 0;
     WndClass.cbWndExtra    = 0;
     WndClass.hInstance     = hInstance;