呵呵,好长时间不来回帖了,你可以试着运行以下代码,就可以看到半透明的窗体了 :)
import org.eclipse.swt.SWT;
import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.internal.win32.TCHAR;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Test extends Shell {
public static void main(String args[]) {
try {
Display display = Display.getDefault();
Test shell = new Test(display, SWT.SHELL_TRIM);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public Test(Display display, int style) {
super(display, style);
createContents();
}
protected void createContents() {
setText("SWT Application");
setSize(500, 375);
setLayout(new GridLayout());
OS.SetWindowLong(this.handle, OS.GWL_EXSTYLE, OS.GetWindowLong(
this.handle, OS.GWL_EXSTYLE) ^ 0x80000);
TCHAR lpLibFileName = new TCHAR(0, "User32.dll", true);
int hInst = OS.LoadLibrary(lpLibFileName);
if (hInst != 0) {
String name = "SetLayeredWindowAttributes\0";
byte[] lpProcName = new byte[name.length()];
for (int i = 0; i < lpProcName.length; i++) {
lpProcName = (byte) name.charAt(i);
}
final int fun = OS.GetProcAddress(hInst, lpProcName);
if (fun != 0) {
OS.CallWindowProc(fun, this.handle, 0, 150, 2);
}
OS.FreeLibrary(hInst);
}
}
protected void checkSubclass() {
}
}