-
-
Notifications
You must be signed in to change notification settings - Fork 280
/
Copy pathWinWrapper.cpp
98 lines (81 loc) · 3.17 KB
/
WinWrapper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Copyright 2022 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// avoid inlining of printf()
#define _NO_CRT_STDIO_INLINE
#include <windows.h>
#include <dwmapi.h>
#include "com_formdev_flatlaf_ui_FlatNativeWindowsLibrary.h"
/**
* @author Karl Tauber
*/
// see FlatWndProc.cpp
HWND getWindowHandle( JNIEnv* env, jobject window );
//---- Utility ----------------------------------------------------------------
typedef LONG (WINAPI *RtlGetVersion_Type)( OSVERSIONINFO* );
extern "C"
JNIEXPORT jlong JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_getOSBuildNumberImpl
( JNIEnv* env, jclass cls )
{
OSVERSIONINFO info;
info.dwOSVersionInfoSize = sizeof( info );
info.dwBuildNumber = 0;
// use RtlGetVersion for the case that app manifest does not specify Windows 10+ compatibility
// https://www.codeproject.com/Articles/5336372/Windows-Version-Detection
HMODULE ntdllModule = ::GetModuleHandleA( "ntdll.dll" );
if( ntdllModule != NULL ) {
RtlGetVersion_Type pRtlGetVersion = (RtlGetVersion_Type) ::GetProcAddress( ntdllModule, "RtlGetVersion" );
if( pRtlGetVersion != NULL && pRtlGetVersion( &info ) == 0 )
return info.dwBuildNumber;
}
// fallback
if( !::GetVersionEx( &info ) )
return 0;
return info.dwBuildNumber;
}
extern "C"
JNIEXPORT jlong JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_getHWND
( JNIEnv* env, jclass cls, jobject window )
{
return reinterpret_cast<jlong>( getWindowHandle( env, window ) );
}
//---- Desktop Window Manager (DWM) -------------------------------------------
extern "C"
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_setWindowCornerPreference
( JNIEnv* env, jclass cls, jlong hwnd, jint cornerPreference )
{
if( hwnd == 0 )
return FALSE;
DWM_WINDOW_CORNER_PREFERENCE attr = (DWM_WINDOW_CORNER_PREFERENCE) cornerPreference;
return ::DwmSetWindowAttribute( reinterpret_cast<HWND>( hwnd ), DWMWA_WINDOW_CORNER_PREFERENCE, &attr, sizeof( attr ) ) == S_OK;
}
extern "C"
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_dwmSetWindowAttributeBOOL
( JNIEnv* env, jclass cls, jlong hwnd, jint attribute, jboolean value )
{
if( hwnd == 0 )
return FALSE;
BOOL attr = value;
return ::DwmSetWindowAttribute( reinterpret_cast<HWND>( hwnd ), attribute, &attr, sizeof( attr ) ) == S_OK;
}
extern "C"
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_dwmSetWindowAttributeDWORD
( JNIEnv* env, jclass cls, jlong hwnd, jint attribute, jint value )
{
if( hwnd == 0 )
return FALSE;
DWORD attr = value;
return ::DwmSetWindowAttribute( reinterpret_cast<HWND>( hwnd ), attribute, &attr, sizeof( attr ) ) == S_OK;
}