Skip to content

Commit a02763f

Browse files
committed
feat: Add shell32 and notifyicon support with new constants
1 parent 59eef64 commit a02763f

File tree

7 files changed

+100
-0
lines changed

7 files changed

+100
-0
lines changed

source/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export { koffi } from './private.js'
22
export * from './ctypes.js'
33
export * from './win32/kernel32.js'
44
export * from './win32/user32.js'
5+
export * from './win32/shell32.js'

source/win32/consts.ts

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export * from './consts/IDI.js'
1010
export * from './consts/IMAGE.js'
1111
export * from './consts/LR.js'
1212
export * from './consts/MB.js'
13+
export * from './consts/NIF.js'
14+
export * from './consts/NIM.js'
1315
export * from './consts/OBM.js'
1416
export * from './consts/OCR.js'
1517
export * from './consts/OIC.js'

source/win32/consts/NIF.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
export const enum NIF_ {
3+
MESSAGE = 0x0001,
4+
ICON = 0x0002,
5+
TIP = 0x0004,
6+
STATE = 0x0008,
7+
INFO = 0x0010,
8+
GUID = 0x0020,
9+
REALTIME = 0x0040,
10+
SHOWTIP = 0x0080,
11+
}

source/win32/consts/NIM.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
export const enum NIM_ {
3+
ADD = 0x00000000,
4+
MODIFY = 0x00000001,
5+
DELETE = 0x00000002,
6+
SETFOCUS = 0x00000003,
7+
SETVERSION = 0x00000004,
8+
}

source/win32/shell32.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { shell32 } from './shell32/_lib.js'
2+
export * from './shell32/notifyicon.js'

source/win32/shell32/_lib.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { load, type koffi } from '../../private.js'
2+
3+
const shell32lib = load('shell32.dll')
4+
5+
/*@__NO_SIDE_EFFECTS__*/
6+
export function shell32(name: string, result: koffi.IKoffiCType, parameters: koffi.IKoffiCType[]) {
7+
return shell32lib.lib.func(name, result, parameters)
8+
}

source/win32/shell32/notifyicon.ts

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import {
2+
pointer, out, textDecoder,
3+
struct, sizeof,
4+
register, unregister,
5+
type koffi
6+
} from '../../private.js'
7+
import {
8+
cBOOL, cDWORD, cUINT, cLPWSTR, cLPCWSTR,
9+
} from '../../ctypes.js'
10+
import { shell32 } from './_lib.js'
11+
import { cHWND, type HWND } from '../user32/window.js'
12+
import { cHICON, type HICON } from '../user32/icon.js'
13+
import { NIF_, NIM_ } from '../consts.js'
14+
15+
// #region Types
16+
17+
/**
18+
* Contains information that the system needs to display notifications in the notification area.
19+
*
20+
* @link https://learn.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-notifyicondataw
21+
*/
22+
export class NOTIFYICONDATA {
23+
readonly cbSize = sizeof(cNOTIFYICONDATA)
24+
declare hWnd: HWND
25+
declare uID: number
26+
declare uFlags: NIF_
27+
declare uCallbackMessage: number
28+
declare hIcon: HICON
29+
declare szTip?: string
30+
declare dwState?: number
31+
declare dwStateMask?: number
32+
declare szInfo?: string
33+
declare uVersion?: number
34+
declare szInfoTitle?: string
35+
declare dwInfoFlags?: number
36+
declare guidItem?: number
37+
declare hBalloonIcon?: HICON
38+
}
39+
40+
export const cNOTIFYICONDATA = struct('NOTIFYICONDATA', {
41+
cbSize: cDWORD,
42+
hWnd: cHWND,
43+
uID: cUINT,
44+
uFlags: cUINT,
45+
uCallbackMessage: cUINT,
46+
hIcon: cHICON,
47+
szTip: cLPWSTR,
48+
dwState: cDWORD,
49+
dwStateMask: cDWORD,
50+
szInfo: cLPWSTR,
51+
uVersion: cUINT,
52+
szInfoTitle: cLPWSTR,
53+
dwInfoFlags: cDWORD,
54+
guidItem: cDWORD,
55+
hBalloonIcon: cHICON
56+
})
57+
58+
// #region Functions
59+
60+
/**
61+
* Adds, modifies, or deletes an icon from the taskbar status area.
62+
*
63+
* @link https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyiconw
64+
*/
65+
export const Shell_NotifyIcon: koffi.KoffiFunc<(
66+
dwMessage: NIM_,
67+
lpData: NOTIFYICONDATA
68+
) => boolean> = shell32('Shell_NotifyIconW', cBOOL, [ cDWORD, cNOTIFYICONDATA ])

0 commit comments

Comments
 (0)