如何使用 JNA 创建 Microsoft Windows 子窗口

发布于 2024-09-29 17:59:10 字数 1420 浏览 3 评论 0原文

我花了一些时间尝试通过在 JNA(Java Native Access)上使用以下代码来创建现有窗口的子窗口,但我想这与尝试使用 Windows API 的所有其他编程语言几乎相同。

这是我的 CreateWindowsExA 声明:

public int CreateWindowExA(int i, String string, String string0, int i0, int i1, int i2, int i3, int i4, int ninja, Object object, Object object0, int i5);

这是我如何调用它:

int childLabel = user32.CreateWindowExA
(
   0, //sets style to default
   "STATIC", //window style is label
   "Show Message", //label text is show Message
   1342177280, // WS_CHILD + WS_VISIBLE  = &H40000000 + &H10000000
   10,         //x
   90,         //y
   100,        //width
   0,          //height 
   parentWindowHandler,   //a valid handler to a window (has been tested and is valid)
   null,    // a handler to a menu             
   null,  //A handle to the instance of the module to be associated with the window. (NO IDEA)
   0      //arguments list (no idea)
);

调用函数后,我得到按钮的有效处理程序... 但它是不可见的。对 getLastError 的调用以及对 TranslateMessage 的后续调用给出了“函数成功完成”。 另外,如果我调用 GetAncestor(childButton,3) 我会将句柄返回到parentWindowHandler。 我还可以调用 GetWindowTextA(childButton..bla) 并获取 显示消息 字符串。 所以,显然我已经创建了parentWindow 的一个子窗口并且它就在那里。然而,它是不可见的。接下来想到的是我的窗口/标签位于其父级 z-index 的底部,因此必须进行一些其他调用,我打算这样做。但如果我的方向错了,我只会浪费一点时间。

我该如何让这个孩子可见或者我做错了什么。 您应该注意,我不会在回调中调用它或发送任何消息。

有什么指点吗?

I have spent some time trying to create a child window of an existing window by using the following piece of code on JNA (Java Native Access) but I guess it is pretty much the same with every other programming language trying to use Windows API.

Here is my declaration of CreateWindowsExA :

public int CreateWindowExA(int i, String string, String string0, int i0, int i1, int i2, int i3, int i4, int ninja, Object object, Object object0, int i5);

And here is how I call it:

int childLabel = user32.CreateWindowExA
(
   0, //sets style to default
   "STATIC", //window style is label
   "Show Message", //label text is show Message
   1342177280, // WS_CHILD + WS_VISIBLE  = &H40000000 + &H10000000
   10,         //x
   90,         //y
   100,        //width
   0,          //height 
   parentWindowHandler,   //a valid handler to a window (has been tested and is valid)
   null,    // a handler to a menu             
   null,  //A handle to the instance of the module to be associated with the window. (NO IDEA)
   0      //arguments list (no idea)
);

After a call to the function I get a valid handler to the button...
But it is not visible. A call to getLastError and a subsequent call to TranslateMessage give me "The function completed successfully".
Also, if i call GetAncestor(childButton,3) I get my handle back to the parentWindowHandler.
I can also call GetWindowTextA(childButton..bla) and will obtain the Show Message string.
So, obviously I have created a child of the parentWindow and it is there. However, it is not visible. The next thing that comes in mind is that my window/label is in the bottom of the z-index of its parent, so some other calls have to be made and I intend to do so. But if I am at the wrong direction, I will just waste a bit of time.

How do i make this child visible or what am i doing wrong.
You should note that I do not call this in a callback or send any msg's.

Any pointers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那片花海 2024-10-06 17:59:10

是的,这就是我的想法,但略有不同。需要将 WM_PAINT 消息发送到父窗口以便刷新。

Yep, it was just what I thought, but slightly different. A WM_PAINT message needed to be sent to the parent window so it refreshes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文