Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to call GetClientRect(HWND, tagRECT*) from java

843829Dec 24 2008 — edited Dec 27 2008
hi,
public class DLLWrapper
{
   private static class RECT
   {
      public int left;
      public int top;
      public int right;
      public int bottom;
   }

   public native boolean getClientRect(int hWnd, RECT rect);

   public static void main(String args[]) // lets assume that args[1] is int pointer to parent window (say, in the screensaver's preview mode)
   {
      RECT rect = new RECT();

      if(new DLLWrapper().getClientRect(Integer.parseInt(args[1]), rect))
      {
         // blah....
      }
   }
}
i compiled the above and generated DLLWrapper.h. then i added this to Win32DLLWrapper.h in my mfc appwizard (dll) project:
JNIEXPORT jboolean JNICALL Java_dll_DLLWrapper_getClientRect(JNIEnv *env, jobject obj1, jint hWnd, jobject obj2)
{
	return GetClientRect((HWND) hWnd, (tagRECT*) obj2); //=======================> correct???
}
i then copied Win32DLLWrapper.dll to \system32 and i was able to run but didn't have a valid hwnd, which is fine
since i'm interested in the correctness of the code.

1. is everything correct thus far (can't test it with a valid hwnd)???
2. how do you translate the following c# code into java: Graphics g = Graphics.FromHwnd(hwnd);???

for question 2, do i add GetDC() in Win32DLLWrapper.h? the return type of GetDC() is HDC, can this be somehow converted into a java Graphics object???
please provide an example.

thank you very much!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 24 2009
Added on Dec 24 2008
2 comments
289 views