forked from sciter-sdk/pysciter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplain-win.py
151 lines (115 loc) · 3.87 KB
/
plain-win.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
"""Sciter sample for Win32 API."""
# sciter import
import sciter
from sciter import sapi
from sciter.capi.scdef import *
# ctypes import
from ctypes import *
from ctypes.wintypes import *
# defs
WS_EX_APPWINDOW = 0x40000
WS_OVERLAPPEDWINDOW = 0xcf0000
WS_CAPTION = 0xc00000
SW_SHOWNORMAL = 1
SW_SHOW = 5
CS_HREDRAW = 2
CS_VREDRAW = 1
CW_USEDEFAULT = 0x80000000
WM_DESTROY = 2
WHITE_BRUSH = 0
IDC_ARROW = 31514
WNDPROCTYPE = WINFUNCTYPE(LRESULT, HWND, c_uint, WPARAM, LPARAM)
class WNDCLASSEX(Structure):
_fields_ = [
("cbSize", c_uint),
("style", c_uint),
("lpfnWndProc", WNDPROCTYPE),
("cbClsExtra", c_int),
("cbWndExtra", c_int),
("hInstance", HANDLE),
("hIcon", HANDLE),
("hCursor", HANDLE),
("hBrush", HANDLE),
("lpszMenuName", LPCWSTR),
("lpszClassName", LPCWSTR),
("hIconSm", HANDLE)]
def on_load_data(ld):
"""Custom documents loader, just for example."""
uri = ld.uri
uri = uri
return 0
def on_create_behavior(ld):
"""Custom behavior factory, just for example."""
name = ld.behaviorName
name = name
return 0
def on_sciter_callback(pld, param):
"""Sciter notifications callback."""
ld = pld.contents
if ld.code == SciterNotification.SC_LOAD_DATA:
return on_load_data(cast(pld, POINTER(SCN_LOAD_DATA)).contents)
elif ld.code == SciterNotification.SC_ATTACH_BEHAVIOR:
return on_create_behavior(cast(pld, POINTER(SCN_ATTACH_BEHAVIOR)).contents)
return 0
def on_wnd_message(hWnd, Msg, wParam, lParam):
"""WindowProc Function."""
handled = BOOL(0)
lr = sapi.SciterProcND(hWnd, Msg, wParam, lParam, byref(handled))
if handled:
return lr
if Msg == WM_DESTROY:
windll.user32.PostQuitMessage(0)
return 0
try:
return windll.user32.DefWindowProcW(hWnd, Msg, wParam, lParam)
except:
import traceback
etype, evalue, estack = sys.exc_info()
print("WndProc exception: %X, 0x%04X, 0x%X, 0x%X" % (hWnd, Msg, wParam, lParam))
traceback.print_exception(etype, evalue, estack)
return 0
def main():
clsname = sapi.SciterClassName()
sciter.runtime_features(allow_sysinfo=True)
title = u"Win32 Sciter"
clsname = u"PySciter"
windll.user32.DefWindowProcW.argtypes = [HWND, c_uint, WPARAM, LPARAM]
windll.user32.DefWindowProcW.restype = LRESULT
WndProc = WNDPROCTYPE(on_wnd_message)
wndClass = WNDCLASSEX()
wndClass.cbSize = sizeof(WNDCLASSEX)
wndClass.style = CS_HREDRAW | CS_VREDRAW
wndClass.lpfnWndProc = WndProc
wndClass.cbClsExtra = 0
wndClass.cbWndExtra = 0
wndClass.hInstance = windll.kernel32.GetModuleHandleW(0)
wndClass.hIcon = 0
wndClass.hCursor = windll.user32.LoadCursorW(0, IDC_ARROW)
wndClass.hBrush = windll.gdi32.GetStockObject(WHITE_BRUSH)
wndClass.lpszMenuName = 0
wndClass.lpszClassName = clsname
wndClass.hIconSm = 0
if not windll.user32.RegisterClassExW(byref(wndClass)):
err = windll.kernel32.GetLastError()
print('Failed to register window: ', err)
exit(0)
hWnd = windll.user32.CreateWindowExW(0, clsname, title, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, 0, 0, 0, 0)
if not hWnd:
err = windll.kernel32.GetLastError()
print('Failed to create window: ', err)
exit(0)
scproc = SciterHostCallback(on_sciter_callback)
sapi.SciterSetCallback(hWnd, scproc, None)
url = u"examples/minimal.htm"
sapi.SciterLoadFile(hWnd, url)
windll.user32.ShowWindow(hWnd, SW_SHOW)
windll.user32.UpdateWindow(hWnd)
msg = MSG()
lpmsg = pointer(msg)
print('Entering message loop')
while windll.user32.GetMessageW(lpmsg, 0, 0, 0) != 0:
windll.user32.TranslateMessage(lpmsg)
windll.user32.DispatchMessageW(lpmsg)
print('Quit.')
if __name__ == '__main__':
main()