Skip to content

Commit 7265aa9

Browse files
committed
feat(demos): Enrich and comment the window demo
1 parent 514f5c1 commit 7265aa9

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

source/demos/window.ts

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import {
22
GetModuleHandle, GetLastError,
33
RegisterClassEx, LoadCursor, LoadIcon, WNDCLASSEX,
4-
CreateWindow, ShowWindow, UpdateWindow, DefWindowProc,
4+
CreateWindowEx, CW_USEDEFAULT, ShowWindow, UpdateWindow, DefWindowProc,
55
GetMessage, TranslateMessage, DispatchMessage, PostQuitMessage,
66
MessageBox,
77
type HINSTANCE, type WPARAM, type LPARAM, type HWND, type MSG
88
} from 'libwin32'
9-
import { CS, CW, IDC, IDI, MB, SW, WM, WS } from 'libwin32/consts'
9+
10+
// Also import some helpfull constants.
11+
// Note: import { CS, IDC, IDI, MB, SW, WM, WS } from 'libwin32/consts' would also work,
12+
// but at the cost of tree-shakeability due to the way TypeScript exports enums.
13+
import { WM } from 'libwin32/consts/WM'
14+
import { SW } from 'libwin32/consts/SW'
15+
import { CS } from 'libwin32/consts/CS'
16+
import { IDC } from 'libwin32/consts/IDC'
17+
import { IDI } from 'libwin32/consts/IDI'
18+
import { MB } from 'libwin32/consts/MB'
19+
import { WS, WS_EX } from 'libwin32/consts/WS'
1020

1121
const windowClass = "NodeApp"
12-
const windowName = "Window Demo !"
22+
const windowName = "Window Demo!"
1323
const appTitle = "A NodeJS app using the Win32 API"
1424

1525
function wndProc(hWnd: HWND, uMmsg: WM, wParam: WPARAM, lParam: LPARAM) {
@@ -31,25 +41,26 @@ function wndProc(hWnd: HWND, uMmsg: WM, wParam: WPARAM, lParam: LPARAM) {
3141

3242
function WinMain(hInstance: HINSTANCE, nCmdShow: SW): number {
3343

34-
using wcex = new WNDCLASSEX(wndProc)
44+
using wcex = new WNDCLASSEX(wndProc) // Note: cbSize is set by the WNDCLASSEX constructor
3545
wcex.lpszClassName = windowClass
3646
wcex.style = CS.HREDRAW | CS.VREDRAW
3747
wcex.hInstance = hInstance
3848
wcex.hCursor = LoadCursor(null, IDC.ARROW)
3949
wcex.hIcon = LoadIcon(hInstance, IDI.APPLICATION)
4050
wcex.hIconSm = LoadIcon(hInstance, IDI.APPLICATION)
41-
wcex.hbrBackground = 13 as any
51+
wcex.hbrBackground = 13 as any // Note: brushes are not yet implemented. 13 is the standard background.
4252

4353
const atom = RegisterClassEx(wcex)
4454
if (!atom) {
4555
MessageBox(null, "Call to RegisterClassEx failed!", appTitle, MB.OK | MB.ICONERROR)
4656
return 1
4757
}
4858

49-
const hWnd = CreateWindow(
59+
const hWnd = CreateWindowEx(
60+
WS_EX.CLIENTEDGE,
5061
windowClass, windowName,
51-
WS.CAPTION | WS.SYSMENU,
52-
CW.USEDEFAULT, CW.USEDEFAULT, 600, 400,
62+
WS.OVERLAPPEDWINDOW | WS.VSCROLL,
63+
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
5364
null, null, hInstance, 0
5465
)
5566
if (!hWnd) {

0 commit comments

Comments
 (0)