Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activate does not work #36

Open
ghost opened this issue Dec 31, 2020 · 8 comments
Open

Activate does not work #36

ghost opened this issue Dec 31, 2020 · 8 comments

Comments

@ghost
Copy link

ghost commented Dec 31, 2020

No description provided.

@widb0005
Copy link

widb0005 commented Jan 4, 2021

Same after using it regularly for months; here's the error where DeltekWindow is from DeltekWindow = gw.getWindowsWithTitle('Deltek')[0]

Traceback (most recent call last):
File "C:\Users\aaw\AppData\Local\Programs\Python\Python38-32\pyTimesheet.py", line 51, in
DeltekWindow.activate()
File "C:\Users\aaw\AppData\Roaming\Python\Python38\site-packages\pygetwindow_pygetwindow_win.py", line 237, in activate
_raiseWithLastError()
File "C:\Users\aaw\AppData\Roaming\Python\Python38\site-packages\pygetwindow_pygetwindow_win.py", line 97, in _raiseWithLastError
raise PyGetWindowException('Error code from Windows: %s - %s' % (errorCode, _formatMessage(errorCode)))
pygetwindow.PyGetWindowException: Error code from Windows: 0 - The operation completed successfully.

@William-Bourget
Copy link

Hi,
I have the same exact error.

@saintyoung
Copy link

Hi I have the same error. The first time call win.activate() is working. But get the error when call the second time with other window. Could you take a look please? Thanks!

@noacharon
Copy link

Same here.
The problem is caused by ctypes.windll.user32.SetForegroundWindow returning False / 0 for any hWnd but the one of the active python programm.

@s-weigand
Copy link

Hi, I got the same issue.
As a workaround I use

window.minimize()
window.restore()

@medifle
Copy link

medifle commented Oct 1, 2023

I learned there are limitations when working with this method. When I tried the .activate() method in a terminal (REPL mode), it threw pygetwindow.PyGetWindowException: Error code from Windows: 6 - The handle is invalid. and the target program had a red flash in the taskbar.

Reading the SetForegroundWindow doc:

An application cannot force a window to the foreground while the user is working with another window. Instead, Windows flashes the taskbar button of the window to notify the user.

So I tried invoking .activate() in an automated python script, it worked as expected.

@eito-88
Copy link

eito-88 commented Mar 5, 2024

It seems there is a short-term solution available.
Reference: https://stackoverflow.com/questions/14295337/win32gui-setactivewindow-error-the-specified-procedure-could-not-be-found/15503675#15503675

The above web page is an example of win32gui, but it appears to be applicable to this library as well.
Specifically, the issue can be resolved by inputting the Alt key right before calling activate().

code example:

import pyautogui

# some process...

if not window.isActive:
    pyautogui.press('altleft')
    window.activate()

@ShiqiRao
Copy link

It seems there is a short-term solution available. Reference: https://stackoverflow.com/questions/14295337/win32gui-setactivewindow-error-the-specified-procedure-could-not-be-found/15503675#15503675

The above web page is an example of win32gui, but it appears to be applicable to this library as well. Specifically, the issue can be resolved by inputting the Alt key right before calling activate().

code example:

import pyautogui

# some process...

if not window.isActive:
    pyautogui.press('altleft')
    window.activate()

Wow, it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants