该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
代码:
import win32gui
import win32con
import win32api
import win32ui
def wndProc(hWnd, message, wParam, lParam):
if message == win32con.WM_PAINT:
print("WM_PAINT")
hdc, paintStruct = win32gui.BeginPaint(hWnd)
dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0
fontSize = 80
lf = win32gui.LOGFONT()
lf.lfFaceName = "Times New Roman"
lf.lfHeight = int(round(dpiScale * fontSize))
hf = win32gui.CreateFontIndirect(lf)
win32gui.SelectObject(hdc, hf)
rect = win32gui.GetClientRect(hWnd)
win32gui.DrawText(
hdc, '测试', -1, rect,
win32con.DT_CENTER | win32con.DT_NOCLIP | win32con.DT_SINGLELINE | win32con.DT_VCENTER
)
win32gui.EndPaint(hWnd, paintStruct)
return 0
elif message == win32con.WM_CREATE:
print("WM_CREATE")
return 0
else:
return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
def createPropertyWin(hWndParent = None):
hInstance = win32api.GetModuleHandle()
className = 'MyCreatePropertyWin'
wndClass = win32gui.WNDCLASS()
wndClass.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW | win32con.CS_DBLCLKS
wndClass.lpfnWndProc = wndProc
wndClass.hInstance = hInstance
wndClass.hCursor = win32gui.LoadCursor(None, win32con.IDC_ARROW)
wndClass.hbrBackground = win32gui.GetStockObject(win32con.WHITE_BRUSH)
wndClass.lpszClassName = className
wndClassAtom = win32gui.RegisterClass(wndClass)
exStyle = win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED | win32con.WS_EX_CLIENTEDGE
style = win32con.WS_OVERLAPPEDWINDOW | win32con.CW_USEDEFAULT
hWindow = win32gui.CreateWindowEx(
exStyle,
wndClassAtom,
"属性",
style,
0, 0,
300, 500, hWndParent,
None, hInstance, None
)
win32gui.ShowWindow(hWindow, win32con.SW_SHOWNORMAL)
win32gui.UpdateWindow(hWindow)
win32gui.PumpMessages()
createPropertyWin()
为什么没win32con.WM_CREATE消息呢!