1
1
# -*- coding: utf-8 -*-
2
2
3
3
"""
4
- (C) 2014 Roman Sirokov
4
+ (C) 2014-2015 Roman Sirokov
5
5
Licensed under BSD license
6
6
7
7
http://github.com/r0x0r/pywebview/
8
8
"""
9
9
10
- import win32con , win32api , win32gui , win32ui
10
+ import win32con , win32api , win32gui
11
11
from win32com .shell import shell , shellcon
12
12
import os
13
13
import sys
27
27
28
28
GetModule ('shdocvw.dll' )
29
29
30
- _kernel32 = windll .kernel32
31
- _user32 = windll .user32
32
30
_atl = windll .atl
33
-
34
-
35
- #NULL = c_int(win32con.NULL)
36
31
_WNDPROC = WINFUNCTYPE (c_long , c_int , c_uint , c_int , c_int )
37
32
33
+ # for some reason we have to set an offset for the height of ATL window in order for the vertical scrollbar to be fully
34
+ # visible
35
+ VERTICAL_SCROLLBAR_OFFSET = 20
36
+
38
37
class WNDCLASS (Structure ):
39
38
_fields_ = [('style' , c_uint ),
40
39
('lpfnWndProc' , _WNDPROC ),
@@ -59,6 +58,9 @@ def __init__(self, title, url, width, height, resizable, fullscreen):
59
58
self .resizable = resizable
60
59
self .fullscreen = fullscreen
61
60
61
+ self .scrollbar_width = win32api .GetSystemMetrics (win32con .SM_CXVSCROLL )
62
+ self .scrollbar_height = win32api .GetSystemMetrics (win32con .SM_CYHSCROLL )
63
+
62
64
self .atlhwnd = - 1 # AtlAx host window hwnd
63
65
self .browser = None # IWebBrowser2 COM object
64
66
@@ -73,15 +75,15 @@ def _register_window(self):
73
75
message_map = {
74
76
win32con .WM_DESTROY : self ._on_destroy ,
75
77
win32con .WM_SIZE : self ._on_resize ,
76
- win32con .WM_ERASEBKGND : self ._on_erase_bkgnd
78
+ win32con .WM_ERASEBKGND : self ._on_erase_bkgnd ,
77
79
}
78
80
79
81
self .wndclass = win32gui .WNDCLASS ()
80
82
self .wndclass .style = win32con .CS_HREDRAW | win32con .CS_VREDRAW
81
83
self .wndclass .lpfnWndProc = message_map
82
84
self .wndclass .hInstance = win32api .GetModuleHandle ()
83
- self .wndclass .hCursor = _user32 . LoadCursorW ( c_int ( win32con .NULL ), c_int ( win32con .IDC_ARROW ) )
84
- self .wndclass .hbrBackground = windll . gdi32 . GetStockObject (c_int ( win32con .WHITE_BRUSH ) )
85
+ self .wndclass .hCursor = win32gui . LoadCursor ( win32con .NULL , win32con .IDC_ARROW )
86
+ self .wndclass .hbrBackground = win32gui . GetStockObject (win32con .WHITE_BRUSH )
85
87
self .wndclass .lpszMenuName = ""
86
88
self .wndclass .lpszClassName = "MainWin"
87
89
@@ -91,38 +93,47 @@ def _register_window(self):
91
93
92
94
def _create_main_window (self ):
93
95
# Set window style
94
- style = win32con .WS_VISIBLE
95
- if self .resizable :
96
- style = style | win32con .WS_OVERLAPPEDWINDOW
97
- else :
98
- style = style | (win32con .WS_OVERLAPPEDWINDOW ^ win32con .WS_THICKFRAME )
96
+ style = win32con .WS_VISIBLE | win32con .WS_OVERLAPPEDWINDOW
97
+ if not self .resizable :
98
+ style = style ^ win32con .WS_THICKFRAME
99
99
100
100
# Center window on the screen
101
- screen_x = _user32 .GetSystemMetrics (win32con .SM_CXSCREEN )
102
- screen_y = _user32 .GetSystemMetrics (win32con .SM_CYSCREEN )
101
+ screen_x = win32api .GetSystemMetrics (win32con .SM_CXSCREEN )
102
+ screen_y = win32api .GetSystemMetrics (win32con .SM_CYSCREEN )
103
103
x = int ((screen_x - self .width ) / 2 )
104
104
y = int ((screen_y - self .height ) / 2 )
105
105
106
+
106
107
# Create Window
107
108
self .hwnd = win32gui .CreateWindow (self .wndclass .lpszClassName ,
108
109
self .title , style , x , y , self .width , self .height ,
109
110
None , None , self .wndclass .hInstance , None )
110
111
111
112
# Set fullscreen
112
113
if self .fullscreen :
113
- style = _user32 .GetWindowLongW (self .hwnd , win32con .GWL_STYLE )
114
- _user32 .SetWindowLongW (self .hwnd , win32con .GWL_STYLE , style & ~ win32con .WS_OVERLAPPEDWINDOW )
115
- _user32 .SetWindowPos (self .hwnd , win32con .HWND_TOP , 0 , 0 , screen_x , screen_y ,
114
+ self .width = screen_x
115
+ self .height = screen_y
116
+
117
+ style = win32gui .GetWindowLong (self .hwnd , win32con .GWL_STYLE )
118
+ win32gui .SetWindowLong (self .hwnd , win32con .GWL_STYLE , style & ~ win32con .WS_OVERLAPPEDWINDOW )
119
+ win32gui .SetWindowPos (self .hwnd , win32con .HWND_TOP , 0 , 0 , screen_x , screen_y ,
116
120
win32con .SWP_NOOWNERZORDER | win32con .SWP_FRAMECHANGED )
117
121
118
122
119
123
def _create_atlax_window (self ):
120
124
_atl .AtlAxWinInit ()
121
125
hInstance = win32api .GetModuleHandle (None )
126
+
127
+ if self .fullscreen :
128
+ atl_width = self .width
129
+ atl_height = self .height
130
+ else :
131
+ atl_width = self .width - self .scrollbar_width
132
+ atl_height = self .height - self .scrollbar_height - VERTICAL_SCROLLBAR_OFFSET
133
+
122
134
self .atlhwnd = win32gui .CreateWindow ("AtlAxWin" , self .url ,
123
135
win32con .WS_CHILD | win32con .WS_HSCROLL | win32con .WS_VSCROLL ,
124
- 0 , 0 , self .width , self .height ,
125
- self .hwnd , None , hInstance , None )
136
+ 0 , 0 , atl_width , atl_height , self .hwnd , None , hInstance , None )
126
137
127
138
# COM voodoo
128
139
pBrowserUnk = POINTER (IUnknown )()
@@ -133,6 +144,7 @@ def _create_atlax_window(self):
133
144
134
145
def show (self ):
135
146
# Show main window
147
+ win32gui .SetWindowPos (self .hwnd , win32con .HWND_TOP , 0 , 0 , self .width , self .height , win32con .SWP_SHOWWINDOW )
136
148
win32gui .ShowWindow (self .hwnd , win32con .SW_SHOWNORMAL )
137
149
win32gui .UpdateWindow (self .hwnd )
138
150
@@ -185,13 +197,14 @@ def _on_destroy(self, hwnd, message, wparam, lparam):
185
197
186
198
def _on_resize (self , hwnd , message , wparam , lparam ):
187
199
# Resize the ATL window as the size of the main window is changed
188
- if BrowserView .instance != None :
200
+ if BrowserView .instance != None and not self . fullscreen :
189
201
atl_hwnd = BrowserView .instance .atlhwnd
190
202
width = win32api .LOWORD (lparam )
191
203
height = win32api .HIWORD (lparam )
192
- _user32 .SetWindowPos (atl_hwnd , win32con .HWND_TOP , 0 , 0 , width , height , win32con .SWP_SHOWWINDOW )
193
- _user32 .ShowWindow (c_int (atl_hwnd ), c_int (win32con .SW_SHOW ))
194
- _user32 .UpdateWindow (c_int (atl_hwnd ))
204
+ win32gui .SetWindowPos (atl_hwnd , win32con .HWND_TOP , 0 , 0 , width , height , win32con .SWP_SHOWWINDOW )
205
+ win32gui .ShowWindow (atl_hwnd , win32con .SW_SHOW )
206
+ win32gui .UpdateWindow (atl_hwnd )
207
+
195
208
return 0
196
209
197
210
def _on_erase_bkgnd (self , hwnd , message , wparam , lparam ):
0 commit comments