From 9a9406dc7edd53e215d98b048fb3314fef57a1ec Mon Sep 17 00:00:00 2001 From: Brian Matzon Date: Sat, 8 Feb 2003 23:01:58 +0000 Subject: [PATCH] add: close button enabled --- src/java/org/lwjgl/Display.java | 6 ++++-- src/native/common/org_lwjgl_Display.h | 2 +- src/native/win32/org_lwjgl_Display.cpp | 17 +++++++++++++---- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/java/org/lwjgl/Display.java b/src/java/org/lwjgl/Display.java index fd7c5ec5..1fd8d936 100644 --- a/src/java/org/lwjgl/Display.java +++ b/src/java/org/lwjgl/Display.java @@ -57,6 +57,9 @@ public final class Display { /** A pointer to the native display window. On Windows this will be an hWnd. */ private static int handle; + + /** Whether or not the display has been requested to shutdown by the user */ + public static boolean closeRequested = false; /** * No construction allowed. @@ -214,5 +217,4 @@ public final class Display { * @return true if the display is minimized */ public static native boolean isMinimized(); - -} +} \ No newline at end of file diff --git a/src/native/common/org_lwjgl_Display.h b/src/native/common/org_lwjgl_Display.h index 7c025277..bc601b33 100644 --- a/src/native/common/org_lwjgl_Display.h +++ b/src/native/common/org_lwjgl_Display.h @@ -11,6 +11,7 @@ extern "C" { /* Inaccessible static: created */ /* Inaccessible static: mode */ /* Inaccessible static: handle */ +/* Inaccessible static: closeRequested */ /* Inaccessible static: class_000240 */ /* * Class: org_lwjgl_Display @@ -44,7 +45,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_nDestroy JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_isMinimized (JNIEnv *, jclass); - #ifdef __cplusplus } #endif diff --git a/src/native/win32/org_lwjgl_Display.cpp b/src/native/win32/org_lwjgl_Display.cpp index 3a5820c7..225f918b 100644 --- a/src/native/win32/org_lwjgl_Display.cpp +++ b/src/native/win32/org_lwjgl_Display.cpp @@ -59,6 +59,9 @@ HDC hdc = NULL; // Device context LPDIRECTINPUT lpdi = NULL; bool isMinimized = false; bool isFullscreen = false; +JNIEnv* environment; +jclass clsDisplay; +jfieldID fidclose; void destroyDI(void) { @@ -148,6 +151,12 @@ LRESULT CALLBACK WindowProc(HWND hWnd, case SC_RESTORE: isMinimized = false; appActivate(false); + break; + case SC_CLOSE: + environment->SetStaticBooleanField(clsDisplay, fidclose, true); + //don't continue processing this command since this + //would shutdown the window, which the application might not want to + return 0L; default: break; } @@ -276,6 +285,10 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate (JNIEnv * env, jclass clazz, jint width, jint height, jint bpp, jint freq, jint alphaBits, jint depthBits, jint stencilBits, jboolean fullscreen, jstring title) { + environment = env; + clsDisplay = clazz; + fidclose = env->GetStaticFieldID(clsDisplay, "closeRequested", "Z"); + #ifdef _DEBUG printf("Creating display: size %dx%d %dhz %dbpp...\n", width, height, freq, bpp); #endif @@ -352,10 +365,6 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate NULL); env->ReleaseStringUTFChars(title, titleString); - // Disable close button - HMENU SysMen = GetSystemMenu(hwnd, false); - EnableMenuItem(SysMen, SC_CLOSE, MF_BYCOMMAND | MF_DISABLED); - // And we never look at windowClass again... ShowWindow(hwnd, SW_SHOWNORMAL);