C# 消息发送
界面

frmMain
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
namespace lxw_QQAutoSendMsg
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private List<QQChatWindows> ltQQChatWindows = new List<QQChatWindows>();
private void btnFindQQWindow_Click(object sender, EventArgs e)
{
FindQQChatWindows();
}
private void btnSendMsg_Click(object sender, EventArgs e)
{
if (this.txtSendText.Text.Equals(String.Empty))
{
MessageBox.Show("请输入要发送的内容");
return;
}
if (ltQQChatWindows.Count <= 0)
{
MessageBox.Show("没有可用发送的聊天窗体,请先查找对话框!");
return;
}
if (this.listQQWindows.SelectedItem == null)
{
MessageBox.Show("请选择需要发送消息的窗体");
return;
}
string qqCaption = this.listQQWindows.SelectedItem.ToString();
QQChatWindows qqChatWindows = ltQQChatWindows.Find(o => o.Caption.Equals(qqCaption));
if (qqChatWindows == null)
{
MessageBox.Show("没有找到可发送信息的QQ聊天窗体,请先查找对话框!");
}
else
{
int RepeatTime = 10;
int SleepTime = 1000;
if (!int.TryParse(txtRepeatTime.Text, out RepeatTime))
{
RepeatTime = 10;
}
if (!int.TryParse(txtSleepTime.Text, out SleepTime))
{
SleepTime = 1000;
}
string error = "";
string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string info = "";
for (int i = 0; i < RepeatTime; i++)
{
if (this.SendQQMsg(qqChatWindows.WindowHwnd, this.txtSendText.Text, out error))
{
info = time + " [" + qqCaption + "]-->" + "发送成功";
}
else
{
info = time + " [" + qqCaption + "]-->" + "发送失败:" + error;
}
if (info.Contains("发送失败"))
{
//高亮显示
rtxtInfo.SelectionStart = rtxtInfo.Text.Length;
rtxtInfo.SelectionLength = info.Length;
rtxtInfo.SelectionColor = Color.FromName("Red");
}
rtxtInfo.AppendText(info + "\r\n");
Thread.Sleep(SleepTime);
}
}
}
/// <summary>
/// 查找QQ对话框
/// </summary>
private void FindQQChatWindows()
{
this.listQQWindows.Items.Clear();
ltQQChatWindows.Clear();
WinAPI.EnumDesktopWindows(IntPtr.Zero, new WinAPI.EnumDesktopWindowsDelegate(EnumWindowsProc), IntPtr.Zero);
}
private bool EnumWindowsProc(IntPtr hWnd, uint lParam)
{
string qqProName = this.GetProcessName(hWnd);
StringBuilder className = new StringBuilder(255 + 1); //ClassName 最长
WinAPI.GetClassName(hWnd, className, className.Capacity);
if (!qqProName.Equals(String.Empty) && qqProName.Equals("QQ") && className.ToString().Equals("TXGuiFoundation"))
{
StringBuilder caption = new StringBuilder(WinAPI.GetWindowTextLength(hWnd) + 1);
WinAPI.GetWindowText(hWnd, caption, caption.Capacity);
if (!caption.ToString().Equals(String.Empty) && !caption.ToString().Equals("TXMenuWindow"))
{
QQChatWindows qqchat = new QQChatWindows(hWnd, caption.ToString());
ltQQChatWindows.Add(qqchat);
this.listQQWindows.Items.Add(caption);
}
}
return true;
}
public string GetProcessName(IntPtr hWnd)
{
try
{
string processname = String.Empty;
int proid = 0;
uint threadid = WinAPI.GetWindowThreadProcessId(hWnd, out proid);
if (threadid > 0 && proid > 0)
{
Process pro = Process.GetProcessById(proid);
processname = pro.ProcessName;
}
return processname;
}
catch
{
return String.Empty;
}
}
/// <summary>
/// 发送消息
/// </summary>
/// <param name="hWnd"></param>
/// <param name="sendText"></param>
/// <param name="error"></param>
/// <returns></returns>
private bool SendQQMsg(IntPtr hWnd, string sendText, out string error)
{
error = "";
try
{
WinAPI.ShowWindow(hWnd, WinAPI.ShowWindowCommands.Normal);
WinAPI.BringWindowToTop(hWnd);
SendKeys.SendWait(sendText);
//SendKeys.SendWait("^{ENTER}");//Ctrl+Enter
SendKeys.Send("{ENTER}");//Enter
return true;
}
catch (Exception ex)
{
error = ex.Message;
return false;
}
}
}
}
C# 消息发送的更多相关文章
- C#开发微信门户及应用(19)-微信企业号的消息发送(文本、图片、文件、语音、视频、图文消息等)
我们知道,企业号主要是面向企业需求而生的,因此内部消息的交流显得非常重要,而且发送.回复消息数量应该很可观,对于大企业尤其如此,因此可以结合企业号实现内部消息的交流.企业号具有关注安全.消息无限制等特 ...
- [UWP]UWP中获取联系人/邮件发送/SMS消息发送操作
这篇博客将介绍如何在UWP程序中获取联系人/邮件发送/SMS发送的基础操作. 1. 获取联系人 UWP中联系人获取需要引入Windows.ApplicationModel.Contacts名称空间. ...
- Kafka、RabbitMQ、RocketMQ消息中间件的对比 —— 消息发送性能-转自阿里中间件
引言 分布式系统中,我们广泛运用消息中间件进行系统间的数据交换,便于异步解耦.现在开源的消息中间件有很多,前段时间我们自家的产品 RocketMQ (MetaQ的内核) 也顺利开源,得到大家的关注. ...
- iOS开发小技巧--即时通讯项目:消息发送框(UITextView)高度的变化; 以及UITextView光标复位的小技巧
1.即时通讯项目中输入框(UITextView)跟随输入文字的增多,高度变化的实现 最主要的方法就是监听UITextView的文字变化的方法- (void)textViewDidChange:(UIT ...
- activemq安装与简单消息发送接收实例
安装环境:Activemq5.11.1, jdk1.7(activemq5.11.1版本需要jdk升级到1.7),虚拟机: 192.168.147.131 [root@localhost softwa ...
- eBay 消息发送(2)
1.简介 Call Index Doc: http://developer.ebay.com/DevZone/XML/docs/Reference/eBay/index.html 消息发送主要 ...
- eBay 消息发送(1)
1.简介 Call Index Doc: http://developer.ebay.com/DevZone/XML/docs/Reference/eBay/index.html 消息发送主要 ...
- twitter storm源码走读之2 -- tuple消息发送场景分析
欢迎转载,转载请注明出处源自徽沪一郎.本文尝试分析tuple发送时的具体细节,本博的另一篇文章<bolt消息传递路径之源码解读>主要从消息接收方面来阐述问题,两篇文章互为补充. worke ...
- ActiveMQ点对点的消息发送案例
公司最近会用MQ对某些业务进行处理,所以,这次我下载了apache-activemq-5.12.0-bin把玩下. 基于练习方便需要,使用Windows的版本. 参考的优秀文章: activemq的几 ...
- 高效的TCP消息发送组件
目前的.net 架构下缺乏高效的TCP消息发送组件,而这种组件是构建高性能分布式应用所必需的.为此我结合多年的底层开发经验开发了一个.net 下的高效TCP消息发送组件.这个组件在异步发送时可以达到每 ...
随机推荐
- 一文总结 C++ 常量表达式、constexpr 和 const
TLDR 修饰变量的时候,可以把 constexpr 对象当作加强版的 const 对象:const 对象表明值不会改变,但不一定能够在编译期取得结果:constexpr 对象不仅值不会改变,而且保证 ...
- 【Android】截图案例
1 工作空间 2 代码 MainActivity.java package com.zhyan8.demo; import android.graphics.Bitmap; import andr ...
- 解决unable to find valid certification path to requested target
问题描述 最近java程序去调用远程服务器接口时报错了: I/O error on POST request for "https://XXX.xyz/create": sun.s ...
- Oracle DBMS_UTILITY.GET_TIME与DBMS_UTILITY.GET_CPU_TIME区别
DBMS_UTILITY.GET_TIME与DBMS_UTILITY.GET_CPU_TIME比较 原文链接: http://www.oracle-developer.net/display.php? ...
- OFDM系统各种调制阶数的QAM误码率(Symbol Error Rate)与 误比特率(Bit Error Rate)仿真结果
本文是OFDM系统的不同QAM调制阶数的误码率与误比特率仿真,仅考虑在高斯白噪声信道下的情景,着重分析不同信噪比下的误码(符号)率性能曲线,不关心具体的调制与解调方案,仿真结果与理论的误码率曲线进行了 ...
- RK3588开发笔记(二):基于方案商提供sdk搭建引入mpp和sdk的宿主机交叉编译Qt5.12.10环境
前言 上一篇项目已经构建好了Qt,板子接入mipi屏幕也跑起来了,Qt也能正常运行了,现在需要接入定制开发的sdk,sdk中使用了硬解码等资源涉及到bsp的mpp,所以下一步就是引入mpp和sdk ...
- 统信UOS系统开发笔记(五):安装QtCreator开发IDE中的中文输入环境Fcitx输入法
前言 中文输入法,QtCreator中无法输入中文也是ubuntu中一个常规问题,在国产银河麒麟系统中也有此问题(PS:最终无法结局,用文本自行贴),国产UOS也有此问题,本片要解决此问题,主要是 ...
- 【LeetCode栈与队列#03】删除字符串中所有的相邻重复项
删除字符串中所有的相邻重复项 力扣题目链接(opens new window) 给出由小写字母组成的字符串 S,重复项删除操作会选择两个相邻且相同的字母,并删除它们. 在 S 上反复执行重复项删除操作 ...
- 第一百一十二篇: JS数组Array(一)数组基本用法
好家伙, 1.数组 Array应该就是ECMAScript中最常用的类型了.ECMAScript数组跟其他编程语言的数组有很大区别. 跟其他语言中的数组一样,ECMAScript 数组也是一组有序 ...
- 阿尔萨斯(Arthas)入门
目录 简介 Arthas(阿尔萨斯) 能为你做什么 安装 快速安装 全量安装 卸载 使用 启动arthas 查看dashboard 通过thread命令来获取到arthas-demo进程的Main C ...