X Tutup
Skip to content

Commit f6e7de2

Browse files
committed
Update window_size.py snippet. Works on Windows now.
1 parent 3364c8f commit f6e7de2

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

examples/README-examples.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ See small code snippets that show various CEF features in the
6363
on a web page as soon as DOM is ready.
6464
- [onpagecomplete.py](snippets/onpagecomplete.py) - Execute custom
6565
Python code on a web page when page loading is complete.
66+
- [window_size.py](snippets/window_size.py) - Set initial window size
67+
without using any third party GUI framework.
6668

6769

6870
### GUI frameworks

examples/snippets/window_size.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
"""
2-
Set initial size of window to 900px / 640px without using
2+
Set initial window size to 900/600 pixels without using
33
any third party GUI framework. On Linux/Mac you can set
44
window size by calling WindowInfo.SetAsChild. On Windows
55
you can accomplish this by calling Windows native functions
66
using the ctypes module.
77
"""
88

99
from cefpython3 import cefpython as cef
10+
import ctypes
1011
import platform
1112

1213

1314
def main():
1415
cef.Initialize()
1516
window_info = cef.WindowInfo()
16-
window_info.SetAsChild(0, [0, 0, 900, 640])
17+
parent_handle = 0
18+
# All rect coordinates are applied including X and Y parameters
19+
window_info.SetAsChild(parent_handle, [0, 0, 900, 640])
1720
browser = cef.CreateBrowserSync(url="https://www.google.com/",
1821
window_info=window_info,
1922
window_title="Window size")
2023
if platform.system() == "Windows":
21-
pass
24+
window_handle = browser.GetOuterWindowHandle()
25+
# X and Y parameters are ignored by setting the SWP_NOMOVE flag
26+
SWP_NOMOVE = 0x0002
27+
insert_after_handle = 0
28+
# noinspection PyUnresolvedReferences
29+
ctypes.windll.user32.SetWindowPos(window_handle, insert_after_handle,
30+
0, 0, 900, 640, SWP_NOMOVE)
2231
cef.MessageLoop()
2332
del browser
2433
cef.Shutdown()

0 commit comments

Comments
 (0)
X Tutup