之前看到开心expz的那个恶搞程序觉着挺好玩,就想用python试一下那个改msgbox位置的功能
[Python] 纯文本查看 复制代码 import time
import tkinter
import ctypes
import threading
x1 = 0
y1 = 0
tk = tkinter.Tk()
class RECT(ctypes.Structure):
_fields_ = [("left", ctypes.c_long),
("top", ctypes.c_long),
("right", ctypes.c_long),
("bottom", ctypes.c_long)]
user32 = ctypes.windll.user32
kernel32 = ctypes.windll.kernel32
handle = user32.FindWindowW(None,'tk')
print(handle)
def xyx(lMsg,wParam,lParam):
global x1,y1
if lMsg == 5:
rectmsg = RECT()
user32.GetWindowRect(wParam,rectmsg)
w = rectmsg.right - rectmsg.left
h = rectmsg.bottom - rectmsg.top
if x1 <= user32.GetSystemMetrics(0) - w:
tmpa = x1
else:
tmpa = user32.GetSystemMetrics(0) - w
if x1 >= 0:
a = tmpa
else:
a = 0
if y1 <= user32.GetSystemMetrics(1) - h - 40:
tmpb = y1
else:
tmpb = user32.GetSystemMetrics(1) - h - 40
if y1 >= 0:
b = tmpb
else:
b = 0
user32.SetWindowPos(wParam,0,a,b,b,a,21)
x1 = x1 + 21
y1 = y1 + 21
user32.UnhookWindowsHookEx(hHook)
return 0
def win(weizhi):
HOOKPROC = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int)
global hHook
hHook = user32.SetWindowsHookExW(5,HOOKPROC(weizhi),user32.GetWindowLongW(handle,-6),kernel32.GetCurrentThreadId())
user32.MessageBoxTimeoutW(0,'0x00C21FE5 指定引用的 0x00C21FE5 内存。因 0xc000000e 的错误状态而无法将请求的数据放入内存。\r\r要终止程序,请单击"确定"。','winlogon.exe - 应用程序错误',16|65536,0,5000)
print('hhh')
for _ in range(10):
time.sleep(1)
thread = threading.Thread(target=win,args=(xyx,))
thread.start()
但python运行会出大问题
不知道哪里有错。。。 |