Bug 549713 (Part2) - [Win32][API]Query the current system setting for
dark mode

Change-Id: I1e77327958ecc1fe6ed20eac53143522441f4a46
Signed-off-by: Niraj Modi <niraj.modi@in.ibm.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
index 9391b57..8cdf2c1 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
@@ -2040,25 +2040,15 @@
 	if (OS.WIN32_VERSION >= OS.VERSION (10, 0)) {
 		TCHAR key = new TCHAR (0, "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", true); //$NON-NLS-1$
 		long [] phkResult = new long [1];
-		boolean regKeyFound = false;
 		if (OS.RegOpenKeyEx(OS.HKEY_CURRENT_USER, key, 0, OS.KEY_READ, phkResult) == 0) {
-			regKeyFound = true;
-		} else if (OS.RegOpenKeyEx(OS.HKEY_LOCAL_MACHINE, key, 0, OS.KEY_READ, phkResult) == 0) {
-			// Try reading from HKLM
-			regKeyFound = true;
-		}
-		if (regKeyFound) {
-			int [] lpcbData = new int [1];
-			TCHAR buffer = new TCHAR (0, "AppsUseLightTheme", true); //$NON-NLS-1$
-			int result = OS.RegQueryValueEx (phkResult [0], buffer, 0, new int[] {OS.REG_DWORD}, (TCHAR)null, lpcbData);
+			int[] lpcbData = new int[] { 4 };
+			TCHAR buffer = new TCHAR(0, "AppsUseLightTheme", true); //$NON-NLS-1$
+			int[] lpData = new int[1];
+			int result = OS.RegQueryValueEx(phkResult[0], buffer, 0, null, lpData, lpcbData);
 			if (result == 0) {
-				int[] lpData = new int[lpcbData[0] / TCHAR.sizeof];
-				result = OS.RegQueryValueEx(phkResult[0], buffer, 0, new int[] {OS.REG_DWORD}, lpData, lpcbData);
-				if (result == 0) {
-					isDarkTheme = (lpData[0] == 0);
-				}
+				isDarkTheme = (lpData[0] == 0);
 			}
-			OS.RegCloseKey (phkResult [0]);
+			OS.RegCloseKey(phkResult[0]);
 		}
 	}
 	return isDarkTheme;
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java
index ebc6f7c..b9cfd12 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -1507,4 +1507,10 @@
 		display.dispose();
 	}
 }
+
+@Test
+public void test_isSystemDarkTheme() {
+	System.out.println("org.eclipse.swt.widgets.Display.isSystemDarkTheme(): " + Display.isSystemDarkTheme());
+}
+
 }