FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
MBPython/MBPython/wndproc.py at master · lochen88/MBPython · GitHub
lochen88
/
MBPython
Public
Notifications
You must be signed in to change notification settings
Fork
12
Star
62
Code
Issues
3
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
MBPython
/
MBPython
/
wndproc.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
70 lines (67 loc) · 2.66 KB
Breadcrumbs
MBPython
/
MBPython
/
wndproc.py
Copy path
File metadata and controls
70 lines (67 loc) · 2.66 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# -*- coding:utf-8 -*-
from
.
winConst
import
WinConst
from
.
wkeStruct
import
COPYDATASTRUCT
from
ctypes
import
(
cast
,
c_char_p
,
py_object
,
sizeof
,
byref
,
string_at
,
create_string_buffer
,
POINTER
)
import
win32gui
import
win32api
import
json
PCOPYDATASTRUCT
=
POINTER
(
COPYDATASTRUCT
)
class
WndProcHook
:
def
__init__
(
self
,
hwnd
,
webview
=
None
):
self
.
webview
=
webview
self
.
hwnd
=
hwnd
self
.
msg_func_dict
=
{}
def
hook_WndProc
(
self
):
self
.
oldWndProc
=
win32gui
.
SetWindowLong
(
self
.
hwnd
,
WinConst
.
GWL_WNDPROC
,
self
.
_onWndProcCallback
)
def
unhook_WndProc
(
self
):
win32api
.
SetWindowLong
(
self
.
hwnd
,
WinConst
.
GWL_WNDPROC
,
self
.
oldWndProc
)
def
add_msg_func
(
self
,
webview
,
hwnd
,
msg
,
msg_func
):
self
.
msg_func_dict
[
msg
]
=
msg_func
def
_onWndProcCallback
(
self
,
hwnd
,
msg
,
wParam
,
lParam
):
if
msg
in
self
.
msg_func_dict
:
argcount
=
self
.
msg_func_dict
[
msg
].
__code__
.
co_argcount
ret
=
None
if
argcount
==
5
:
arg_vals
=
self
.
msg_func_dict
[
msg
].
__code__
.
co_varnames
if
arg_vals
[
0
]
==
'self'
:
ret
=
self
.
msg_func_dict
[
msg
](
self
.
webview
,
hwnd
,
wParam
,
lParam
)
elif
argcount
==
4
:
ret
=
self
.
msg_func_dict
[
msg
](
self
.
webview
,
hwnd
,
wParam
,
lParam
)
elif
argcount
==
3
:
ret
=
self
.
msg_func_dict
[
msg
](
hwnd
,
wParam
,
lParam
)
elif
argcount
==
2
:
ret
=
self
.
msg_func_dict
[
msg
](
wParam
,
lParam
)
if
ret
!=
None
:
return
ret
if
hasattr
(
self
,
'onWndProcCallback'
):
ret
=
self
.
onWndProcCallback
(
hwnd
=
hwnd
,
msg
=
msg
,
wParam
=
wParam
,
lParam
=
lParam
)
if
ret
!=
None
:
return
ret
if
msg
==
WinConst
.
WM_DESTROY
:
self
.
unhook_WndProc
()
return
win32gui
.
CallWindowProc
(
self
.
oldWndProc
,
hwnd
,
msg
,
wParam
,
lParam
)
@
staticmethod
def
value_to_msg
(
value
,
copydate
=
False
):
if
copydate
:
cds
=
COPYDATASTRUCT
()
cds
.
dwData
=
0
value
=
json
.
dumps
(
value
).
encode
()
cds
.
cbData
=
sizeof
(
create_string_buffer
(
value
))
cds
.
lpData
=
c_char_p
(
value
)
return
byref
(
cds
)
else
:
value
=
json
.
dumps
(
value
).
encode
()
return
c_char_p
(
value
)
@
staticmethod
def
msg_to_value
(
wParam
,
lParam
,
copydate
=
False
):
if
lParam
!=
0
:
try
:
if
copydate
:
pCDS
=
cast
(
lParam
,
PCOPYDATASTRUCT
)
value
=
string_at
(
pCDS
.
contents
.
lpData
).
decode
()
else
:
value
=
cast
(
lParam
,
c_char_p
).
value
.
decode
()
except
:
return
value
=
json
.
loads
(
value
)
return
value
Back
|
FazBrowse Home
|
New Git URL