-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwindows_app.py
55 lines (47 loc) · 1.27 KB
/
windows_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from win32gui import *
from win32con import *
from ctypes import *
def WinMain():
# Define Window Class
wndclass = WNDCLASS()
wndclass.style = CS_HREDRAW | CS_VREDRAW
wndclass.lpfnWndProc = WndProc
wndclass.hInstance = GetModuleHandle(None)
wndclass.hIcon = LoadIcon(None, IDI_APPLICATION)
wndclass.hCursor = LoadCursor(None, IDC_ARROW)
wndclass.hbrBackground = GetStockObject(WHITE_BRUSH)
wndclass.lpszMenuName = ""
wndclass.lpszClassName = "MainWin"
# Register Window Class
if not RegisterClass(wndclass):
raise WinError()
hwnd = CreateWindowEx(0,
wndclass.lpszClassName,
"Python Window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
None,
None,
wndclass.hInstance,
None)
# Show Window
ShowWindow(hwnd, SW_SHOWNORMAL)
UpdateWindow(hwnd)
return PumpMessages()
def WndProc(hwnd, message, wParam, lParam):
if message == WM_PAINT:
hdc , ps = BeginPaint(hwnd)
rect = GetClientRect(hwnd)
DrawText(hdc, "Python Powered Windows" ,
-1, rect,
DT_SINGLELINE|DT_CENTER|DT_VCENTER)
EndPaint(hwnd, ps)
return 0
elif message == WM_DESTROY:
PostQuitMessage(0)
return 0
return DefWindowProc(hwnd, message, wParam, lParam)
WinMain()