java 调用window API 获取窗口句柄 并发消息 有人会吗 谢谢

java 调用window API 获取窗口句柄 并发消息 有人会吗 谢谢,第1张

使用JNI调用WIN32 API ,先得到窗口句柄,再得到窗口的RECT 先WindowFromPoint(point); 再GetWindowRect(hwnd, &rect); 返回的rect,就是窗口的left/top/width/height 这个不麻烦、也不复杂,很简单的JNI。

如果窗口是现有程序的,使用VS自带的spy++获取窗口的相关信息,然後使用WinAPI获取句柄,具体参考spy++的使用方法和winapi的使用

FindWindow(

lpClassName, {窗口的类名}

lpWindowName: PChar {窗口的标题}

): HWND; {返回窗口的句柄; 失败返回 0}

//FindWindowEx 比 FindWindow 多出两个句柄参数:

FindWindowEx(

Parent: HWND; {要查找子窗口的父窗口句柄}

Child: HWND; {子窗口句柄}

ClassName: PChar; {}

WindowName: PChar {}

): HWND;

如果窗口是你的程序动态生成的,使用如下语句

Form _FORM=new Form();

IntPtr _P = _FORMHandle;

_P就是你实例化的窗口句柄

这是一个vb用findwindow等api找到其它窗口,并且更改其它窗口的文本的源码:

>

应该可以用:

HWND GetForegroundWindow(void);

MSDN里的解释:

GetForegroundWindow

This function returns the handle to the foreground window—the window with which the user is currently working

HWND GetForegroundWindow(void);

Return Values

The handle to the foreground window indicates success

百度百科里的解释:

GetForegroundWindow

函数功能:该函数返回前台窗口(用户当前工作的窗口)。系统分配给产生前台窗口的线程一个稍高一点的优先级。

函数原型:HWND GetForegroundWindow(VOID)

参数:无。 返回值:函数返回前台窗回的句柄。

速查:Windows NT:31以上版本;Windows:95以上版本:Windows CE:10以上版本:头文件:Winuserh;库文件:user32lib。

using System;

using SystemRuntimeInteropServices;

using SystemText;

using SystemCollectionsGeneric;

class CSharpAPIsDemo

{

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

[DllImport("user32dll")]

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

//[DllImport("user32dll")]

//private static extern IntPtr FindWindowW(string lpClassName, string lpWindowName);

[DllImport("user32dll")]

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

[DllImport("user32dll")]

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

public struct WindowInfo

{

public IntPtr hWnd;

public string szWindowName;

public string szClassName;

}

public WindowInfo[] GetAllDesktopWindows()

{

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

//enum all desktop windows

EnumWindows(delegate(IntPtr hWnd, int lParam)

{

WindowInfo wnd = new WindowInfo();

StringBuilder sb = new StringBuilder(256);

//get hwnd

wndhWnd = hWnd;

//get window name

GetWindowTextW(hWnd, sb, sbCapacity);

wndszWindowName = sbToString();

//get window class

GetClassNameW(hWnd, sb, sbCapacity);

wndszClassName = sbToString();

//add it into list

wndListAdd(wnd);

return true;

}, 0);

return wndListToArray();

}

}

比较简单,如果有不明白可以消息我。

以上就是关于java 调用window API 获取窗口句柄 并发消息 有人会吗 谢谢全部的内容,包括:java 调用window API 获取窗口句柄 并发消息 有人会吗 谢谢、如何获取某个应用程序的窗体句柄、用VB或VB.NET用API函数FindWindow获取一个当前XX窗口句柄等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/9351583.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存