aboutsummaryrefslogtreecommitdiff
path: root/src/mingwMain/kotlin/moe/yuuta/aero/Aero.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/mingwMain/kotlin/moe/yuuta/aero/Aero.kt')
-rw-r--r--src/mingwMain/kotlin/moe/yuuta/aero/Aero.kt73
1 files changed, 20 insertions, 53 deletions
diff --git a/src/mingwMain/kotlin/moe/yuuta/aero/Aero.kt b/src/mingwMain/kotlin/moe/yuuta/aero/Aero.kt
index 44c184e..e9f47b4 100644
--- a/src/mingwMain/kotlin/moe/yuuta/aero/Aero.kt
+++ b/src/mingwMain/kotlin/moe/yuuta/aero/Aero.kt
@@ -29,38 +29,23 @@ fun main() {
null
)
- val forceDialogEnv = WinApi.getenv("AERO_DEMO_FORCE_DIALOG")
+ if (hwnd == null) {
+ MessageBoxA(null,
+ "The system returns an empty dialog (${GetLastError()})",
+ "Aero",
+ (MB_OK or MB_ICONERROR).convert())
+ return
+ }
- if (hwnd == null || (forceDialogEnv == "true")) {
- if (hwnd == null) {
- MessageBoxA(null,
- "The system returns an empty dialog (${GetLastError()})",
- "Aero",
- (MB_OK or MB_ICONERROR).convert())
- }
- memScoped {
- // Fallback
- val dlgImpl = cValue<DLGTEMPLATE> {
- style = (WS_OVERLAPPEDWINDOW or
- DS_CENTER or
- DS_MODALFRAME).convert()
- dwExtendedStyle = 0.convert()
- cdit = 0.convert()
- x = 0
- y = 0
- cx = 400
- cy = 200
- }
- return@memScoped DialogBoxIndirectParamW(WinCompat.hInstance,
- dlgImpl.ptr,
- null,
- staticCFunction(::dlgProc),
- 0)
- }
- } else {
- ShowWindow(hwnd, WinCompat.nCmdShow)
- WinApi.msgLoop()
+ val result = DwmEnableComposition(DWM_EC_ENABLECOMPOSITION) and 0xFFFF
+ if (result != 0) {
+ MessageBoxA(hwnd,
+ "DwmEnableComposition() fail (0x${result.toString(16)})",
+ "Aero",
+ (MB_OK or MB_ICONERROR).convert())
}
+ ShowWindow(hwnd, WinCompat.nCmdShow)
+ WinApi.msgLoop()
}
fun windowProc(hwnd: HWND?,
@@ -69,13 +54,17 @@ fun windowProc(hwnd: HWND?,
lParam: LPARAM): LRESULT {
return when (uMsg.convert<Int>()) {
WM_CREATE -> {
- WinApi.setAero(hwnd)
+ WinApi.setAero10(hwnd)
1
}
WM_DESTROY -> {
PostQuitMessage(0)
1
}
+ WM_ACTIVATE -> {
+ WinApi.setAero7(hwnd)
+ 1
+ }
WM_PAINT -> {
val ps = nativeHeap.alloc<PAINTSTRUCT>()
val hdc = BeginPaint(hwnd, ps.ptr)
@@ -90,26 +79,4 @@ fun windowProc(hwnd: HWND?,
DefWindowProcA(hwnd, uMsg, wParam, lParam)
}
}
-}
-
-fun dlgProc(hDlg: HWND?,
- message: UINT,
- wParam: WPARAM,
- lParam: LPARAM): INT_PTR {
- when (message.convert<Int>()) {
- WM_INITDIALOG -> {
- WinApi.setAero(hDlg)
- return true.toByte().toLong()
- }
- WM_COMMAND -> {
- EndDialog(hDlg, wParam.convert())
- return true.toByte().toLong()
- }
- WM_CTLCOLORDLG -> {
- return GetStockObject(BLACK_BRUSH).rawValue.toLong()
- }
- else -> {
- return false.toByte().toLong()
- }
- }
} \ No newline at end of file