general.odin 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  1. // +build windows
  2. package win32
  3. Uint_Ptr :: distinct uintptr
  4. Int_Ptr :: distinct int
  5. Long_Ptr :: distinct int
  6. Handle :: distinct rawptr
  7. Hwnd :: distinct Handle
  8. Hdc :: distinct Handle
  9. Hinstance :: distinct Handle
  10. Hicon :: distinct Handle
  11. Hcursor :: distinct Handle
  12. Hmenu :: distinct Handle
  13. Hbitmap :: distinct Handle
  14. Hbrush :: distinct Handle
  15. Hgdiobj :: distinct Handle
  16. Hmodule :: distinct Handle
  17. Hmonitor :: distinct Handle
  18. Hrawinput :: distinct Handle
  19. Hresult :: distinct i32
  20. HKL :: distinct Handle
  21. Wparam :: distinct Uint_Ptr
  22. Lparam :: distinct Long_Ptr
  23. Lresult :: distinct Long_Ptr
  24. Wnd_Proc :: distinct #type proc "std" (Hwnd, u32, Wparam, Lparam) -> Lresult
  25. Monitor_Enum_Proc :: distinct #type proc "std" (Hmonitor, Hdc, ^Rect, Lparam) -> bool
  26. Bool :: distinct b32
  27. Wstring :: distinct ^u16
  28. Point :: struct {
  29. x, y: i32,
  30. }
  31. Wnd_Class_A :: struct {
  32. style: u32,
  33. wnd_proc: Wnd_Proc,
  34. cls_extra, wnd_extra: i32,
  35. instance: Hinstance,
  36. icon: Hicon,
  37. cursor: Hcursor,
  38. background: Hbrush,
  39. menu_name, class_name: cstring,
  40. }
  41. Wnd_Class_W :: struct {
  42. style: u32,
  43. wnd_proc: Wnd_Proc,
  44. cls_extra, wnd_extra: i32,
  45. instance: Hinstance,
  46. icon: Hicon,
  47. cursor: Hcursor,
  48. background: Hbrush,
  49. menu_name, class_name: Wstring,
  50. }
  51. Wnd_Class_Ex_A :: struct {
  52. size, style: u32,
  53. wnd_proc: Wnd_Proc,
  54. cls_extra, wnd_extra: i32,
  55. instance: Hinstance,
  56. icon: Hicon,
  57. cursor: Hcursor,
  58. background: Hbrush,
  59. menu_name, class_name: cstring,
  60. sm: Hicon,
  61. }
  62. Wnd_Class_Ex_W :: struct {
  63. size, style: u32,
  64. wnd_proc: Wnd_Proc,
  65. cls_extra, wnd_extra: i32,
  66. instance: Hinstance,
  67. icon: Hicon,
  68. cursor: Hcursor,
  69. background: Hbrush,
  70. menu_name, class_name: Wstring,
  71. sm: Hicon,
  72. }
  73. Msg :: struct {
  74. hwnd: Hwnd,
  75. message: u32,
  76. wparam: Wparam,
  77. lparam: Lparam,
  78. time: u32,
  79. pt: Point,
  80. }
  81. Rect :: struct {
  82. left: i32,
  83. top: i32,
  84. right: i32,
  85. bottom: i32,
  86. }
  87. Dev_Mode_A :: struct {
  88. device_name: [32]u8,
  89. spec_version: u16,
  90. driver_version: u16,
  91. size: u16,
  92. driver_extra: u16,
  93. fields: u32,
  94. using _: struct #raw_union {
  95. // Printer only fields.
  96. using _: struct {
  97. orientation: i16,
  98. paper_size: i16,
  99. paper_length: i16,
  100. paper_width: i16,
  101. scale: i16,
  102. copies: i16,
  103. default_source: i16,
  104. print_quality: i16,
  105. },
  106. // Display only fields.
  107. using _: struct {
  108. position: Point,
  109. display_orientation: u32,
  110. display_fixed_output: u32,
  111. },
  112. },
  113. color: i16,
  114. duplex: i16,
  115. y_resolution: i16,
  116. tt_option: i16,
  117. collate: i16,
  118. form_name: [32]u8,
  119. log_pixels: u16,
  120. bits_per_pel: u32,
  121. pels_width: u32,
  122. pels_height: u32,
  123. using _: struct #raw_union {
  124. display_flags: u32,
  125. nup: u32,
  126. },
  127. display_frequency: u32,
  128. icm_method: u32,
  129. icm_intent: u32,
  130. media_type: u32,
  131. dither_type: u32,
  132. reserved_1: u32,
  133. reserved_2: u32,
  134. panning_width: u32,
  135. panning_height: u32,
  136. }
  137. Filetime :: struct {
  138. lo, hi: u32,
  139. }
  140. Systemtime :: struct {
  141. year, month: u16,
  142. day_of_week, day: u16,
  143. hour, minute, second, millisecond: u16,
  144. }
  145. By_Handle_File_Information :: struct {
  146. file_attributes: u32,
  147. creation_time,
  148. last_access_time,
  149. last_write_time: Filetime,
  150. volume_serial_number,
  151. file_size_high,
  152. file_size_low,
  153. number_of_links,
  154. file_index_high,
  155. file_index_low: u32,
  156. }
  157. File_Attribute_Data :: struct {
  158. file_attributes: u32,
  159. creation_time,
  160. last_access_time,
  161. last_write_time: Filetime,
  162. file_size_high,
  163. file_size_low: u32,
  164. }
  165. // NOTE(Jeroen): The widechar version might want at least the 32k MAX_PATH_WIDE
  166. // https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findfirstfilew#parameters
  167. Find_Data_W :: struct{
  168. file_attributes: u32,
  169. creation_time: Filetime,
  170. last_access_time: Filetime,
  171. last_write_time: Filetime,
  172. file_size_high: u32,
  173. file_size_low: u32,
  174. reserved0: u32,
  175. reserved1: u32,
  176. file_name: [MAX_PATH]u16,
  177. alternate_file_name: [14]u16,
  178. }
  179. Find_Data_A :: struct{
  180. file_attributes: u32,
  181. creation_time: Filetime,
  182. last_access_time: Filetime,
  183. last_write_time: Filetime,
  184. file_size_high: u32,
  185. file_size_low: u32,
  186. reserved0: u32,
  187. reserved1: u32,
  188. file_name: [MAX_PATH]byte,
  189. alternate_file_name: [14]byte,
  190. }
  191. Security_Attributes :: struct {
  192. length: u32,
  193. security_descriptor: rawptr,
  194. inherit_handle: Bool,
  195. }
  196. Process_Information :: struct {
  197. process: Handle,
  198. thread: Handle,
  199. process_id: u32,
  200. thread_id: u32,
  201. }
  202. Startup_Info :: struct {
  203. cb: u32,
  204. reserved: Wstring,
  205. desktop: Wstring,
  206. title: Wstring,
  207. x: u32,
  208. y: u32,
  209. x_size: u32,
  210. y_size: u32,
  211. x_count_chars: u32,
  212. y_count_chars: u32,
  213. fill_attribute: u32,
  214. flags: u32,
  215. show_window: u16,
  216. _: u16,
  217. _: cstring,
  218. stdin: Handle,
  219. stdout: Handle,
  220. stderr: Handle,
  221. }
  222. Pixel_Format_Descriptor :: struct {
  223. size,
  224. version,
  225. flags: u32,
  226. pixel_type,
  227. color_bits,
  228. red_bits,
  229. red_shift,
  230. green_bits,
  231. green_shift,
  232. blue_bits,
  233. blue_shift,
  234. alpha_bits,
  235. alpha_shift,
  236. accum_bits,
  237. accum_red_bits,
  238. accum_green_bits,
  239. accum_blue_bits,
  240. accum_alpha_bits,
  241. depth_bits,
  242. stencil_bits,
  243. aux_buffers,
  244. layer_type,
  245. reserved: byte,
  246. layer_mask,
  247. visible_mask,
  248. damage_mask: u32,
  249. }
  250. Critical_Section :: struct {
  251. debug_info: ^Critical_Section_Debug,
  252. lock_count: i32,
  253. recursion_count: i32,
  254. owning_thread: Handle,
  255. lock_semaphore: Handle,
  256. spin_count: ^u32,
  257. }
  258. Critical_Section_Debug :: struct {
  259. typ: u16,
  260. creator_back_trace_index: u16,
  261. critical_section: ^Critical_Section,
  262. process_locks_list: ^List_Entry,
  263. entry_count: u32,
  264. contention_count: u32,
  265. flags: u32,
  266. creator_back_trace_index_high: u16,
  267. spare_word: u16,
  268. }
  269. List_Entry :: struct {flink, blink: ^List_Entry}
  270. Raw_Input_Device :: struct {
  271. usage_page: u16,
  272. usage: u16,
  273. flags: u32,
  274. wnd_target: Hwnd,
  275. }
  276. Raw_Input_Header :: struct {
  277. kind: u32,
  278. size: u32,
  279. device: Handle,
  280. wparam: Wparam,
  281. }
  282. Raw_HID :: struct {
  283. size_hid: u32,
  284. count: u32,
  285. raw_data: [1]byte,
  286. }
  287. Raw_Keyboard :: struct {
  288. make_code: u16,
  289. flags: u16,
  290. reserved: u16,
  291. vkey: u16,
  292. message: u32,
  293. extra_information: u32,
  294. }
  295. Raw_Mouse :: struct {
  296. flags: u16,
  297. using data: struct #raw_union {
  298. buttons: u32,
  299. using _: struct {
  300. button_flags: u16,
  301. button_data: u16,
  302. },
  303. },
  304. raw_buttons: u32,
  305. last_x: i32,
  306. last_y: i32,
  307. extra_information: u32,
  308. }
  309. Raw_Input :: struct {
  310. using header: Raw_Input_Header,
  311. data: struct #raw_union {
  312. mouse: Raw_Mouse,
  313. keyboard: Raw_Keyboard,
  314. hid: Raw_HID,
  315. },
  316. }
  317. Overlapped :: struct {
  318. internal: ^u64,
  319. internal_high: ^u64,
  320. using _: struct #raw_union {
  321. using _: struct {
  322. offset: u32,
  323. offset_high: u32,
  324. },
  325. pointer: rawptr,
  326. },
  327. event: Handle,
  328. }
  329. File_Notify_Information :: struct {
  330. next_entry_offset: u32,
  331. action: u32,
  332. file_name_length: u32,
  333. file_name: [1]u16,
  334. }
  335. // https://docs.microsoft.com/en-gb/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info
  336. System_Info :: struct {
  337. using _: struct #raw_union {
  338. oem_id: u32,
  339. using _: struct #raw_union {
  340. processor_architecture: u16,
  341. _: u16, // reserved
  342. },
  343. },
  344. page_size: u32,
  345. minimum_application_address: rawptr,
  346. maximum_application_address: rawptr,
  347. active_processor_mask: u32,
  348. number_of_processors: u32,
  349. processor_type: u32,
  350. allocation_granularity: u32,
  351. processor_level: u16,
  352. processor_revision: u16,
  353. }
  354. // https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_osversioninfoexa
  355. OS_Version_Info_Ex_A :: struct {
  356. os_version_info_size: u32,
  357. major_version: u32,
  358. minor_version: u32,
  359. build_number: u32,
  360. platform_id : u32,
  361. service_pack_string: [128]u8,
  362. service_pack_major: u16,
  363. service_pack_minor: u16,
  364. suite_mask: u16,
  365. product_type: u8,
  366. reserved: u8,
  367. }
  368. MAPVK_VK_TO_VSC :: 0
  369. MAPVK_VSC_TO_VK :: 1
  370. MAPVK_VK_TO_CHAR :: 2
  371. MAPVK_VSC_TO_VK_EX :: 3
  372. //WinUser.h
  373. ENUM_CURRENT_SETTINGS :: u32(4294967295) // (DWORD)-1
  374. ENUM_REGISTRY_SETTINGS :: u32(4294967294) // (DWORD)-2
  375. VK_LBUTTON :: 0x01
  376. VK_RBUTTON :: 0x02
  377. VK_CANCEL :: 0x03
  378. VK_MBUTTON :: 0x04 /* NOT contiguous with L & RBUTTON */
  379. VK_XBUTTON1 :: 0x05 /* NOT contiguous with L & RBUTTON */
  380. VK_XBUTTON2 :: 0x06 /* NOT contiguous with L & RBUTTON */
  381. /*
  382. * :: 0x07 : reserved
  383. */
  384. VK_BACK :: 0x08
  385. VK_TAB :: 0x09
  386. /*
  387. * :: 0x0A - :: 0x0B : reserved
  388. */
  389. VK_CLEAR :: 0x0C
  390. VK_RETURN :: 0x0D
  391. /*
  392. * :: 0x0E - :: 0x0F : unassigned
  393. */
  394. VK_SHIFT :: 0x10
  395. VK_CONTROL :: 0x11
  396. VK_MENU :: 0x12
  397. VK_PAUSE :: 0x13
  398. VK_CAPITAL :: 0x14
  399. VK_KANA :: 0x15
  400. VK_HANGEUL :: 0x15 /* old name - should be here for compatibility */
  401. VK_HANGUL :: 0x15
  402. /*
  403. * :: 0x16 : unassigned
  404. */
  405. VK_JUNJA :: 0x17
  406. VK_FINAL :: 0x18
  407. VK_HANJA :: 0x19
  408. VK_KANJI :: 0x19
  409. /*
  410. * :: 0x1A : unassigned
  411. */
  412. VK_ESCAPE :: 0x1B
  413. VK_CONVERT :: 0x1C
  414. VK_NONCONVERT :: 0x1D
  415. VK_ACCEPT :: 0x1E
  416. VK_MODECHANGE :: 0x1F
  417. VK_SPACE :: 0x20
  418. VK_PRIOR :: 0x21
  419. VK_NEXT :: 0x22
  420. VK_END :: 0x23
  421. VK_HOME :: 0x24
  422. VK_LEFT :: 0x25
  423. VK_UP :: 0x26
  424. VK_RIGHT :: 0x27
  425. VK_DOWN :: 0x28
  426. VK_SELECT :: 0x29
  427. VK_PRINT :: 0x2A
  428. VK_EXECUTE :: 0x2B
  429. VK_SNAPSHOT :: 0x2C
  430. VK_INSERT :: 0x2D
  431. VK_DELETE :: 0x2E
  432. VK_HELP :: 0x2F
  433. /*
  434. * VK_0 - VK_9 are the same as ASCII '0' - '9' (:: 0x30 - :: 0x39)
  435. * :: 0x3A - :: 0x40 : unassigned
  436. * VK_A - VK_Z are the same as ASCII 'A' - 'Z' (:: 0x41 - :: 0x5A)
  437. */
  438. VK_LWIN :: 0x5B
  439. VK_RWIN :: 0x5C
  440. VK_APPS :: 0x5D
  441. /*
  442. * :: 0x5E : reserved
  443. */
  444. VK_SLEEP :: 0x5F
  445. VK_NUMPAD0 :: 0x60
  446. VK_NUMPAD1 :: 0x61
  447. VK_NUMPAD2 :: 0x62
  448. VK_NUMPAD3 :: 0x63
  449. VK_NUMPAD4 :: 0x64
  450. VK_NUMPAD5 :: 0x65
  451. VK_NUMPAD6 :: 0x66
  452. VK_NUMPAD7 :: 0x67
  453. VK_NUMPAD8 :: 0x68
  454. VK_NUMPAD9 :: 0x69
  455. VK_MULTIPLY :: 0x6A
  456. VK_ADD :: 0x6B
  457. VK_SEPARATOR :: 0x6C
  458. VK_SUBTRACT :: 0x6D
  459. VK_DECIMAL :: 0x6E
  460. VK_DIVIDE :: 0x6F
  461. VK_F1 :: 0x70
  462. VK_F2 :: 0x71
  463. VK_F3 :: 0x72
  464. VK_F4 :: 0x73
  465. VK_F5 :: 0x74
  466. VK_F6 :: 0x75
  467. VK_F7 :: 0x76
  468. VK_F8 :: 0x77
  469. VK_F9 :: 0x78
  470. VK_F10 :: 0x79
  471. VK_F11 :: 0x7A
  472. VK_F12 :: 0x7B
  473. VK_F13 :: 0x7C
  474. VK_F14 :: 0x7D
  475. VK_F15 :: 0x7E
  476. VK_F16 :: 0x7F
  477. VK_F17 :: 0x80
  478. VK_F18 :: 0x81
  479. VK_F19 :: 0x82
  480. VK_F20 :: 0x83
  481. VK_F21 :: 0x84
  482. VK_F22 :: 0x85
  483. VK_F23 :: 0x86
  484. VK_F24 :: 0x87
  485. INVALID_HANDLE :: Handle(~uintptr(0))
  486. CREATE_SUSPENDED :: 0x00000004
  487. STACK_SIZE_PARAM_IS_A_RESERVATION :: 0x00010000
  488. WAIT_ABANDONED :: 0x00000080
  489. WAIT_OBJECT_0 :: 0
  490. WAIT_TIMEOUT :: 0x00000102
  491. WAIT_FAILED :: 0xffffffff
  492. CS_VREDRAW :: 0x0001
  493. CS_HREDRAW :: 0x0002
  494. CS_OWNDC :: 0x0020
  495. CW_USEDEFAULT :: -0x80000000
  496. WS_OVERLAPPED :: 0
  497. WS_MAXIMIZEBOX :: 0x00010000
  498. WS_MINIMIZEBOX :: 0x00020000
  499. WS_THICKFRAME :: 0x00040000
  500. WS_SYSMENU :: 0x00080000
  501. WS_BORDER :: 0x00800000
  502. WS_CAPTION :: 0x00C00000
  503. WS_VISIBLE :: 0x10000000
  504. WS_POPUP :: 0x80000000
  505. WS_MAXIMIZE :: 0x01000000
  506. WS_MINIMIZE :: 0x20000000
  507. WS_OVERLAPPEDWINDOW :: WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX
  508. WS_POPUPWINDOW :: WS_POPUP | WS_BORDER | WS_SYSMENU
  509. WS_EX_DLGMODALFRAME :: 0x00000001
  510. WS_EX_NOPARENTNOTIFY :: 0x00000004
  511. WS_EX_TOPMOST :: 0x00000008
  512. WS_EX_ACCEPTFILES :: 0x00000010
  513. WS_EX_TRANSPARENT :: 0x00000020
  514. WS_EX_MDICHILD :: 0x00000040
  515. WS_EX_TOOLWINDOW :: 0x00000080
  516. WS_EX_WINDOWEDGE :: 0x00000100
  517. WS_EX_CLIENTEDGE :: 0x00000200
  518. WS_EX_CONTEXTHELP :: 0x00000400
  519. WS_EX_RIGHT :: 0x00001000
  520. WS_EX_LEFT :: 0x00000000
  521. WS_EX_RTLREADING :: 0x00002000
  522. WS_EX_LTRREADING :: 0x00000000
  523. WS_EX_LEFTSCROLLBAR :: 0x00004000
  524. WS_EX_RIGHTSCROLLBAR :: 0x00000000
  525. WS_EX_CONTROLPARENT :: 0x00010000
  526. WS_EX_STATICEDGE :: 0x00020000
  527. WS_EX_APPWINDOW :: 0x00040000
  528. WS_EX_OVERLAPPEDWINDOW :: WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE
  529. WS_EX_PALETTEWINDOW :: WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST
  530. WS_EX_LAYERED :: 0x00080000
  531. WS_EX_NOINHERITLAYOUT :: 0x00100000 // Disable inheritence of mirroring by children
  532. WS_EX_NOREDIRECTIONBITMAP :: 0x00200000
  533. WS_EX_LAYOUTRTL :: 0x00400000 // Right to left mirroring
  534. WS_EX_COMPOSITED :: 0x02000000
  535. WS_EX_NOACTIVATE :: 0x08000000
  536. WM_ACTIVATE :: 0x0006
  537. WM_ACTIVATEAPP :: 0x001C
  538. WM_CHAR :: 0x0102
  539. WM_CLOSE :: 0x0010
  540. WM_CREATE :: 0x0001
  541. WM_DESTROY :: 0x0002
  542. WM_INPUT :: 0x00FF
  543. WM_KEYDOWN :: 0x0100
  544. WM_KEYUP :: 0x0101
  545. WM_KILLFOCUS :: 0x0008
  546. WM_QUIT :: 0x0012
  547. WM_SETCURSOR :: 0x0020
  548. WM_SETFOCUS :: 0x0007
  549. WM_SIZE :: 0x0005
  550. WM_SIZING :: 0x0214
  551. WM_SYSKEYDOWN :: 0x0104
  552. WM_SYSKEYUP :: 0x0105
  553. WM_USER :: 0x0400
  554. WM_WINDOWPOSCHANGED :: 0x0047
  555. WM_COMMAND :: 0x0111
  556. WM_PAINT :: 0x000F
  557. WM_MOUSEWHEEL :: 0x020A
  558. WM_MOUSEMOVE :: 0x0200
  559. WM_LBUTTONDOWN :: 0x0201
  560. WM_LBUTTONUP :: 0x0202
  561. WM_LBUTTONDBLCLK :: 0x0203
  562. WM_RBUTTONDOWN :: 0x0204
  563. WM_RBUTTONUP :: 0x0205
  564. WM_RBUTTONDBLCLK :: 0x0206
  565. WM_MBUTTONDOWN :: 0x0207
  566. WM_MBUTTONUP :: 0x0208
  567. WM_MBUTTONDBLCLK :: 0x0209
  568. PM_NOREMOVE :: 0x0000
  569. PM_REMOVE :: 0x0001
  570. PM_NOYIELD :: 0x0002
  571. BLACK_BRUSH :: 4
  572. SM_CXSCREEN :: 0
  573. SM_CYSCREEN :: 1
  574. SW_SHOW :: 5
  575. COLOR_BACKGROUND :: Hbrush(uintptr(1))
  576. INVALID_SET_FILE_POINTER :: ~u32(0)
  577. HEAP_ZERO_MEMORY :: 0x00000008
  578. INFINITE :: 0xffffffff
  579. GWL_EXSTYLE :: -20
  580. GWLP_HINSTANCE :: -6
  581. GWLP_ID :: -12
  582. GWL_STYLE :: -16
  583. GWLP_USERDATA :: -21
  584. GWLP_WNDPROC :: -4
  585. Hwnd_TOP :: Hwnd(uintptr(0))
  586. BI_RGB :: 0
  587. DIB_RGB_COLORS :: 0x00
  588. SRCCOPY: u32 : 0x00cc0020
  589. MONITOR_DEFAULTTONULL :: 0x00000000
  590. MONITOR_DEFAULTTOPRIMARY :: 0x00000001
  591. MONITOR_DEFAULTTONEAREST :: 0x00000002
  592. SWP_FRAMECHANGED :: 0x0020
  593. SWP_NOOWNERZORDER :: 0x0200
  594. SWP_NOZORDER :: 0x0004
  595. SWP_NOSIZE :: 0x0001
  596. SWP_NOMOVE :: 0x0002
  597. // Raw Input
  598. RID_HEADER :: 0x10000005
  599. RID_INPUT :: 0x10000003
  600. RIDEV_APPKEYS :: 0x00000400
  601. RIDEV_CAPTUREMOUSE :: 0x00000200
  602. RIDEV_DEVNOTIFY :: 0x00002000
  603. RIDEV_EXCLUDE :: 0x00000010
  604. RIDEV_EXINPUTSINK :: 0x00001000
  605. RIDEV_INPUTSINK :: 0x00000100
  606. RIDEV_NOHOTKEYS :: 0x00000200
  607. RIDEV_NOLEGACY :: 0x00000030
  608. RIDEV_PAGEONLY :: 0x00000020
  609. RIDEV_REMOVE :: 0x00000001
  610. RIM_TYPEMOUSE :: 0
  611. RIM_TYPEKEYBOARD :: 1
  612. RIM_TYPEHID :: 2
  613. MOUSE_ATTRIBUTES_CHANGED :: 0x04
  614. MOUSE_MOVE_RELATIVE :: 0
  615. MOUSE_MOVE_ABSOLUTE :: 1
  616. MOUSE_VIRTUAL_DESKTOP :: 0x02
  617. RI_MOUSE_BUTTON_1_DOWN :: 0x0001
  618. RI_MOUSE_BUTTON_1_UP :: 0x0002
  619. RI_MOUSE_BUTTON_2_DOWN :: 0x0004
  620. RI_MOUSE_BUTTON_2_UP :: 0x0008
  621. RI_MOUSE_BUTTON_3_DOWN :: 0x0010
  622. RI_MOUSE_BUTTON_3_UP :: 0x0020
  623. RI_MOUSE_BUTTON_4_DOWN :: 0x0040
  624. RI_MOUSE_BUTTON_4_UP :: 0x0080
  625. RI_MOUSE_BUTTON_5_DOWN :: 0x0100
  626. RI_MOUSE_BUTTON_5_UP :: 0x0200
  627. RI_MOUSE_LEFT_BUTTON_DOWN :: 0x0001
  628. RI_MOUSE_LEFT_BUTTON_UP :: 0x0002
  629. RI_MOUSE_MIDDLE_BUTTON_DOWN :: 0x0010
  630. RI_MOUSE_MIDDLE_BUTTON_UP :: 0x0020
  631. RI_MOUSE_RIGHT_BUTTON_DOWN :: 0x0004
  632. RI_MOUSE_RIGHT_BUTTON_UP :: 0x0008
  633. RI_MOUSE_WHEEL :: 0x0400
  634. RI_KEY_MAKE :: 0x00
  635. RI_KEY_BREAK :: 0x01
  636. RI_KEY_E0 :: 0x02
  637. RI_KEY_E1 :: 0x04
  638. RI_KEY_TERMSRV_SET_LED :: 0x08
  639. RI_KEY_TERMSRV_SHADOW :: 0x10
  640. // Windows OpenGL
  641. PFD_TYPE_RGBA :: 0
  642. PFD_TYPE_COLORINDEX :: 1
  643. PFD_MAIN_PLANE :: 0
  644. PFD_OVERLAY_PLANE :: 1
  645. PFD_UNDERLAY_PLANE :: -1
  646. PFD_DOUBLEBUFFER :: 1
  647. PFD_STEREO :: 2
  648. PFD_DRAW_TO_WINDOW :: 4
  649. PFD_DRAW_TO_BITMAP :: 8
  650. PFD_SUPPORT_GDI :: 16
  651. PFD_SUPPORT_OPENGL :: 32
  652. PFD_GENERIC_FORMAT :: 64
  653. PFD_NEED_PALETTE :: 128
  654. PFD_NEED_SYSTEM_PALETTE :: 0x00000100
  655. PFD_SWAP_EXCHANGE :: 0x00000200
  656. PFD_SWAP_COPY :: 0x00000400
  657. PFD_SWAP_LAYER_BUFFERS :: 0x00000800
  658. PFD_GENERIC_ACCELERATED :: 0x00001000
  659. PFD_DEPTH_DONTCARE :: 0x20000000
  660. PFD_DOUBLEBUFFER_DONTCARE :: 0x40000000
  661. PFD_STEREO_DONTCARE :: 0x80000000
  662. GET_FILEEX_INFO_LEVELS :: distinct i32
  663. GetFileExInfoStandard: GET_FILEEX_INFO_LEVELS : 0
  664. GetFileExMaxInfoLevel: GET_FILEEX_INFO_LEVELS : 1
  665. STARTF_USESHOWWINDOW :: 0x00000001
  666. STARTF_USESIZE :: 0x00000002
  667. STARTF_USEPOSITION :: 0x00000004
  668. STARTF_USECOUNTCHARS :: 0x00000008
  669. STARTF_USEFILLATTRIBUTE :: 0x00000010
  670. STARTF_RUNFULLSCREEN :: 0x00000020 // ignored for non-x86 platforms
  671. STARTF_FORCEONFEEDBACK :: 0x00000040
  672. STARTF_FORCEOFFFEEDBACK :: 0x00000080
  673. STARTF_USESTDHANDLES :: 0x00000100
  674. STARTF_USEHOTKEY :: 0x00000200
  675. STARTF_TITLEISLINKNAME :: 0x00000800
  676. STARTF_TITLEISAPPID :: 0x00001000
  677. STARTF_PREVENTPINNING :: 0x00002000
  678. STARTF_UNTRUSTEDSOURCE :: 0x00008000
  679. MOVEFILE_REPLACE_EXISTING :: 0x00000001
  680. MOVEFILE_COPY_ALLOWED :: 0x00000002
  681. MOVEFILE_DELAY_UNTIL_REBOOT :: 0x00000004
  682. MOVEFILE_WRITE_THROUGH :: 0x00000008
  683. MOVEFILE_CREATE_HARDLINK :: 0x00000010
  684. MOVEFILE_FAIL_IF_NOT_TRACKABLE :: 0x00000020
  685. FILE_NOTIFY_CHANGE_FILE_NAME :: 0x00000001
  686. FILE_NOTIFY_CHANGE_DIR_NAME :: 0x00000002
  687. FILE_NOTIFY_CHANGE_ATTRIBUTES :: 0x00000004
  688. FILE_NOTIFY_CHANGE_SIZE :: 0x00000008
  689. FILE_NOTIFY_CHANGE_LAST_WRITE :: 0x00000010
  690. FILE_NOTIFY_CHANGE_LAST_ACCESS :: 0x00000020
  691. FILE_NOTIFY_CHANGE_CREATION :: 0x00000040
  692. FILE_NOTIFY_CHANGE_SECURITY :: 0x00000100
  693. FILE_FLAG_WRITE_THROUGH :: 0x80000000
  694. FILE_FLAG_OVERLAPPED :: 0x40000000
  695. FILE_FLAG_NO_BUFFERING :: 0x20000000
  696. FILE_FLAG_RANDOM_ACCESS :: 0x10000000
  697. FILE_FLAG_SEQUENTIAL_SCAN :: 0x08000000
  698. FILE_FLAG_DELETE_ON_CLOSE :: 0x04000000
  699. FILE_FLAG_BACKUP_SEMANTICS :: 0x02000000
  700. FILE_FLAG_POSIX_SEMANTICS :: 0x01000000
  701. FILE_FLAG_SESSION_AWARE :: 0x00800000
  702. FILE_FLAG_OPEN_REPARSE_POINT :: 0x00200000
  703. FILE_FLAG_OPEN_NO_RECALL :: 0x00100000
  704. FILE_FLAG_FIRST_PIPE_INSTANCE :: 0x00080000
  705. FILE_ACTION_ADDED :: 0x00000001
  706. FILE_ACTION_REMOVED :: 0x00000002
  707. FILE_ACTION_MODIFIED :: 0x00000003
  708. FILE_ACTION_RENAMED_OLD_NAME :: 0x00000004
  709. FILE_ACTION_RENAMED_NEW_NAME :: 0x00000005
  710. CP_ACP :: 0 // default to ANSI code page
  711. CP_OEMCP :: 1 // default to OEM code page
  712. CP_MACCP :: 2 // default to MAC code page
  713. CP_THREAD_ACP :: 3 // current thread's ANSI code page
  714. CP_SYMBOL :: 42 // SYMBOL translations
  715. CP_UTF7 :: 65000 // UTF-7 translation
  716. CP_UTF8 :: 65001 // UTF-8 translation
  717. MB_ERR_INVALID_CHARS :: 8
  718. WC_ERR_INVALID_CHARS :: 128
  719. utf8_to_utf16 :: proc(s: string, allocator := context.temp_allocator) -> []u16 {
  720. if len(s) < 1 {
  721. return nil
  722. }
  723. b := transmute([]byte)s
  724. cstr := cstring(&b[0])
  725. n := multi_byte_to_wide_char(CP_UTF8, MB_ERR_INVALID_CHARS, cstr, i32(len(s)), nil, 0)
  726. if n == 0 {
  727. return nil
  728. }
  729. text := make([]u16, n+1, allocator)
  730. n1 := multi_byte_to_wide_char(CP_UTF8, MB_ERR_INVALID_CHARS, cstr, i32(len(s)), Wstring(&text[0]), i32(n))
  731. if n1 == 0 {
  732. delete(text, allocator)
  733. return nil
  734. }
  735. text[n] = 0
  736. for n >= 1 && text[n-1] == 0 {
  737. n -= 1
  738. }
  739. return text[:n]
  740. }
  741. utf8_to_wstring :: proc(s: string, allocator := context.temp_allocator) -> Wstring {
  742. if res := utf8_to_utf16(s, allocator); res != nil {
  743. return Wstring(&res[0])
  744. }
  745. return nil
  746. }
  747. wstring_to_utf8 :: proc(s: Wstring, N: int, allocator := context.temp_allocator) -> string {
  748. if N == 0 {
  749. return ""
  750. }
  751. n := wide_char_to_multi_byte(CP_UTF8, WC_ERR_INVALID_CHARS, s, i32(N), nil, 0, nil, nil)
  752. if n == 0 {
  753. return ""
  754. }
  755. // If N == -1 the call to wide_char_to_multi_byte assume the wide string is null terminated
  756. // and will scan it to find the first null terminated character. The resulting string will
  757. // also null terminated.
  758. // If N != -1 it assumes the wide string is not null terminated and the resulting string
  759. // will not be null terminated, we therefore have to force it to be null terminated manually.
  760. text := make([]byte, n+1 if N != -1 else n, allocator)
  761. if n1 := wide_char_to_multi_byte(CP_UTF8, WC_ERR_INVALID_CHARS, s, i32(N), cstring(&text[0]), n, nil, nil); n1 == 0 {
  762. delete(text, allocator)
  763. return ""
  764. }
  765. for i in 0..<n {
  766. if text[i] == 0 {
  767. n = i
  768. break
  769. }
  770. }
  771. return string(text[:n])
  772. }
  773. utf16_to_utf8 :: proc(s: []u16, allocator := context.temp_allocator) -> string {
  774. if len(s) == 0 {
  775. return ""
  776. }
  777. return wstring_to_utf8(cast(Wstring)&s[0], len(s), allocator)
  778. }
  779. get_query_performance_frequency :: proc() -> i64 {
  780. r: i64
  781. query_performance_frequency(&r)
  782. return r
  783. }
  784. HIWORD_W :: proc(wParam: Wparam) -> u16 { return u16((u32(wParam) >> 16) & 0xffff) }
  785. HIWORD_L :: proc(lParam: Lparam) -> u16 { return u16((u32(lParam) >> 16) & 0xffff) }
  786. LOWORD_W :: proc(wParam: Wparam) -> u16 { return u16(wParam) }
  787. LOWORD_L :: proc(lParam: Lparam) -> u16 { return u16(lParam) }
  788. is_key_down :: #force_inline proc(key: Key_Code) -> bool { return get_async_key_state(i32(key)) < 0 }
  789. MAX_PATH :: 0x00000104
  790. MAX_PATH_WIDE :: 0x8000
  791. HANDLE_FLAG_INHERIT :: 1
  792. HANDLE_FLAG_PROTECT_FROM_CLOSE :: 2
  793. FILE_BEGIN :: 0
  794. FILE_CURRENT :: 1
  795. FILE_END :: 2
  796. FILE_SHARE_READ :: 0x00000001
  797. FILE_SHARE_WRITE :: 0x00000002
  798. FILE_SHARE_DELETE :: 0x00000004
  799. FILE_GENERIC_ALL :: 0x10000000
  800. FILE_GENERIC_EXECUTE :: 0x20000000
  801. FILE_GENERIC_WRITE :: 0x40000000
  802. FILE_GENERIC_READ :: 0x80000000
  803. FILE_READ_DATA :: 0x0001
  804. FILE_LIST_DIRECTORY :: 0x0001
  805. FILE_WRITE_DATA :: 0x0002
  806. FILE_ADD_FILE :: 0x0002
  807. FILE_APPEND_DATA :: 0x0004
  808. FILE_ADD_SUBDIRECTORY :: 0x0004
  809. FILE_CREATE_PIPE_INSTANCE :: 0x0004
  810. FILE_READ_EA :: 0x0008
  811. FILE_WRITE_EA :: 0x0010
  812. FILE_EXECUTE :: 0x0020
  813. FILE_TRAVERSE :: 0x0020
  814. FILE_DELETE_CHILD :: 0x0040
  815. FILE_READ_ATTRIBUTES :: 0x0080
  816. FILE_WRITE_ATTRIBUTES :: 0x0100
  817. STD_INPUT_HANDLE :: -10
  818. STD_OUTPUT_HANDLE :: -11
  819. STD_ERROR_HANDLE :: -12
  820. CREATE_NEW :: 1
  821. CREATE_ALWAYS :: 2
  822. OPEN_EXISTING :: 3
  823. OPEN_ALWAYS :: 4
  824. TRUNCATE_EXISTING :: 5
  825. INVALID_FILE_ATTRIBUTES :: -1
  826. FILE_ATTRIBUTE_READONLY :: 0x00000001
  827. FILE_ATTRIBUTE_HIDDEN :: 0x00000002
  828. FILE_ATTRIBUTE_SYSTEM :: 0x00000004
  829. FILE_ATTRIBUTE_DIRECTORY :: 0x00000010
  830. FILE_ATTRIBUTE_ARCHIVE :: 0x00000020
  831. FILE_ATTRIBUTE_DEVICE :: 0x00000040
  832. FILE_ATTRIBUTE_NORMAL :: 0x00000080
  833. FILE_ATTRIBUTE_TEMPORARY :: 0x00000100
  834. FILE_ATTRIBUTE_SPARSE_FILE :: 0x00000200
  835. FILE_ATTRIBUTE_REPARSE_Point :: 0x00000400
  836. FILE_ATTRIBUTE_COMPRESSED :: 0x00000800
  837. FILE_ATTRIBUTE_OFFLINE :: 0x00001000
  838. FILE_ATTRIBUTE_NOT_CONTENT_INDEXED :: 0x00002000
  839. FILE_ATTRIBUTE_ENCRYPTED :: 0x00004000
  840. FILE_TYPE_DISK :: 0x0001
  841. FILE_TYPE_CHAR :: 0x0002
  842. FILE_TYPE_PIPE :: 0x0003
  843. Monitor_Info :: struct {
  844. size: u32,
  845. monitor: Rect,
  846. work: Rect,
  847. flags: u32,
  848. }
  849. Window_Placement :: struct {
  850. length: u32,
  851. flags: u32,
  852. show_cmd: u32,
  853. min_pos: Point,
  854. max_pos: Point,
  855. normal_pos: Rect,
  856. }
  857. Bitmap_Info_Header :: struct {
  858. size: u32,
  859. width, height: i32,
  860. planes, bit_count: i16,
  861. compression: u32,
  862. size_image: u32,
  863. x_pels_per_meter: i32,
  864. y_pels_per_meter: i32,
  865. clr_used: u32,
  866. clr_important: u32,
  867. }
  868. Bitmap_Info :: struct {
  869. using header: Bitmap_Info_Header,
  870. colors: [1]Rgb_Quad,
  871. }
  872. Paint_Struct :: struct {
  873. hdc: Hdc,
  874. erase: Bool,
  875. rc_paint: Rect,
  876. restore: Bool,
  877. inc_update: Bool,
  878. rgb_reserved: [32]byte,
  879. }
  880. Rgb_Quad :: struct {blue, green, red, reserved: byte}
  881. Key_Code :: enum i32 {
  882. Unknown = 0x00,
  883. Lbutton = 0x01,
  884. Rbutton = 0x02,
  885. Cancel = 0x03,
  886. Mbutton = 0x04,
  887. Xbutton1 = 0x05,
  888. Xbutton2 = 0x06,
  889. Back = 0x08,
  890. Tab = 0x09,
  891. Clear = 0x0C,
  892. Return = 0x0D,
  893. Shift = 0x10,
  894. Control = 0x11,
  895. Menu = 0x12,
  896. Pause = 0x13,
  897. Capital = 0x14,
  898. Kana = 0x15,
  899. Hangeul = 0x15,
  900. Hangul = 0x15,
  901. Junja = 0x17,
  902. Final = 0x18,
  903. Hanja = 0x19,
  904. Kanji = 0x19,
  905. Escape = 0x1B,
  906. Convert = 0x1C,
  907. NonConvert = 0x1D,
  908. Accept = 0x1E,
  909. ModeChange = 0x1F,
  910. Space = 0x20,
  911. Prior = 0x21,
  912. Next = 0x22,
  913. End = 0x23,
  914. Home = 0x24,
  915. Left = 0x25,
  916. Up = 0x26,
  917. Right = 0x27,
  918. Down = 0x28,
  919. Select = 0x29,
  920. Print = 0x2A,
  921. Execute = 0x2B,
  922. Snapshot = 0x2C,
  923. Insert = 0x2D,
  924. Delete = 0x2E,
  925. Help = 0x2F,
  926. Num0 = '0',
  927. Num1 = '1',
  928. Num2 = '2',
  929. Num3 = '3',
  930. Num4 = '4',
  931. Num5 = '5',
  932. Num6 = '6',
  933. Num7 = '7',
  934. Num8 = '8',
  935. Num9 = '9',
  936. A = 'A',
  937. B = 'B',
  938. C = 'C',
  939. D = 'D',
  940. E = 'E',
  941. F = 'F',
  942. G = 'G',
  943. H = 'H',
  944. I = 'I',
  945. J = 'J',
  946. K = 'K',
  947. L = 'L',
  948. M = 'M',
  949. N = 'N',
  950. O = 'O',
  951. P = 'P',
  952. Q = 'Q',
  953. R = 'R',
  954. S = 'S',
  955. T = 'T',
  956. U = 'U',
  957. V = 'V',
  958. W = 'W',
  959. X = 'X',
  960. Y = 'Y',
  961. Z = 'Z',
  962. Lwin = 0x5B,
  963. Rwin = 0x5C,
  964. Apps = 0x5D,
  965. Numpad0 = 0x60,
  966. Numpad1 = 0x61,
  967. Numpad2 = 0x62,
  968. Numpad3 = 0x63,
  969. Numpad4 = 0x64,
  970. Numpad5 = 0x65,
  971. Numpad6 = 0x66,
  972. Numpad7 = 0x67,
  973. Numpad8 = 0x68,
  974. Numpad9 = 0x69,
  975. Multiply = 0x6A,
  976. Add = 0x6B,
  977. Separator = 0x6C,
  978. Subtract = 0x6D,
  979. Decimal = 0x6E,
  980. Divide = 0x6F,
  981. F1 = 0x70,
  982. F2 = 0x71,
  983. F3 = 0x72,
  984. F4 = 0x73,
  985. F5 = 0x74,
  986. F6 = 0x75,
  987. F7 = 0x76,
  988. F8 = 0x77,
  989. F9 = 0x78,
  990. F10 = 0x79,
  991. F11 = 0x7A,
  992. F12 = 0x7B,
  993. F13 = 0x7C,
  994. F14 = 0x7D,
  995. F15 = 0x7E,
  996. F16 = 0x7F,
  997. F17 = 0x80,
  998. F18 = 0x81,
  999. F19 = 0x82,
  1000. F20 = 0x83,
  1001. F21 = 0x84,
  1002. F22 = 0x85,
  1003. F23 = 0x86,
  1004. F24 = 0x87,
  1005. Numlock = 0x90,
  1006. Scroll = 0x91,
  1007. Lshift = 0xA0,
  1008. Rshift = 0xA1,
  1009. Lcontrol = 0xA2,
  1010. Rcontrol = 0xA3,
  1011. Lmenu = 0xA4,
  1012. Rmenu = 0xA5,
  1013. ProcessKey = 0xE5,
  1014. Attn = 0xF6,
  1015. Crsel = 0xF7,
  1016. Exsel = 0xF8,
  1017. Ereof = 0xF9,
  1018. Play = 0xFA,
  1019. Zoom = 0xFB,
  1020. Noname = 0xFC,
  1021. Pa1 = 0xFD,
  1022. OemClear = 0xFE,
  1023. }