예제 #1
0
 def set_size(self, width: int, height: int) -> None:
     super().set_size(width, height)
     width, height = self._client_to_window_size(width, height)
     _user32.SetWindowPos(self._hwnd, 0, 0, 0, width, height,
                          (SWP_NOZORDER |
                           SWP_NOMOVE |
                           SWP_NOOWNERZORDER))
예제 #2
0
파일: __init__.py 프로젝트: momja/Code-Club
 def _update_view_location(self, width, height):
     if self._fullscreen:
         x = (self.screen.width - width) // 2
         y = (self.screen.height - height) // 2
     else:
         x = y = 0
     _user32.SetWindowPos(self._view_hwnd, 0, x, y, width, height,
                          SWP_NOZORDER | SWP_NOOWNERZORDER)
예제 #3
0
 def set_size(self, width, height):
     if self._fullscreen:
         raise WindowException('Cannot set size of fullscreen window.')
     width, height = self._client_to_window_size(width, height)
     _user32.SetWindowPos(self._hwnd, 0, 0, 0, width, height,
                          (SWP_NOZORDER |
                           SWP_NOMOVE |
                           SWP_NOOWNERZORDER))
예제 #4
0
파일: __init__.py 프로젝트: momja/Code-Club
 def set_visible(self, visible=True):
     if visible:
         insertAfter = HWND_TOPMOST if self._fullscreen else HWND_TOP
         _user32.SetWindowPos(self._hwnd, insertAfter, 0, 0, 0, 0,
                              SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW)
         self.dispatch_event('on_resize', self._width, self._height)
         self.activate()
         self.dispatch_event('on_show')
     else:
         _user32.ShowWindow(self._hwnd, SW_HIDE)
         self.dispatch_event('on_hide')
     self._visible = visible
     self.set_mouse_platform_visible()
예제 #5
0
 def set_visible(self, visible=True):
     if visible:
         if self._fullscreen:
             _user32.SetWindowPos(self._hwnd, HWND_TOPMOST, 0, 0, 0, 0,
                                  SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW)
         else:
             _user32.ShowWindow(self._hwnd, SW_SHOW)
         self.dispatch_event('on_show')
         self.activate()
     else:
         _user32.ShowWindow(self._hwnd, SW_HIDE)
         self.dispatch_event('on_hide')
     self._visible = visible
     self.set_mouse_platform_visible()
예제 #6
0
파일: __init__.py 프로젝트: momja/Code-Club
 def set_location(self, x, y):
     x, y = self._client_to_window_pos(x, y)
     _user32.SetWindowPos(self._hwnd, 0, x, y, 0, 0,
                          (SWP_NOZORDER | SWP_NOSIZE | SWP_NOOWNERZORDER))
예제 #7
0
파일: __init__.py 프로젝트: momja/Code-Club
    def _create(self):
        # Ensure style is set before determining width/height.
        if self._fullscreen:
            self._ws_style = WS_POPUP
            self._ex_ws_style = 0  # WS_EX_TOPMOST
        else:
            styles = {
                self.WINDOW_STYLE_DEFAULT: (WS_OVERLAPPEDWINDOW, 0),
                self.WINDOW_STYLE_DIALOG:
                (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, WS_EX_DLGMODALFRAME),
                self.WINDOW_STYLE_TOOL:
                (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, WS_EX_TOOLWINDOW),
                self.WINDOW_STYLE_BORDERLESS: (WS_POPUP, 0),
            }
            self._ws_style, self._ex_ws_style = styles[self._style]

        if self._resizable and not self._fullscreen:
            self._ws_style |= WS_THICKFRAME
        else:
            self._ws_style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX)

        if self._fullscreen:
            width = self.screen.width
            height = self.screen.height
        else:
            width, height = \
                self._client_to_window_size(self._width, self._height)

        if not self._window_class:
            module = _kernel32.GetModuleHandleW(None)
            white = _gdi32.GetStockObject(WHITE_BRUSH)
            black = _gdi32.GetStockObject(BLACK_BRUSH)
            self._window_class = WNDCLASS()
            self._window_class.lpszClassName = u'GenericAppClass%d' % id(self)
            self._window_class.lpfnWndProc = WNDPROC(
                self._get_window_proc(self._event_handlers))
            self._window_class.style = CS_VREDRAW | CS_HREDRAW
            self._window_class.hInstance = 0
            self._window_class.hIcon = _user32.LoadIconW(
                module, MAKEINTRESOURCE(1))
            self._window_class.hbrBackground = black
            self._window_class.lpszMenuName = None
            self._window_class.cbClsExtra = 0
            self._window_class.cbWndExtra = 0
            _user32.RegisterClassW(byref(self._window_class))

            self._view_window_class = WNDCLASS()
            self._view_window_class.lpszClassName = \
                u'GenericViewClass%d' % id(self)
            self._view_window_class.lpfnWndProc = WNDPROC(
                self._get_window_proc(self._view_event_handlers))
            self._view_window_class.style = 0
            self._view_window_class.hInstance = 0
            self._view_window_class.hIcon = 0
            self._view_window_class.hbrBackground = white
            self._view_window_class.lpszMenuName = None
            self._view_window_class.cbClsExtra = 0
            self._view_window_class.cbWndExtra = 0
            _user32.RegisterClassW(byref(self._view_window_class))

        if not self._hwnd:
            self._hwnd = _user32.CreateWindowExW(
                self._ex_ws_style, self._window_class.lpszClassName, u'',
                self._ws_style, CW_USEDEFAULT, CW_USEDEFAULT, width, height, 0,
                0, self._window_class.hInstance, 0)

            self._view_hwnd = _user32.CreateWindowExW(
                0, self._view_window_class.lpszClassName, u'',
                WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, self._hwnd, 0,
                self._view_window_class.hInstance, 0)

            self._dc = _user32.GetDC(self._view_hwnd)
        else:
            # Window already exists, update it with new style

            # We need to hide window here, otherwise Windows forgets
            # to redraw the whole screen after leaving fullscreen.
            _user32.ShowWindow(self._hwnd, SW_HIDE)

            _user32.SetWindowLongW(self._hwnd, GWL_STYLE, self._ws_style)
            _user32.SetWindowLongW(self._hwnd, GWL_EXSTYLE, self._ex_ws_style)

        if self._fullscreen:
            hwnd_after = HWND_TOPMOST
        else:
            hwnd_after = HWND_NOTOPMOST

        # Position and size window
        if self._fullscreen:
            _user32.SetWindowPos(self._hwnd, hwnd_after, self._screen.x,
                                 self._screen.y, width, height,
                                 SWP_FRAMECHANGED)
        elif False:  # TODO location not in pyglet API
            x, y = self._client_to_window_pos(*factory.get_location())
            _user32.SetWindowPos(self._hwnd, hwnd_after, x, y, width, height,
                                 SWP_FRAMECHANGED)
        else:
            _user32.SetWindowPos(self._hwnd, hwnd_after, 0, 0, width, height,
                                 SWP_NOMOVE | SWP_FRAMECHANGED)

        self._update_view_location(self._width, self._height)

        # Context must be created after window is created.
        if not self._wgl_context:
            self.canvas = Win32Canvas(self.display, self._view_hwnd, self._dc)
            self.context.attach(self.canvas)
            self._wgl_context = self.context._context

        self.set_caption(self._caption)

        self.switch_to()
        self.set_vsync(self._vsync)

        if self._visible:
            self.set_visible()
            # Might need resize event if going from fullscreen to fullscreen
            self.dispatch_event('on_resize', self._width, self._height)
            self.dispatch_event('on_expose')
예제 #8
0
    def _create(self):
        # Ensure style is set before determining width/height.
        if self._fullscreen:
            self._ws_style = WS_POPUP
            self._ex_ws_style = 0  # WS_EX_TOPMOST
        else:
            styles = {
                self.WINDOW_STYLE_DEFAULT: (WS_OVERLAPPEDWINDOW, 0),
                self.WINDOW_STYLE_DIALOG: (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU,
                                           WS_EX_DLGMODALFRAME),
                self.WINDOW_STYLE_TOOL: (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU,
                                         WS_EX_TOOLWINDOW),
                self.WINDOW_STYLE_BORDERLESS: (WS_POPUP, 0),
            }
            self._ws_style, self._ex_ws_style = styles[self._style]

        if self._resizable and not self._fullscreen:
            self._ws_style |= WS_THICKFRAME
        else:
            self._ws_style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX)

        if self._fullscreen:
            width = self.screen.width
            height = self.screen.height
        else:
            width, height = \
                self._client_to_window_size(self._width, self._height)

        if not self._window_class:
            module = _kernel32.GetModuleHandleW(None)
            white = _gdi32.GetStockObject(WHITE_BRUSH)
            black = _gdi32.GetStockObject(BLACK_BRUSH)
            self._window_class = WNDCLASS()
            self._window_class.lpszClassName = u'GenericAppClass%d' % id(self)
            self._window_class.lpfnWndProc = WNDPROC(
                self._get_window_proc(self._event_handlers))
            self._window_class.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC
            self._window_class.hInstance = 0
            self._window_class.hIcon = _user32.LoadIconW(module, MAKEINTRESOURCE(1))
            self._window_class.hbrBackground = black
            self._window_class.lpszMenuName = None
            self._window_class.cbClsExtra = 0
            self._window_class.cbWndExtra = 0
            _user32.RegisterClassW(byref(self._window_class))

            self._view_window_class = WNDCLASS()
            self._view_window_class.lpszClassName = \
                u'GenericViewClass%d' % id(self)
            self._view_window_class.lpfnWndProc = WNDPROC(
                self._get_window_proc(self._view_event_handlers))
            self._view_window_class.style = 0
            self._view_window_class.hInstance = 0
            self._view_window_class.hIcon = 0
            self._view_window_class.hbrBackground = white
            self._view_window_class.lpszMenuName = None
            self._view_window_class.cbClsExtra = 0
            self._view_window_class.cbWndExtra = 0
            _user32.RegisterClassW(byref(self._view_window_class))

        if not self._hwnd:
            self._hwnd = _user32.CreateWindowExW(
                self._ex_ws_style,
                self._window_class.lpszClassName,
                u'',
                self._ws_style,
                CW_USEDEFAULT,
                CW_USEDEFAULT,
                width,
                height,
                0,
                0,
                self._window_class.hInstance,
                0)

            self._view_hwnd = _user32.CreateWindowExW(
                0,
                self._view_window_class.lpszClassName,
                u'',
                WS_CHILD | WS_VISIBLE,
                0, 0, 0, 0,
                self._hwnd,
                0,
                self._view_window_class.hInstance,
                0)

            self._dc = _user32.GetDC(self._view_hwnd)

            # Only allow files being dropped if specified.
            if self._file_drops:
                # Allows UAC to not block the drop files request if low permissions. All 3 must be set.
                if WINDOWS_7_OR_GREATER:
                    _user32.ChangeWindowMessageFilterEx(self._hwnd, WM_DROPFILES, MSGFLT_ALLOW, None)
                    _user32.ChangeWindowMessageFilterEx(self._hwnd, WM_COPYDATA, MSGFLT_ALLOW, None)
                    _user32.ChangeWindowMessageFilterEx(self._hwnd, WM_COPYGLOBALDATA, MSGFLT_ALLOW, None)

                _shell32.DragAcceptFiles(self._hwnd, True)
                
            # Register raw input keyboard to allow the window to receive input events.
            raw_keyboard = RAWINPUTDEVICE(0x01, 0x06, 0, self._view_hwnd)
            if not _user32.RegisterRawInputDevices(
                byref(raw_keyboard), 1, sizeof(RAWINPUTDEVICE)):
                    print("Warning: Failed to register raw input keyboard. on_key events for shift keys will not be called.")
        else:
            # Window already exists, update it with new style

            # We need to hide window here, otherwise Windows forgets
            # to redraw the whole screen after leaving fullscreen.
            _user32.ShowWindow(self._hwnd, SW_HIDE)

            _user32.SetWindowLongW(self._hwnd,
                                   GWL_STYLE,
                                   self._ws_style)
            _user32.SetWindowLongW(self._hwnd,
                                   GWL_EXSTYLE,
                                   self._ex_ws_style)

        if self._fullscreen:
            hwnd_after = HWND_TOPMOST
        else:
            hwnd_after = HWND_NOTOPMOST

        # Position and size window
        if self._fullscreen:
            _user32.SetWindowPos(self._hwnd, hwnd_after,
                                 self._screen.x, self._screen.y, width, height, SWP_FRAMECHANGED)
        elif False:  # TODO location not in pyglet API
            x, y = self._client_to_window_pos(*factory.get_location())
            _user32.SetWindowPos(self._hwnd, hwnd_after,
                                 x, y, width, height, SWP_FRAMECHANGED)
        else:
            _user32.SetWindowPos(self._hwnd, hwnd_after,
                                 0, 0, width, height, SWP_NOMOVE | SWP_FRAMECHANGED)

        self._update_view_location(self._width, self._height)

        # Context must be created after window is created.
        if not self._wgl_context:
            self.canvas = Win32Canvas(self.display, self._view_hwnd, self._dc)
            self.context.attach(self.canvas)
            self._wgl_context = self.context._context

        self.set_caption(self._caption)

        self.switch_to()
        self.set_vsync(self._vsync)

        if self._visible:
            self.set_visible()
            # Might need resize event if going from fullscreen to fullscreen
            self.dispatch_event('on_resize', self._width, self._height)
            self.dispatch_event('on_expose')
예제 #9
0
 def set_size(self, width, height):
     super().set_size(width, height)
     width, height = self._client_to_window_size(width, height)
     _user32.SetWindowPos(self._hwnd, 0, 0, 0, width, height,
                          (SWP_NOZORDER | SWP_NOMOVE | SWP_NOOWNERZORDER))
     self.dispatch_event('on_resize', width, height)