|
3 | 3 | import sys |
4 | 4 | import mainWindowGUI as mainWindowGUI |
5 | 5 | import mineSweeperGUI as mineSweeperGUI |
6 | | -from win32gui import FindWindow |
7 | 6 | import ctypes |
| 7 | +from ctypes import wintypes |
| 8 | + |
| 9 | + |
| 10 | +def find_window(class_name, window_name): |
| 11 | + user32 = ctypes.WinDLL('user32', use_last_error=True) |
| 12 | + user32.FindWindowW.argtypes = [wintypes.LPCWSTR, wintypes.LPCWSTR] |
| 13 | + user32.FindWindowW.restype = wintypes.HWND |
| 14 | + |
| 15 | + hwnd = user32.FindWindowW(class_name, window_name) |
| 16 | + if not hwnd: |
| 17 | + raise ctypes.WinError(ctypes.get_last_error()) |
| 18 | + return hwnd |
8 | 19 |
|
9 | 20 |
|
10 | 21 | if __name__ == "__main__": |
| 22 | + |
| 23 | + |
| 24 | + |
11 | 25 | app = QtWidgets.QApplication (sys.argv) |
12 | 26 | mainWindow = mainWindowGUI.MainWindow() |
13 | 27 | ui = mineSweeperGUI.MineSweeperGUI(mainWindow, sys.argv) |
14 | 28 | ui.mainWindow.show() |
15 | 29 | ui.mainWindow.game_setting_path = ui.game_setting_path |
16 | 30 |
|
| 31 | + hwnd = find_window(None, "元扫雷") |
17 | 32 |
|
18 | 33 | SetWindowDisplayAffinity = ctypes.windll.user32.SetWindowDisplayAffinity |
19 | | - ui.disable_screenshot = lambda: ... if SetWindowDisplayAffinity(FindWindow(None, "元扫雷"), 0x00000011) else 1/0 |
20 | | - ui.enable_screenshot = lambda: ... if SetWindowDisplayAffinity(FindWindow(None, "元扫雷"), 0x00000000) else 1/0 |
| 34 | + ui.disable_screenshot = lambda: ... if SetWindowDisplayAffinity(hwnd, 0x00000011) else 1/0 |
| 35 | + ui.enable_screenshot = lambda: ... if SetWindowDisplayAffinity(hwnd, 0x00000000) else 1/0 |
| 36 | + |
| 37 | + |
| 38 | + |
21 | 39 |
|
22 | 40 | sys.exit(app.exec_()) |
23 | 41 | ... |
|
0 commit comments