Skip to content

Commit

Permalink
feat(win32-api): gdi32.CreateCompatibleDC()
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Jul 18, 2022
1 parent 2cdb74c commit 956587d
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/win32-api/src/index.promise.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

export * as Comctl32 from './lib/comctl32/index.promise.js'
export * as Gdi32 from './lib/gdi32/index.promise.js'
export * as Kernel32 from './lib/kernel32/index.promise.js'
export * as Ntdll from './lib/ntdll/index.promise.js'
export * as User32 from './lib/user32/index.promise.js'
Expand Down
3 changes: 3 additions & 0 deletions packages/win32-api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Comctl32 from './lib/comctl32/index.js'
import * as Gdi32 from './lib/gdi32/index.js'
import * as Kernel32 from './lib/kernel32/index.js'
import * as Ntdll from './lib/ntdll/index.js'
import * as User32 from './lib/user32/index.js'
Expand All @@ -24,6 +25,8 @@ export * as DStruct from 'win32-def/struct.def'
export * as DTypes from 'win32-def/common.def'


export { Gdi32 }

export { User32 as U }
export { User32 }

Expand Down
20 changes: 20 additions & 0 deletions packages/win32-api/src/lib/gdi32/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable id-length */
import * as M from 'win32-def'
import * as W from 'win32-def/common.def'


export interface Win32Fns {

/**
* @link https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createcompatibledc
*/
CreateCompatibleDC: (hdc: M.HDC) => M.HDC
}


export const apiDef: M.DllFuncs<Win32Fns> = {

CreateCompatibleDC: [W.HDC, [W.HDC] ],

}

16 changes: 16 additions & 0 deletions packages/win32-api/src/lib/gdi32/index.promise.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { FnName, LoadSettings } from 'win32-def'

import { loadAsync as hload } from '../helper.js'
import { DllNames } from '../types.js'

import { apiDef, Win32Fns } from './api.js'


export { apiDef }
export { Win32Fns }
export const dllName = DllNames.gdi32
export const load = (
fns?: FnName[],
settings?: LoadSettings,
) => hload<Win32Fns>(dllName, apiDef, fns, settings)

24 changes: 24 additions & 0 deletions packages/win32-api/src/lib/gdi32/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ExpandFnModel, FnName, LoadSettings } from 'win32-def'

import { load as hload } from '../helper.js'
import { DllNames } from '../types.js'

import { apiDef, Win32Fns } from './api.js'


export { apiDef }
export { Win32Fns }
export const dllName = DllNames.gdi32
/**
* @deprecated use promise instead
* ```ts
* import { User32 } from 'win32-api/promise'
* const user32 = User32.load()
* const hWnd = await user32.FindWindowExW(...)
* ```
*/
export const load = (
fns?: FnName[],
settings?: LoadSettings,
) => hload<ExpandFnModel<Win32Fns>>(dllName, apiDef, fns, settings)

1 change: 1 addition & 0 deletions packages/win32-api/src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

export const enum DllNames {
comctl32 = 'comctl32',
gdi32 = 'gdi32',
kernel32 = 'kernel32',
ntdll = 'ntdll',
user32 = 'user32',
Expand Down
27 changes: 27 additions & 0 deletions packages/win32-api/test/gdi32/201.CreateCompatibleDC.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import assert from 'node:assert/strict'

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 { gdi32 } from '../helper.js'


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

describe('Should CreateCompatibleDC() work', () => {
it('normal', async () => {
const hdc = await gdi32.CreateCompatibleDC(0)
console.log({ hdc })
assert(hdc)
})
})
})

2 changes: 2 additions & 0 deletions packages/win32-api/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
Kernel32,
User32,
Comctl32,
Gdi32,
} from '../src/index.promise.js'


Expand All @@ -26,6 +27,7 @@ export type StructDiType = typeof Struct
export const Union = UnionDi(ref)

export const comctl32 = Comctl32.load()
export const gdi32 = Gdi32.load()
export const knl32 = Kernel32.load()
export const knl32Sync = K.load()
export const user32 = User32.load()
Expand Down

0 comments on commit 956587d

Please sign in to comment.