MessageBox只显示一个字符
问题描述:
为什么这只会为标题和框内打印一个字符。我如何确保它能打印所有内容?MessageBox只显示一个字符
import ctypes
ctypes.windll.user32.MessageBoxA(0, "info", "title", 3)
只有'我'被打印,只有't'被打印标题,这是什么问题?
答
如果测试
ctypes.windll.user32.MessageBoxW(0, "info", "title", 3)
应该有 “信息” 和 “称号”。此外,如果你测试
ctypes.windll.user32.MessageBoxA(0, "info".encode('ascii'),
"title".encode('ascii'), 3)
所以它似乎是某种文字编码问题。 UTF-16编码的字符串可能默认传递。
>>> '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\0'
和't\0'
,得到考虑。
'ctypes.windll.user32.MessageBoxA(0,b'info',b'title',3)'也很好 –