C#:另一个应用程序捕获的WindowState变化(C / C ++写的,我认为) [英] C#: capture windowstate changes of another application (wrote in c/c++ i think)
本文介绍了C#:另一个应用程序捕获的WindowState变化(C / C ++写的,我认为)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个情况我需要捕捉的WindowState另一个窗口的变化(这是不是我的应用程序拥有的,我没有写的。我认为这是写在C ++)。
其实我使用一个单独的线程在那里我不断做GetWindowState和火灾自定义事件时,该值发生变化(我有窗口的句柄),但我想知道是否有更好的方法
谢谢,
PS
我使用的winform如果能以任何方式有用
解决方案
在一个定时器//使用这个或钩窗口
//这将是使用系统更简单的方法
;使用System.Runtime.InteropServices
;
公共静态类的WindowState
{
函数[DllImport(USER32)]
私人静态外部INT IsWindowEnabled(INT的hWnd);
函数[DllImport(USER32)]
私人静态外部INT IsWindowVisible(INT的hWnd);
函数[DllImport(USER32)]
私人静态外部INT IsZoomed(INT的hWnd);
函数[DllImport(USER32)]
私人静态外部INT IsIconic(INT的hWnd);
公共静态布尔IsMaximized(INT的hWnd)
{
如果(IsZoomed(HWND)== 0)
返回FALSE;
,否则
返回真;
}
公共静态布尔IsMinimized(INT的hWnd)
{
如果(IsIconic(HWND)== 0)
返回FALSE;
,否则
返回真;
}
公共静态布尔IsEnabled(INT的hWnd)
{
如果(IsWindowEnabled(HWND)== 0)
返回FALSE;
,否则
返回真;
}
公共静态布尔可见性(INT的hWnd)
{
如果(IsWindowVisible(HWND)== 0)
返回FALSE;
,否则
返回真;
}
}
I have a situation where I need to capture windowstate changes of another window (which is not owned by my application and I didn't wrote it. I think it's written in C++).
Actually I'm using a separate thread where I constantly do GetWindowState and fire custom events when this value changes (I have the handle of the window), but I would like to know if there is a better method
Thanks,
P.S. I'm using winform if can be useful in any way
解决方案
//use this in a timer or hook the window
//this would be the easier way
using System;
using System.Runtime.InteropServices;
public static class WindowState
{
[DllImport("user32")]
private static extern int IsWindowEnabled(int hWnd);
[DllImport("user32")]
private static extern int IsWindowVisible(int hWnd);
[DllImport("user32")]
private static extern int IsZoomed(int hWnd);
[DllImport("user32")]
private static extern int IsIconic(int hWnd);
public static bool IsMaximized(int hWnd)
{
if (IsZoomed(hWnd) == 0)
return false;
else
return true;
}
public static bool IsMinimized(int hWnd)
{
if (IsIconic(hWnd) == 0)
return false;
else
return true;
}
public static bool IsEnabled(int hWnd)
{
if (IsWindowEnabled(hWnd) == 0)
return false;
else
return true;
}
public static bool IsVisible(int hWnd)
{
if (IsWindowVisible(hWnd) == 0)
return false;
else
return true;
}
}
这篇关于C#:另一个应用程序捕获的WindowState变化(C / C ++写的,我认为)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文