Skip to content

Commit 6c52731

Browse files
rednoahmatthiasblaesing
authored andcommitted
Shell32.SetCurrentProcessExplicitAppUserModelID (#680)
Added SetCurrentProcessExplicitAppUserModelID and GetCurrentProcessExplicitAppUserModelID functions to Shell32 wrapper
1 parent b961e5a commit 6c52731

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Features
5555
* [#654](https://github.com/java-native-access/jna/pull/654): Support named arguments for `com.sun.jna.platform.win32.COM.util.CallbackProxy` based callbacks - [@matthiasblaesing](https://github.com/matthiasblaesing).
5656
* [#659](https://github.com/java-native-access/jna/issues/659): Enable LCID (locale) override for `com.sun.jna.platform.win32.COM.util.ProxyObject`-based COM calls - [@matthiasblaesing](https://github.com/matthiasblaesing).
5757
* [#665](https://github.com/java-native-access/jna/pull/665): Added `XSetWMProtocols` and `XGetWMProtocols` to `com.sun.jna.platform.unix.X11` - [@zainab-ali](https://github.com/zainab-ali).
58+
* [#680](https://github.com/java-native-access/jna/pull/680): Added `SetCurrentProcessExplicitAppUserModelID` and `GetCurrentProcessExplicitAppUserModelID` to `com.sun.jna.platform.win32.Shell32` for setting the [System.AppUserModel.ID](https://msdn.microsoft.com/en-us/library/windows/desktop/dd391569.aspx) of the host process - [@rednoah](https://github.com/rednoah).
5859

5960
Bug Fixes
6061
---------

contrib/platform/src/com/sun/jna/platform/win32/Shell32.java

+22
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package com.sun.jna.platform.win32;
1414

1515
import com.sun.jna.Native;
16+
import com.sun.jna.WString;
1617
import com.sun.jna.platform.win32.Guid.GUID;
1718
import com.sun.jna.platform.win32.WinDef.DWORD;
1819
import com.sun.jna.platform.win32.WinDef.HICON;
@@ -376,5 +377,26 @@ public interface Shell32 extends ShellAPI, StdCallLibrary {
376377
* @see <a href="https://msdn.microsoft.com/en-us/library/ms648069(VS.85).aspx">MSDN</a>
377378
*/
378379
int ExtractIconEx(String lpszFile, int nIconIndex, HICON[] phiconLarge, HICON[] phiconSmall, int nIcons);
380+
381+
/**
382+
* Retrieves the application-defined, explicit Application User Model ID (AppUserModelID) for the current process.
383+
*
384+
* @param ppszAppID
385+
* A pointer that receives the address of the AppUserModelID assigned to the process. The caller is responsible for freeing this string with {@link Ole32#CoTaskMemFree} when it is no longer needed.
386+
* @return If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
387+
* @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd378419(v=vs.85).aspx">MSDN</a>
388+
*/
389+
HRESULT GetCurrentProcessExplicitAppUserModelID(PointerByReference ppszAppID);
390+
391+
/**
392+
* Specifies a unique application-defined Application User Model ID (AppUserModelID) that identifies the current process to the taskbar. This identifier allows an application to group its associated processes and windows under a single taskbar button.
393+
*
394+
* @param appID
395+
* The AppUserModelID to assign to the current process.
396+
* @return If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
397+
* @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd378422(v=vs.85).aspx">MSDN</a>
398+
*/
399+
HRESULT SetCurrentProcessExplicitAppUserModelID(WString appID);
400+
379401
}
380402

contrib/platform/test/com/sun/jna/platform/win32/Shell32Test.java

+17
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.io.IOException;
1818

1919
import com.sun.jna.Native;
20+
import com.sun.jna.WString;
2021
import com.sun.jna.platform.win32.Guid.GUID;
2122
import com.sun.jna.platform.win32.ShellAPI.APPBARDATA;
2223
import com.sun.jna.platform.win32.ShellAPI.SHELLEXECUTEINFO;
@@ -232,4 +233,20 @@ public void testExtractIconEx() {
232233
int iconCount = Shell32.INSTANCE.ExtractIconEx(new File(winDir, "explorer.exe").getAbsolutePath(), -1, null, null, 1);
233234
assertTrue("Should be at least two icons in explorer.exe", iconCount > 1);
234235
}
236+
237+
public void testCurrentProcessExplicitAppUserModelID() {
238+
String appUserModelID = "com.sun.jna.platform.win32.Shell32Test";
239+
240+
HRESULT r1 = Shell32.INSTANCE.SetCurrentProcessExplicitAppUserModelID(new WString(appUserModelID));
241+
assertEquals(WinError.S_OK, r1);
242+
243+
PointerByReference ppszAppID = new PointerByReference();
244+
HRESULT r2 = Shell32.INSTANCE.GetCurrentProcessExplicitAppUserModelID(ppszAppID);
245+
assertEquals(WinError.S_OK, r2);
246+
247+
assertEquals(appUserModelID, ppszAppID.getValue().getWideString(0));
248+
249+
Ole32.INSTANCE.CoTaskMemFree(ppszAppID.getValue());
250+
}
251+
235252
}

0 commit comments

Comments
 (0)