Skip to content

Commit 3569581

Browse files
committed
Update main.py
1 parent 1115343 commit 3569581

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/main.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,39 @@
33
import sys
44
import mainWindowGUI as mainWindowGUI
55
import mineSweeperGUI as mineSweeperGUI
6-
from win32gui import FindWindow
76
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
819

920

1021
if __name__ == "__main__":
22+
23+
24+
1125
app = QtWidgets.QApplication (sys.argv)
1226
mainWindow = mainWindowGUI.MainWindow()
1327
ui = mineSweeperGUI.MineSweeperGUI(mainWindow, sys.argv)
1428
ui.mainWindow.show()
1529
ui.mainWindow.game_setting_path = ui.game_setting_path
1630

31+
hwnd = find_window(None, "元扫雷")
1732

1833
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+
2139

2240
sys.exit(app.exec_())
2341
...

0 commit comments

Comments
 (0)