【问题标题】:pywintypes.error: (1407, 'CreateWindowEx'..)pywintypes.error: (1407, 'CreateWindowEx'..)
【发布时间】:2021-01-04 17:07:28
【问题描述】:

我尝试开始使用 python 编写 MS 应用程序并从一开始就失败了。

我的具体问题是关于这个错误:

pywintypes.error: (1407, 'CreateWindowEx', 'Windowclass was not found.')

使用此代码:

import ctypes
import win32api
import win32con as con
import win32gui as gui


class Window(object):
    def __init__(self):
        self.hwnd = gui.CreateWindowEx(0,
                                       "Root",
                                       "Python Window",
                                       con.WS_OVERLAPPEDWINDOW,
                                       con.CW_USEDEFAULT,
                                       con.CW_USEDEFAULT,
                                       con.CW_USEDEFAULT,
                                       con.CW_USEDEFAULT,
                                       0,
                                       0,
                                       0,
                                       None)
        gui.ShowWindow(self.hwnd, con.SW_SHOWDEFAULT)

Window()

昨天我读了一些关于注册窗口的东西,但我找不到了。我认为有问题。有人可以帮帮我吗?

另外,如果有人读到这个问题并能给我一些一般性的提示,我会很高兴。 为了描述我目前的情况,我尝试关注 MS 的 documentation,并尝试通过 this example 了解使用 python 翻译 C 代码的想法。但我无法关注,因为我发现的 best documentation of ctypes 不会像示例中那样帮助我使用 ctypes only

【问题讨论】:

标签: python python-3.x winapi ctypes pywin32


【解决方案1】:

错误表示窗口类名字符串未注册。 "Root" 必须是已注册窗口类的名称。请参阅CreateWindowsEx 文档:

lpClassName

类型:LPCTSTR

由先前调用RegisterClassRegisterClassEx 函数创建的以null 结尾的字符串或类原子。原子必须在 lpClassName 的低位词中;高位字必须为零。如果 lpClassName 是一个字符串,它指定窗口类名。类名可以是通过RegisterClassRegisterClassEx 注册的任何名称,前提是注册类的模块也是创建窗口的模块。类名也可以是任何预定义的system class 名称。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-17
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    • 1970-01-01
    • 1970-01-01
    • 2011-05-21
    • 2011-01-17
    相关资源
    最近更新 更多