Why can't run DestroyWindow function in Python

1.4k views Asked by At

I write a program that can open a particular file, i.e., a Flash file, positioning it at particular position and closing it(not minimizing but exitting).

The first second target is ok by os.startfile('file.swf'), finding its hwnd by win32gui.FindWindow(None, file.swf) and positioning it by win32gui.MoveWindow(hwnd,0,0,800,600,True), however, the win32gui.DestroyWindow(hwnd) can't work and I don't know why.

Here is the error message below:

Traceback (most recent call last):
 File "<pyshell#30>", line 1, in <module>
  win32gui.DestroyWindow(hwnd1)
error: (5, 'DestroyWindow', '\xa6s\xa8\xfa\xb3Q\xa9\xda\xa1C')

What is wrong with it? How to fix it?

edit:

my code is:

import win32gui
import os

"""

monitoring a folder which will be updated per one miniute
if the temperature changed the program will open a particular file to display 

"""

FLASH_PATH="santa"
PIC_PATH=""
TEMP_PATH="Temperatures/"

file_name="led_20.swf"
filePath=os.path.join(FLASH_PATH,file_name)
os.startfile(filePath)
hwnd=win32gui.FindWindow(None,file_name)
win32gui.MoveWindow(hwnd,0,0,800,600,True)


"""
display it for a few minute and close it
"""
1

There are 1 answers

0
Ignacio Vazquez-Abrams On BEST ANSWER

Error 5 is ERROR_ACCESS_DENIED. DestroyWindow() can only be called by the thread that created the window. Post or send a WM_DESTROY message instead.