虚拟机有QQ消息时宿主机自动弹窗提示
2017-08-17 19:59
344 查看
因为是检测窗口实现的,所以要求设置会话窗口自动弹出,而且看完消息就把QQ消息窗口关掉。。。
虚拟机端
宿主机端
虚拟机端
#! /usr/bin/env python # -*- coding: utf-8 -*- from win32gui import * import time import socket HOST = '192.168.0.126'#宿主机IP地址 PORT = 8001 def get_QQ_titles(hwnd, mouse): if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd): if GetClassName(hwnd) == 'TXGuiFoundation': # TXGuiFoundation 是所有QQ窗口的类名 text=GetWindowText(hwnd) if text: current_QQ_titles.add(text) def send_message(): # 通知宿主机 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) s.send('new_msg') data = s.recv(10) print data last_QQ_titles = set() # 上一次所有可见QQ窗口的 title 字符串集合 current_QQ_titles = set() # 当前所有可见QQ窗口的 title 字符串集合 last_foreground_window_class_name = '' # 上一个 foreground window 的类名 while True: current_QQ_titles = set() EnumWindows(get_QQ_titles, 0) # 遍历当前可见的QQ窗口 try: foreground_window = GetForegroundWindow() foreground_window_text = GetWindowText(foreground_window) foreground_window_class_name = GetClassName(foreground_window) except Exception,e: print('catch exception') if last_QQ_titles != current_QQ_titles \ and len(last_QQ_titles) < len(current_QQ_titles) \ and (last_foreground_window_class_name != foreground_window_class_name \ or (last_foreground_window_class_name == foreground_window_class_name \ and foreground_window_text != 'QQ')): print 'got new message' send_message() last_QQ_titles = current_QQ_titles last_foreground_window_class_name = foreground_window_class_name time.sleep(1)
宿主机端
#encoding=utf-8 import Tkinter as tk import socket def create_message_dialog(): top = tk.Tk() top.title("QQ Message") top.geometry('400x400') labelHello = tk.Label(top, text = "You've got new QQ messages.") labelHello.pack() top.mainloop() HOST = '192.168.0.126' PORT = 8001 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) s.listen(1) print 'Server start at: %s:%s' %(HOST, PORT) print 'wait for connection...' while True: conn, addr = s.accept() print 'Connected by ', addr data = conn.recv(10) print data if data=='new_msg': create_message_dialog() conn.send("recv") conn.close()
END
2017.8.17 19:58相关文章推荐
- 类似QQ右下角消息提示---自动隐藏。不大适合
- 类似QQ导航底部显示提示弹窗,能自动消失
- 类似QQ右下角消息提示2--自动刷新
- 解决Win7下QQ消息提示音导致播放电影音乐音量自动变小
- Ajax轮询消息自动提示(消息盒子)
- C# 模仿QQ、MSN消息提示系列 二、基本效果模仿包含代码
- C# 模仿QQ、MSN消息提示系列 三、实现多个提示效果
- 模仿QQ拖动清除消息提示
- 类似QQ消息提示框
- 自动发送qq消息 VBS脚本
- phpcms模仿QQ和MSN消息提示的效果
- 类似QQ消息提示的任务栏窗口图标的高亮显示方法
- 页面右下角弹出类似QQ或MSN的消息提示
- Windows 7的VPC虚拟机自动不与主机时间同步的解决办法
- Android 带角标的ImageView(微博,QQ消息提示)
- ExtJs定时消息提示框,类似于QQ右下角提示,ExtJs如何定时向后台发出两个请求并刷新数据实例
- C# 模仿QQ、MSN消息提示系列 四、bug修改 效果优化
- 实现MSN,QQ消息提示效果[ASP.Net]
- 仿QQ、MSN消息提示窗口的实现(C#)
- Jquery 网站保存信息提示消息实现,提示后自动消失