1
1
import {
2
2
GetModuleHandle , GetLastError ,
3
3
RegisterClassEx , LoadCursor , LoadIcon , WNDCLASSEX ,
4
- CreateWindow , ShowWindow , UpdateWindow , DefWindowProc ,
4
+ CreateWindowEx , CW_USEDEFAULT , ShowWindow , UpdateWindow , DefWindowProc ,
5
5
GetMessage , TranslateMessage , DispatchMessage , PostQuitMessage ,
6
6
MessageBox ,
7
7
type HINSTANCE , type WPARAM , type LPARAM , type HWND , type MSG
8
8
} 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'
10
20
11
21
const windowClass = "NodeApp"
12
- const windowName = "Window Demo !"
22
+ const windowName = "Window Demo!"
13
23
const appTitle = "A NodeJS app using the Win32 API"
14
24
15
25
function wndProc ( hWnd : HWND , uMmsg : WM , wParam : WPARAM , lParam : LPARAM ) {
@@ -31,25 +41,26 @@ function wndProc(hWnd: HWND, uMmsg: WM, wParam: WPARAM, lParam: LPARAM) {
31
41
32
42
function WinMain ( hInstance : HINSTANCE , nCmdShow : SW ) : number {
33
43
34
- using wcex = new WNDCLASSEX ( wndProc )
44
+ using wcex = new WNDCLASSEX ( wndProc ) // Note: cbSize is set by the WNDCLASSEX constructor
35
45
wcex . lpszClassName = windowClass
36
46
wcex . style = CS . HREDRAW | CS . VREDRAW
37
47
wcex . hInstance = hInstance
38
48
wcex . hCursor = LoadCursor ( null , IDC . ARROW )
39
49
wcex . hIcon = LoadIcon ( hInstance , IDI . APPLICATION )
40
50
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.
42
52
43
53
const atom = RegisterClassEx ( wcex )
44
54
if ( ! atom ) {
45
55
MessageBox ( null , "Call to RegisterClassEx failed!" , appTitle , MB . OK | MB . ICONERROR )
46
56
return 1
47
57
}
48
58
49
- const hWnd = CreateWindow (
59
+ const hWnd = CreateWindowEx (
60
+ WS_EX . CLIENTEDGE ,
50
61
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 ,
53
64
null , null , hInstance , 0
54
65
)
55
66
if ( ! hWnd ) {
0 commit comments