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?
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.
精彩评论