C# EnumWindows示例代码

摘要:
代码开箱即用,唯一需要处理的就是要提供一个进程的pid。

代码开箱即用,唯一需要处理的就是要提供一个进程的pid。

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Runtime;
usingSystem.Runtime.InteropServices;
usingSystem.Diagnostics;

namespaceEnumPTW
{
    classProgram
    {
        [DllImport("user32.dll", SetLastError = true)]
        static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uintlpdwProcessId);

        //Callback Declaration
        public delegate bool EnumWindowsCallback(IntPtr hwnd, intlParam);
        [DllImport("user32.dll")]
        private static extern int EnumWindows(EnumWindowsCallback callPtr, intlParam);
        [DllImport("user32.dll", SetLastError = true)]
        internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, boolbRepaint);

        public static bool ReportWindow(IntPtr hwnd, intlParam)
        {
            uint processId = 0;
            uint threadId = GetWindowThreadProcessId(hwnd, outprocessId);
           
            if(processId == 23272)  //23272: another program pid
{
                Console.WriteLine(string.Format("Enumerated Window Handle 0x{0:X8}, Process {1}, Thread {2}", hwnd.ToInt32(), processId, threadId));
                
                MoveWindow(hwnd, 100, 100, 800, 600, true);
            }
            
            return true;
        }

        static void Main(string[] args)
        {
            //Have to declare a delegate so that a thunk is created, so that win32 may call us back.
            EnumWindowsCallback callBackFn = newEnumWindowsCallback(ReportWindow);

            EnumWindows(callBackFn, 0);

            Console.WriteLine("Finished. Press any key to continue.");
            Console.ReadKey();
        }
    }
}

一些github上的例子:

免责声明:文章转载自《C# EnumWindows示例代码》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇基于SpringBoot 的CMS系统简学LINGO(三)——实例篇下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

小米路由器3-R3 刷固件

3-3、大功告成,实测:带机12台,内存占用100MB、CPU使用20%不到满载200M带宽。...

Element plus的tree组件实现单选和搜索功能

--elementplus树组件实现单选及搜索功能--˃Elementplus树组件实现单选及搜索功能获取选中的节点//给节点添加classconstcustomNodeClass==˃{if{return'no-checkbox-node';}returnnull;};exportdefault{name:'tree-radio',data(){retur...

数据可视化之powerBI技巧(十四)采悟:PowerBI中自制中文单位万和亿

最令人不快的事情之一是数据单元的设置。现在让我们看看如何通过设置测量值来切换单位。需要动态选择1万元和1亿元的单位进行显示。首先,手动创建单位表,然后使用单位表中的[unit]字段生成切片器。下一步是建立销售衡量标准。销售额=总和('订单'[销售额])为了按过滤单位显示销售额,SELECTEDVALUE函数可以根据切片器选择动态更改分母。如果切片器未进行任何...

开源项目推荐:Qt有关的GitHub/Gitee开源项目

https://www.froglogic.com/windeployqthttps://doc.qt.io/Qt-5/windows部署。htmlhttps://wiki.qt.io/Deploy_an_Application_on_Windowshttps://github.com/lucasg/Dependencieshttp://www.depend...

如何给LINUX红帽子版本配置IP(转)

如果需要绑定另一个IP地址,只需在文件名中添加一个,并在文件中的DEVICE中添加eth0:x。LINUX可以支持多达255个IP别名,多个网卡绑定到一个IP地址,并且可以使用多个网卡创建具有相同IP地址的虚拟网卡。事实上,这种技术已经存在于Sun和Cisco中,它们分别被称为中继和以太网信道技术。在Linux中,这种技术被称为绑定。...

Corn表达式

CronTriggerCronTrigger通常比SimpleTrigger更有用。如果您需要基于日历的概念,而不是SimpleTrigger完全指定的时间间隔,则重复启动工作的时间表。CronTrigger,您可以指定触发器计划,例如“每周五中午”、“每工作日9:30”,甚至“每周一上午、周三和周五9:00和10:00每五分钟”。即使如此,就像Simple...