MessageBox 只显示一个字符

MessageBox only displaying one character

为什么标题和框内只打印一个字符。我如何确保它全部打印出来?

import ctypes 
ctypes.windll.user32.MessageBoxA(0, "info", "title", 3)

只有 'i' 被打印出来,标题只有 't' 被打印出来,这是什么问题?

如果你测试

ctypes.windll.user32.MessageBoxW(0, "info", "title", 3)

应该有"info"和"title"。另外如果你测试

ctypes.windll.user32.MessageBoxA(0, "info".encode('ascii'), 
                                 "title".encode('ascii'), 3)

所以这似乎是某种文本编码问题。 UTF-16-le 编码的字符串可能默认通过。

>>> 'info'.encode('utf-16-le')
b'i\x00n\x00f\x00o\x00'
>>> 'title'.encode('utf-16-le')
b't\x00i\x00t\x00l\x00e\x00'

由于 MessageBoxA 需要 NULL 终止的 C 字符串,因此只考虑了开头的两个字符,即 'i[=15=]''t[=16=]'