@@ -258,11 +258,20 @@ Napi::Boolean showWindow (const Napi::CallbackInfo& info) {
258258
259259Napi::Boolean bringWindowToTop (const Napi::CallbackInfo& info) {
260260 Napi::Env env{ info.Env () };
261-
262261 auto handle{ getValueFromCallbackData<HWND> (info, 0 ) };
263262 BOOL b{ SetForegroundWindow (handle) };
264- SetActiveWindow (handle);
265- SetWindowPos (handle, HWND_TOP, 0 , 0 , 0 , 0 , SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
263+
264+ HWND hCurWnd = ::GetForegroundWindow ();
265+ DWORD dwMyID = ::GetCurrentThreadId ();
266+ DWORD dwCurID = ::GetWindowThreadProcessId (hCurWnd, NULL );
267+ ::AttachThreadInput (dwCurID, dwMyID, TRUE );
268+ ::SetWindowPos (handle, HWND_TOPMOST, 0 , 0 , 0 , 0 , SWP_NOSIZE | SWP_NOMOVE);
269+ ::SetWindowPos (handle, HWND_NOTOPMOST, 0 , 0 , 0 , 0 , SWP_NOSIZE | SWP_NOMOVE);
270+ ::SetForegroundWindow (handle);
271+ ::AttachThreadInput (dwCurID, dwMyID, FALSE );
272+ ::SetFocus (handle);
273+ b = ::SetActiveWindow (handle);
274+
266275
267276 return Napi::Boolean::New (env, b);
268277}
0 commit comments