我基本上试图在
Java SWT中重现这样的东西,但到目前为止还没有成功:
我看到的问题是,据我所知,SWT.TITLE需要显示SWT.CLOSE,SWT.MAX和SWT.MIN
任何人都可以通过设计单个shell或使用多个shell并访问close,min,max组件来告诉我是否有这样做的好方法?
最佳答案 在这个答案中,我认为定位Windows就足够了.如果您想要便携性,请立即停止阅读.
不幸的是,当您删除WS_CAPTION GWL_STYLE时,按钮也会丢失.我不能肯定地说,但我不认为这只是搞乱窗口样式.也许你可以使用AERO,但这限制了可以运行代码的操作系统.
如果你坚持这样做,我只能为你提供下一个最好的东西:放置你自己的按钮,但让它们看起来尽可能接近原生字幕按钮.
这是主题的外观:
这就是经典主题的样子:
仍然可以对齐按钮,在热/按下或最大化/恢复时更改状态,但这是一个起点.
我知道这不完全是你问的,但也许有帮助.
以下是创建窗口的代码:
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.internal.win32.RECT;
import org.eclipse.swt.widgets.*;
public class CaptionItemSnippet {
private static final char[] WINDOW_CLASS = className("WINDOW");
private static final int WP_MINBUTTON = 15;
private static final int WP_MAXBUTTON = 17;
private static final int WP_CLOSEBUTTON = 18;
private static final int DFC_CAPTION = 1;
private static final int DFCS_CAPTIONCLOSE = 0x0000;
private static final int DFCS_CAPTIONMIN = 0x0001;
private static final int DFCS_CAPTIONMAX = 0x0002;
private static final int DFCS_CAPTIONRESTORE = 0x0003;
private static final int DFCS_CAPTIONHELP = 0x0004;
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
int gwlStyle = OS.GetWindowLong(shell.handle, OS.GWL_STYLE);
//remove title bar
gwlStyle &= ~OS.WS_CAPTION;
// add maximize button: does not work
gwlStyle |= OS.WS_SYSMENU | OS.WS_MAXIMIZEBOX;
OS.SetWindowLong(shell.handle, OS.GWL_STYLE, gwlStyle & ~OS.WS_CAPTION);
final Button minimizeButton = createButton(shell, WP_MINBUTTON, DFCS_CAPTIONMIN);
minimizeButton.setBounds(125, 0, 20, 20);
final Button maxButton = createButton(shell, WP_MAXBUTTON, DFCS_CAPTIONMAX);
maxButton.setBounds(145, 0, 20, 20);
final Button closeButton = createButton(shell, WP_CLOSEBUTTON, DFCS_CAPTIONCLOSE);
closeButton.setBounds(165, 0, 20, 20);
shell.setSize(200, 200);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
private static Button createButton(final Composite parent, final int partId, final int uState) {
final Button button = new Button(parent, SWT.PUSH);
button.addListener(SWT.Paint, new Listener() {
@Override
public void handleEvent(Event e) {
final Point size = button.getSize();
final RECT rect = new RECT();
rect.left = 0;
rect.right = size.x;
rect.top = 0;
rect.bottom = size.y;
if (OS.IsAppThemed()) {
final int theme = OS.OpenThemeData(parent.handle, WINDOW_CLASS);
OS.DrawThemeBackground(theme, e.gc.handle, partId, OS.TS_NORMAL, rect, null);
OS.CloseThemeData(theme);
} else {
OS.DrawFrameControl(e.gc.handle, rect, DFC_CAPTION, uState);
}
}
});
return button;
}
private static char[] className(String s) {
final char[] chars = new char[s.length() + 1];
System.arraycopy(s.toCharArray(), 0, chars, 0, s.length());
chars[chars.length - 1] = 0;
return chars;
}
}