5 messages in net.java.dev.jna.usersRe: [jna-users] Create a Window and s...
FromSent OnAttachments
Ulisses CarvalhoJul 10, 2008 10:42 pm 
Timothy WallJul 10, 2008 11:20 pm 
Ulisses CarvalhoJul 11, 2008 9:45 am 
Daniel KaufmannJul 11, 2008 3:39 pm 
Ulisses CarvalhoJul 11, 2008 6:03 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Create a Window and set lpfnWndProcActions...
From:Daniel Kaufmann (dani@gmail.com)
Date:Jul 11, 2008 3:39:33 pm
List:net.java.dev.jna.users

I think the first error (87) is caused by you not setting the size of the
structure you are passing: //wc.cbSize= wc.size(); //size of the structure Most of the Windows API function that get a structure and have a size field
expect this to be filled when you call them with the size of the structure.

Then the second error would be because the RegisterClassEx failed. There is an example on how to use RegisterClassEx here:
http://msdn.microsoft.com/en-us/library/ms633575(VS.85).aspx

Anyway, generally if you just want to set the WindowProc of a particular class
you would use window subclassing, and you can do it for any window you have,
even if it was created by java. You can see an example for VB here
http://www.geocities.com/SiliconValley/Lab/1632/atch12.html, and here some
document from microsoft with C code and more comprehensive explanation:
http://msdn.microsoft.com/en-us/library/ms997565.aspx.

Thanks, Daniel ----- Original Message -----

From: Ulisses Carvalho To: use@jna.dev.java.net Sent: Friday, July 11, 2008 1:46 PM Subject: Re: [jna-users] Create a Window and set lpfnWndProc

Timothy,

First the errors messages: 87 - ERROR_INVALID_PARAMETER - The parameter is incorrect.
(http://msdn.microsoft.com/en-us/library/ms681382(VS.85).aspx) 1407 - ERROR_CANNOT_FIND_WND_CLASS - Cannot find window class.
(http://msdn.microsoft.com/en-us/library/ms681385(VS.85).aspx)

I need create a window using User32 only to set the lpfnWndProc, because i
pass the window handle to another function (function A) and this function
sending events using WindowProc function (see more about:
http://msdn.microsoft.com/en-us/library/ms633573.aspx). I try use Hook
WH_CALLWNDPROC, but i receive the event without the particular information of
structure sent by function A. Do you khow other way to capture the event sent by
function A?

For more information... the function A receive the window handle which is to
receive the completion message for the request.

References:

RegisterClassEx Function -
http://msdn.microsoft.com/en-us/library/ms633587(VS.85).aspx CreateWindowEx Function -
http://msdn.microsoft.com/en-us/library/ms632680(VS.85).aspx RegisterClass Function -
http://msdn.microsoft.com/en-us/library/ms633586(VS.85).aspx CreateWindow Function -
http://msdn.microsoft.com/en-us/library/ms632679(VS.85).aspx

On Fri, Jul 11, 2008 at 3:21 AM, Timothy Wall <twal@dev.java.net> wrote:

On Jul 11, 2008, at 1:42 AM, Ulisses Carvalho wrote:

Hi,

I try create a window using user32 native, because i need set lpfnWndProc
property (Do you know other way to do this?)

You can use Native.getWindowHandle() to obtain the HWND for a Java window.

see my source code below:

============================================================================================= public static void main(String[] args) { User32.WNDPROC WndProc = new User32.WNDPROC() {

public LRESULT callback(HWND hWnd, int uMsg, WPARAM wParam, LPARAM
lParam) { System.out.println("===================================="); System.out.println(hWnd); System.out.println(uMsg); System.out.println(wParam); System.out.println(lParam); int id = User32.INSTANCE.GetWindowThreadProcessId(hWnd, null); System.out.println("ThreadID = " + id); System.out.println("====================================");

//return User32.INSTANCE.CallNextHookEx(hhk, uMsg, wParam,
lParam); return new LRESULT(0); } };

HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null);

User32.WNDCLASSEX wc = new User32.WNDCLASSEX(); wc.style = 0; // style wc.lpfnWndProc = WndProc; // the window procedure callback mechanism wc.cbClsExtra = 0; // Extra bytpe allocation (not required) wc.cbWndExtra = 0; // Extra bytpe allocation (not required) wc.hInstance = null; //link this window with the application instance wc.hIcon = null; // icon to use for the window // wc.hIconSm = null; //Set small icon //wc.hCursor = User32.INSTANCE.LoadCursor(hMod, null); //choose the
cursor for the window wc.hbrBackground = null; // Choose background colour //wc.cbSize= wc.size(); //size of the structure wc.lpszMenuName = null; // Not using wc.lpszClassName = "IDC"; // Name of the class

Atom atom = User32.INSTANCE.RegisterClassEx(wc);

System.out.println("Atom ->"+atom); System.out.println("GetLastError 1
->"+Kernel32.INSTANCE.GetLastError());

HWND hwnd = User32.INSTANCE.CreateWindowEx(User32.WS_EX_TRANSPARENT, wc.lpszClassName, hMod.getPointer(), //null, //User32.WS_EX_TRANSPARENT, User32.WS_EX_LAYERED, 0, 0, 0, 0, (HWND)null, null, null, null);

System.out.println("HWND ->"+hwnd);

System.out.println("GetLastError 1
->"+Kernel32.INSTANCE.GetLastError()); } ==============================================================================

I include this code in com.sun.jna.examples.win32.User32.java:

============================================================================== class WNDCLASSEX extends Structure { public int cbSize; public int style; public WNDPROC lpfnWndProc; public int cbClsExtra; public int cbWndExtra; public HINSTANCE hInstance; public HICON hIcon; public HCURSOR hCursor; public HBRUSH hbrBackground; public String lpszMenuName; public String lpszClassName; public HICON hIconSm; }

Atom RegisterClass(WNDCLASS wndclass);

class WNDCLASS extends Structure { public int style; public WNDPROC lpfnWndProc; public int cbClsExtra; public int cbWndExtra; public HINSTANCE hInstance; public HICON hIcon; public HCURSOR hCursor; public HBRUSH hbrBackground; public String lpszMenuName; public String lpszClassName; }

Atom RegisterClassEx(WNDCLASSEX wndclass);

HWND CreateWindowEx( int dwExStyle, String lpClassName, Pointer lpWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, Pointer lpParam );

class HBRUSH extends HANDLE {

}

class HCURSOR extends HANDLE {

}

interface WNDPROC extends StdCallCallback { LRESULT callback(HWND hWnd, int uMsg, WPARAM uParam, LPARAM lParam); }

class HMENU extends HANDLE {

}

HWND CreateWindow( String lpClassName, String lpWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, Pointer lpParam );

HCURSOR LoadCursor( HINSTANCE hInstance, String lpCursorName ); ==============================================================================

When i executing this class, the program print this:

============================================================================== Atom ->0x7ffd0000 GetLastError 1 ->87 HWND ->null GetLastError 1 ->1407 ==============================================================================

What is wrong?

What does the windows API tell you about that situation? What do the errors
87 and 1407 mean?

--------------------------------------------------------------------- To unsubscribe, e-mail: user@jna.dev.java.net For additional commands, e-mail: user@jna.dev.java.net