Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] Image Capture

I'm using the following code to capture the image of a Text control. When using the Windows XP theme (need have javaw.exe.manifets in the JRE bin directory) I get the wrong border being captured, the captured image displays with the old Windows 200 style border, does anyone know why?


// Imports Removed

   static final int WM_PRINT = 0x0317;
   static final int PRF_CLIENT = 0x00000004;
   static final int PRF_ERASEBKGND = 0x00000008;
   static final int PRF_NONCLIENT = 0x00000002;
   static final int PRF_OWNED = 0x00000020;

   public static void main(String[] args) {
       Display display = new Display();
       Shell shell = new Shell(display);
       GridLayout layout = new GridLayout(1, true);
       layout.verticalSpacing = 8;
       shell.setLayout(layout);

       Text text = new Text(shell, SWT.BORDER);
       text.setText("Hello World");
       text.setSize(300, 24);
       Label label = new Label(shell, SWT.NONE);
       label.setSize(300, 24);

       shell.pack();
       shell.open();

       Image image = captureImage(text);
       label.setImage(image);
       shell.pack();

       while (!shell.isDisposed()) {
           if (!display.readAndDispatch()) display.sleep();
       }

       image.dispose();
       display.dispose();
   }

   static public Image captureImage(Control control) {
       Point size = control.getSize();
       Image image = new Image(control.getDisplay(), size.x, size.y);
       GC gc = new GC(image);
       gc.setClipping(-1, -1, size.x, size.y);
       int hWnd = control.handle;
       int wParam = gc.handle;
       int lParam = PRF_NONCLIENT | PRF_CLIENT | PRF_ERASEBKGND;
       OS.SendMessage(hWnd, WM_PRINT, wParam, lParam);
       gc.dispose();
       return image;
   }

_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail



Back to the top