Skip to content

Commit

Permalink
feat(win32-api): user32 GetClassNameW()
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Jun 30, 2024
1 parent 68ec7ef commit 3b7913f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/win32-api/src/lib/user32/dict/G.def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export class DefUser32_G extends DefUser32_F {
/** https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getclassinfoexw */
static GetClassInfoExW = [D.BOOL, [D.HINSTANCE, [D.WString], `_Out_ ${S.LPWNDCLASSEXW}`]] as const

// /** https://learn.microsoft.com/zh-cn/windows/win32/api/winuser/nf-winuser-getclassnamew */
// static GetClassNameW = [D.INT, [D.HWND, D.LPTSTR, D.INT]]
/** https://learn.microsoft.com/zh-cn/windows/win32/api/winuser/nf-winuser-getclassnamew */
static GetClassNameW = [D.INT, [D.HWND, D.LPTSTR, D.INT]]

/** https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getcursorpos */
static GetCursorPos = [D.BOOL, [`_Out_ ${S.LPPOINT}`]]
Expand Down
4 changes: 4 additions & 0 deletions packages/win32-api/src/lib/user32/dict/G.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export class User32_G extends User32_F {
/** https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getclassinfoexw */
GetClassInfoExW: (hinst: T.HINSTANCE, lpszClass: T.LPCTSTR, LPWNDCLASSEX: S.WNDCLASSEXW_Type) => T.BOOL


/** https://learn.microsoft.com/zh-cn/windows/win32/api/winuser/nf-winuser-getclassnamew */
GetClassNameW: (hWnd: T.HWND, lpClassName: T.LPTSTR, nMaxCount: T.INT) => T.INT

/** https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getcursorpos */
GetCursorPos: (lpPoint: S.POINT_Type) => T.BOOL

Expand Down
43 changes: 43 additions & 0 deletions packages/win32-api/test/lib/user32/1002.GetClassNameW.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import assert from 'node:assert/strict'
import { spawn } from 'node:child_process'

import { fileShortPath, sleep } from '@waiting/shared-core'
import { ucsBufferFrom, ucsBufferToString } from 'win32-def'
import { WNDCLASSEXW_Factory } from 'win32-def/struct'
import type { WNDCLASSEXW_Type } from 'win32-def/struct'

import { User32 as Lib, Kernel32 } from '##/index.js'
import { FindWindowEx } from '##/index.util.js'


describe(fileShortPath(import.meta.url), () => {
const lib = Lib.load()
assert(lib)
const libKnl = Kernel32.load()
assert(libKnl)
const hModule = libKnl.GetModuleHandleW(null)
assert(hModule)

describe('GetClassNameW()', () => {
it('normal', async () => {
const child = spawn('notepad.exe')

try {
await sleep(1500)
const hwnd = await FindWindowEx(0, 0, 'Notepad', null)
assert(hwnd)

const buf = Buffer.alloc(1024)
const ret = lib.GetClassNameW(hwnd, buf, 256)
assert(ret)
const text = ucsBufferToString(buf)
assert(text === 'Notepad')
}
finally {
child.kill()
}
})
})

})

0 comments on commit 3b7913f

Please sign in to comment.