惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
云风的 BLOG
云风的 BLOG
G
Google Developers Blog
S
SegmentFault 最新的问题
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
爱范儿
爱范儿
博客园 - 三生石上(FineUI控件)
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
DataBreaches.Net
F
Fortinet All Blogs
TaoSecurity Blog
TaoSecurity Blog
D
Docker
C
Cybersecurity and Infrastructure Security Agency CISA
K
Kaspersky official blog
宝玉的分享
宝玉的分享
腾讯CDC
Google Online Security Blog
Google Online Security Blog
Recorded Future
Recorded Future
T
The Exploit Database - CXSecurity.com
T
The Blog of Author Tim Ferriss
V
V2EX
S
Securelist
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
CERT Recently Published Vulnerability Notes
A
Arctic Wolf
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
Y
Y Combinator Blog
P
Proofpoint News Feed
T
Tor Project blog
AWS News Blog
AWS News Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
博客园 - 聂微东
T
Threat Research - Cisco Blogs
B
Blog
Attack and Defense Labs
Attack and Defense Labs
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
N
News and Events Feed by Topic
博客园 - 司徒正美
H
Help Net Security
C
Cisco Blogs
C
Check Point Blog
S
Secure Thoughts

博客园 - jasonM

真是郁闷,团队中居然出了这样的骗子!! C++反汇编揭秘1 – 一个简单C++程序反汇编解析 函数调用堆栈变化分析 - jasonM - 博客园 为什么要下断bpSend,原理分析。 做挂第一步:如何找基址(以热血传奇为例) 一步步学外挂(二).CALL的原理。 - jasonM - 博客园 开发企业直销软件需求分析 正则表达式系列文章整理 群发软件开发原理分析 通俗解释socket(并附上注释Socket源代码) CMainFrame::PreCreateWindow这个函数执行了两次 .net调用vc++写的dll 一步步学破解-sdk用实例讲解GDI映射机制 一步步学破解-sdk用实例讲解GDI(含各个消息的调用时机) 一步步学破解-sdk进程间传递信息 一步步学破解-在已有的主窗口上创建按钮(三) 一步步学破解-windows消息循环原理实例总结(二) 一步步学破解-函数调用堆栈变化分析 (一) 老王最新壳试脱时遇到的问题,详细表述如下
开发旺旺群发软件,难点及重要技术点分析(一)
jasonM · 2009-06-30 · via 博客园 - jasonM
 

开发旺旺群发软件,难点及重要技术点分析(一)

一.        C#中调用Win32函数EnumWindows枚举所有窗口。

EnumWindows 函数通过借助于应用程序定义的回调函数传递每个窗口句柄枚举所有顶层的屏幕窗口。直到最后一个顶层窗口被枚举或者回调函数返回false EnumWindows 函数才会退出停止枚举过程。

下面例子说明如何在 C# 中调用 Win32 API - EnumWindows 枚举所有窗口:

1.首先需要声明一个委托函数用于 Win32 API - EnumWindows 的回调函数:
public delegate bool CallBack(int hwnd, int lParam);

2.

然后利用 C# 中的平台调用声明从 USER32.DLL 库中调用 API - EnumWindows,具体参数请参考 MSDN - Win32 API

[DllImport("user32")]

public static extern int EnumWindows(CallBack x, int y);

3.

最后实例化委托,调用 EnumWindows

CallBack myCallBack = new CallBack(EnumWindowsApp.Report);

4.代码如下:

using System;

using System.Collections.Generic;

using System.Text;

using System.Runtime.InteropServices;

namespace ConsoleApplication1

{

    public delegate bool CallBack(int hwnd, int lParam);

    class Program

    {

        [DllImport("user32")]

        public static extern int EnumWindows(CallBack x, int y);

        static void Main(string[] args)

        {

            CallBack myCallBack = new CallBack(Program.Report);

            EnumWindows(myCallBack, 0);

        }

        public static bool Report(int hwnd, int lParam)

        {

            Console.Write("Window handle is :");

            Console.WriteLine(hwnd);

            Console.Read();

            return true;

        }

    }

}

二.          现在我们用一个winform来演示查找旺旺窗口的句柄

代码如下:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Text.RegularExpressions;

using System.Diagnostics;

using System.Threading;

using System.Windows.Forms;

using System.Runtime.InteropServices;

namespace WindowsApplication4

{

    public struct WindowInfo

    {

        public IntPtr hWnd;

        public string szWindowName;

        public string szClassName;

     }

    public partial class Form1 : Form

    {

        [DllImport("shell32.dll")]

        public static extern int ShellExecute(IntPtr hwnd, StringBuilder lpszOp, StringBuilder lpszFile, StringBuilder lpszParams, StringBuilder lpszDir, int FsShowCmd);

        [DllImport("user32.dll")]

        private static extern bool EnumWindows(WNDENUMPROC lpEnumFunc, int lParam);

        [DllImport("user32.dll", CharSet = CharSet.Auto)]

        public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, string lparam);

        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]//查找窗口

        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll")]

        public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

        [DllImport("user32.dll")]

        private static extern int GetWindowTextW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)]StringBuilder lpString, int nMaxCount);

        [DllImport("user32.dll")]

        private static extern int GetClassNameW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)]StringBuilder lpString, int nMaxCount);

        private delegate bool WNDENUMPROC(IntPtr hWnd, int lParam);

        private IntPtr Game;

        public Form1()

        {

            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)

        {

        }

        //寻找系统的全部窗口

        public WindowInfo[] GetAllDesktopWindows()

        {

            List<WindowInfo> wndList = new List<WindowInfo>();

            EnumWindows(delegate(IntPtr hWnd, int lParam)

            {

                WindowInfo wnd = new WindowInfo();

                StringBuilder sb = new StringBuilder(256);

                //get hwnd

                wnd.hWnd = hWnd;

                //get window name

                GetWindowTextW(hWnd, sb, sb.Capacity);

                wnd.szWindowName = sb.ToString();

                //get window class

                GetClassNameW(hWnd, sb, sb.Capacity);

                wnd.szClassName = sb.ToString();

                //add it into list

                wndList.Add(wnd);

                return true;

            },0);

        return wndList.ToArray();

        }

        private void button1_Click(object sender, EventArgs e)

        {

            WindowInfo[] a = GetAllDesktopWindows();

            int i=0;

            int index=0;

            for (i = 0; i < a.Length; i++)

            {

               // MessageBox.Show(a[i].szWindowName.ToString());

                if (a[i].szWindowName.ToString().Contains("mafangmin888"))

                {

                    MessageBox.Show(a[i].szClassName.ToString());

                    index = i;

                }

            }

            game = new IntPtr(a[index].hWnd);

        }

    }

}