Transparent Window (SetLayeredWindowAttributes) without frame and controls [message #461467] |
Sun, 25 September 2005 08:35 |
Joe Messages: 12 Registered: July 2009 |
Junior Member |
|
|
Hi!
I try to display a png-Image on a transparent shell (without frame).
The code below can display a transparent shell using
the (native) windows-method "SetLayeredWindowAttributes".
The problem is, that i want to remove the frame around the window.
Creating the shell with
Shell shell = new Shell(SWT.NO_TRIM)
effects that the background is no updated, when the shell is moved.
Someone has an idea how to get the the frame around the window removed,
without loosing the transparency effect?
____________________________________________________________ __
transparent shell with frame
____________________________________________________________ __
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class TransparentWindowTest {
Display display = null;
Shell shell = new Shell(SWT.CLOSE | SWT.MODELESS);
Label l = new Label(shell, SWT.NONE);
private RGB transparentRGB;
public TransparentWindowTest() {
this.display = shell.getDisplay();
System.load("C:\\WINDOWS\\system32\\OSEx.dll");
OS.SetWindowLong(shell.handle, OS.GWL_EXSTYLE, 0x80000);
transparentRGB = shell.getBackground().getRGB();
// args: windowHandle, rgb.red,rgg.green,rgb.blue, alpha ,dw flags
OSEx.SetLayeredWindowAttributes(this.shell.handle, transparentRGB.red,
transparentRGB.green, transparentRGB.blue, 255, 1);
l.setText("a transparent label");
l.setSize(100, 20);
this.shell.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
Image imgTest = new Image(Display.getDefault(), "test.png");
event.gc.drawImage(imgTest, 0, 0);
}
}
);
this.shell.setSize(256, 256);
this.shell.open();
this.shell.update();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new TransparentWindowTest();
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.03743 seconds