When WS_SIZEBOX is set, even if WS_CAPTION is canceled, the title bar will still be displayed and then disappear

354 Views Asked by At

When the WS_SIZEBOX (same as WS_THICKFRAME) style is set for the window and WS_CAPTION is not set, the title bar will appear on the window, and the title bar will disappear after a title bar event is triggered, leaving a white bar.

Here is the demo video: https://videos.ximinghui.org/230223_demo_video.mp4

My Codes:

import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinUser;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Background;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

import static com.sun.jna.platform.win32.WinUser.*;

class Main {

    public static void main(String[] args) {
        Application.launch(MyApp.class);
    }

}

public class MyApp extends Application {
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Clover GUI");
        Pane pane = new Pane();
        pane.setBackground(Background.fill(Color.rgb(30, 31, 34)));
        primaryStage.setScene(new Scene(pane));
        primaryStage.show();

        HWND hwnd = JNA.getHWND();
        int oldStyle = User32.INSTANCE.GetWindowLongPtr(hwnd, GWL_STYLE).intValue();
        // Method 1 (same as Method 2)
        //User32.INSTANCE.SetWindowLongPtr(hwnd, WinUser.GWL_STYLE, new Pointer(WS_TILED|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SIZEBOX|WS_VISIBLE));
        // Method 2 (same as Method 1)
        User32.INSTANCE.SetWindowLongPtr(hwnd, WinUser.GWL_STYLE, new Pointer(oldStyle ^ WS_CAPTION));

        // User32.INSTANCE.SetWindowPos(hwnd, new HWND(new Pointer(0)),100,100,600,800,SWP_DRAWFRAME);
    }
}

reference:


Update:

After I added the following code to call SetWindowPos, the title bar disappeared. According to microsoft documentation I need to call this function to apply the style of SetWindowLong function.

// @see: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos
int uFlags =
    // Applies new frame styles set using the SetWindowLong function. Sends a WM_NCCALCSIZE message to the window, even if the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the window's size is being changed.
    SWP_FRAMECHANGED |
    // Retains the current position (ignores X and Y parameters).
    SWP_NOMOVE |
    // Retains the current size (ignores the cx and cy parameters).
    SWP_NOSIZE |
    // Does not change the owner window's position in the Z order.
    SWP_NOREPOSITION |
    // Retains the current Z order (ignores the hWndInsertAfter parameter).
    SWP_NOZORDER;

User32.INSTANCE.SetWindowPos(hwnd, null, 0, 0, 0, 0, uFlags);

The white bar is still there, and the top border of the window looks thick (because the window height can be changed when the mouse is hovered over it).

reference:


Update:

The 6px white bar at the top of the window is linked to winapi - Create window without titlebar, with resizable border and without bogus 6px white stripe - Stack Overflow

0

There are 0 best solutions below