mycust.java

来自「自己建立的项目」· Java 代码 · 共 40 行

JAVA
40
字号
package com.swtSample.customControl;

import org.eclipse.swt.SWT;
import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.internal.win32.TCHAR;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MyCust {
	public static void main(String [] args){
     Display display = new Display(); 
     Shell shell = new Shell(display , SWT.NULL); 
     shell.setMaximized(false); 
     shell.setBackground(display.getSystemColor(SWT.COLOR_BLACK)); 
     shell.setText("Example"); 
     shell.setBounds(0 , 700 , 1024 , 68); 
     
     //始终最前
     OS.SetWindowPos(shell.handle , OS.HWND_TOPMOST, 0 , 700 , 1024 , 68 , SWT.NULL); 

     //透明窗体
     OS.SetWindowLong(shell.handle , OS.GWL_EXSTYLE , OS.GetWindowLong(shell.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 [i] = (byte) name.charAt(i); 
         }
         int fun = OS.GetProcAddress(hInst , lpProcName); 
         if(fun != 0){
             OS.CallWindowProc(fun , shell.handle , 0,50,1); 
         }
         OS.FreeLibrary(hInst); 
     }
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?