Skip to content

Commit

Permalink
feat(win32-api): user32.FlashWindow()
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Jul 18, 2022
1 parent c04b7af commit a0b1903
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/win32-api/src/lib/user32/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export interface Win32Fns {
lpszWindow: M.LPCTSTR | null,
) => M.HWND

FlashWindow: (hWnd: M.HWND, bInvert: M.BOOL) => M.BOOL

FlashWindowEx: (pfwi: M.PFLASHWINFO) => M.BOOL

GetAncestor: (hwnd: M.HWND, gaFlags: M.UINT) => M.HWND
Expand Down Expand Up @@ -206,6 +208,8 @@ export const apiDef: M.DllFuncs<Win32Fns> = {

FindWindowExW: [W.HWND, [W.HWND, W.HWND, W.LPCTSTR, W.LPCTSTR] ],

FlashWindow: [W.BOOL, [W.HWND, W.BOOL] ],

FlashWindowEx: [W.BOOL, [W.FLASHWINFO] ],

GetAncestor: [W.HWND, [W.HWND, W.UINT] ],
Expand Down
57 changes: 57 additions & 0 deletions packages/win32-api/test/user32/61.FlashWindow.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import assert from 'node:assert/strict'
import { spawn } from 'node:child_process'

import { fileShortPath } from '@waiting/shared-core'
import ref from 'ref-napi'
import { sleep } from 'zx'

// import * as CS from '../../src/index.consts.js'
import {
DModel as M,
DTypes as W,
DStruct as DS,
StructFactory,
} from '../../src/index.js'
import { calcLpszClassNotepad } from '../config.unittest.js'
import { user32, destroyWin } from '../helper.js'


describe(fileShortPath(import.meta.url), () => {

describe.only('Should FlashWindow() work', () => {
it('true', async () => {
const child = spawn('notepad.exe')
await sleep(1000)

const hWnd = await user32.FindWindowExW(0, 0, calcLpszClassNotepad, null)
assert((typeof hWnd === 'string' && hWnd.length > 0) || hWnd > 0)

const state = await user32.FlashWindow(hWnd, 1)
assert(state > 0)
await sleep(100)
const state2 = await user32.FlashWindow(hWnd, 0)
assert(state2 === 0, state2.toString())

// await sleep(10000)
await destroyWin(hWnd)
child.kill()
})

it('false', async () => {
const child = spawn('notepad.exe')
await sleep(1000)

const hWnd = await user32.FindWindowExW(0, 0, calcLpszClassNotepad, null)
assert((typeof hWnd === 'string' && hWnd.length > 0) || hWnd > 0)

const state = await user32.FlashWindow(hWnd, 0)
assert(state > 0)

// await sleep(10000)
await destroyWin(hWnd)
child.kill()
})

})
})

0 comments on commit a0b1903

Please sign in to comment.