windows: Use FindWindow to locate the window related to the timer 78/250178/3
authorWander Lairson Costa <wander.lairson@gmail.com>
Mon, 21 Dec 2020 17:39:42 +0000 (14:39 -0300)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Tue, 5 Jan 2021 18:27:08 +0000 (18:27 +0000)
If our window is not the foreground window, GetActiveWindow() will
return a null handle, which causes the call to SetTimer to ignore the
given timer ID.

We solve this by calling FindWindow() passing the window class name when
GetActiveWindow returns null.

Change-Id: Icc3e3c9f3fd0f9cfb4f4e8cb97fabffe347c7b5d

dali/internal/window-system/windows/platform-implement-win.cpp

index c56d31ed6068b84d25ad7944f6a9f3832188c775..4a2a60b16f6a1fbde53b8dfd82b02e2e0648ceae 100755 (executable)
@@ -261,13 +261,24 @@ void CALLBACK TimerProc(HWND hWnd, UINT nMsg, UINT_PTR nTimerid, DWORD dwTime)
 
 intptr_t SetTimer(int interval, timerCallback callback, void *data)
 {
+  HWND hwnd = GetActiveWindow();
+  if (!hwnd)
+  {
+    hwnd = FindWindow(DALI_WINDOW_CLASS_NAME.c_str(), nullptr);
+  }
+
+  if (!hwnd)
+  {
+    return -1;
+  }
+
   TTimerCallbackInfo *callbackInfo = new TTimerCallbackInfo;
   callbackInfo->data = data;
   callbackInfo->callback = callback;
-  callbackInfo->hWnd = ::GetActiveWindow();
+  callbackInfo->hWnd = hwnd;
 
   INT_PTR timerID = (INT_PTR)callbackInfo;
-  ::SetTimer( callbackInfo->hWnd, timerID, interval, TimerProc );
+  ::SetTimer( hwnd, timerID, interval, TimerProc );
 
   return timerID;
 }