general.odin 26 KB

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