using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms; namespace test
{
public partial class Form1 : Form
{
[DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int GlobalAddAtom(string lpString); [DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int GlobalDeleteAtom(int atom); [DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern uint GlobalGetAtomName(int nAtom, string lpBuffer, int nSize); [DllImport("user32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(int hwnd, int wMsg, int wParam, int lParam); /// <summary>
/// 定义了一个专用通知消息
/// </summary>
private const int WM_TextNotify = 1090;
/// <summary>
/// 发送文本消息
/// </summary>
/// <param name="pHandle">接收句柄</param>
/// <param name="sText">发送的文本</param>
private static void SendFormMessage(int pHandle, string sText)
{
int atom = GlobalAddAtom(sText);
SendMessage(pHandle, WM_TextNotify, 0, atom);
GlobalDeleteAtom(atom);
} public Form1()
{
InitializeComponent(); StartPosition = FormStartPosition.CenterScreen; this.textBox1.Text = this.Handle.ToInt32().ToString();
} private void button1_Click(object sender, EventArgs e)
{
SendFormMessage(int.Parse(textBox1.Text.Trim()), textBox2.Text);
} protected override void WndProc(ref Message m)
{
base.WndProc(ref m); if (m.Msg.Equals(WM_TextNotify))
{
string cmd = string.Empty;
GlobalGetAtomName(m.LParam.ToInt32(), cmd, 1024); this.textBox3.Text = cmd;
}
}
}
}

demo: https://files.cnblogs.com/files/onlyou13/testSendAtom.rar

c# GlobalAddAtom GlobalDeleteAtom的更多相关文章

  1. GlobalGetAtomName GlobalDeleteAtom 引用 WinAPI: AddAtom、DeleteAtom、FindAtom、GetAtomName、GlobalAddAtom、GlobalDeleteAtom、GlobalFindAtom、GlobalGetAtomName

    http://www.cnblogs.com/del/archive/2008/02/28/1085124.html 这是储存字符串的一组 API.通过 AddAtom 储存一个字符串, 返回一个 I ...

  2. SetWindowPos,RegisterHotKey,GlobalAddAtom的用法

    还以为SetWindowPos是给Frm的子框架间编写的,原来是给mainfrm写的,可以把你写的主窗口置顶,置底(看样子应该可以变成桌面了,还没试呢,才忙到现在...) 子窗口的遮挡可以使用窗口的样 ...

  3. 通过GlobalAddAtom,GlobalGetAtomName方式发送字符串

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  4. 转 C# 只允许运行一个实例

    来源:http://blog.csdn.net/jin20000/article/details/3136791 互斥进程(程序), 简单点说,就是在系统中只能有该程序的一个实例运行. 现在很多软件都 ...

  5. C#封装好的Win32API

    Kernel.cs using System; using System.Runtime.InteropServices; using System.Text; using HANDLE = Syst ...

  6. WPF之全局快捷键

    目录 1.WPF快捷键实现方式 2.全局快捷键设置界面 3.Windows API调用 4.注册全局快捷键 5.快捷键触发 WPF快捷键实现方式 WPF快捷键实现主要有自定义快捷键命令和全局快捷键两种 ...

  7. 英文不好也能快速"记忆" API

    英文不好不要紧,把API函数导入打字练习类软件,即是练习打字速度,提高编程效率:也能短时间记忆API. 坚持每天打一遍,约2小时,连续打两周,会对API有很好的记忆,此方法是结合英文学习方法!以下是W ...

  8. C# winform应用程序仅能打开一个进程运行

    判断程序是否已经运行,使程序只能运行一个实例: 方法1: //这种检测进程的名的方法,并不绝对有效.因为打开第一个实例后,将运行文件改名后,还是可以运行第二个实例. private static bo ...

  9. 【转】delphi程序只允许运行一个实例的三种方法:

    一.        创建互斥对象 在工程project1.dpr中创建互斥对象 Program project1 Uses Windows,Form, FrmMain in 'FrmMain.pas' ...

随机推荐

  1. Caffe2 载入预训练模型(Loading Pre-Trained Models)[7]

    这一节我们主要讲述如何使用预训练模型.Ipython notebook链接在这里. 模型下载 你可以去Model Zoo下载预训练好的模型,或者使用Caffe2的models.download模块获取 ...

  2. 数学公式在 iOS 中的表示

    1. 三角函数  double sin (double);正弦  double cos (double);余弦  double tan (double);正切 2 .反三角函数  double asi ...

  3. UCOS-III API函数

    附录:UCOS-III API函数 任务管理 就绪列表 挂起队列 时间管理 信号量 消息队列 内存管理

  4. Python 爬取 北京市政府首都之窗信件列表-[数据处理]

    日期:2020.01.24 博客期:132 星期五 [代码说明,如果要使用此页代码,必须在本博客页面评论区给予说明] //博客总体说明 1.准备工作 2.爬取工作 3.数据处理(本期博客) 4.信息展 ...

  5. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 辅助类:"text-info" 类的文本样式

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  6. day07 集合

    ''' list,查询过程中修改,会报错,类似java的并发修改异常 Traceback (most recent call last): File "C:/1xubenqing/pytho ...

  7. 【剑指Offer面试编程题】题目1214:丑数--九度OJ

    把只包含因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因为它包含因子7. 习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第N个丑数. 输入: 输入包括一个 ...

  8. C语言入门书籍知识点记录

    1. 数据在内存中的存储(二进制存储) 内存条:电路的电压有两种状态:0V或者5V,对应的一个元器件有2种状态:0 或者1. 一般情况下我们不一个一个的使用元器件,而是将8个元器件看做一个单位. 一个 ...

  9. js 实现去重

    ES6 set去重 Array.from(new Set([1,2,3,3,4,4])) // [1,2,3,4] [...new Set([1,2,3,3,4,4])] // [1,2,3,4] 使 ...

  10. JS监听手机物理返回键,返回到指定页面

    pushHistory(); window.addEventListener("popstate", function(e) { window.location = data.in ...