general.odin 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  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 do return "";
  723. return wstring_to_utf8(cast(Wstring)&s[0], len(s), allocator);
  724. }
  725. get_query_performance_frequency :: proc() -> i64 {
  726. r: i64;
  727. query_performance_frequency(&r);
  728. return r;
  729. }
  730. HIWORD_W :: proc(wParam: Wparam) -> u16 { return u16((u32(wParam) >> 16) & 0xffff); }
  731. HIWORD_L :: proc(lParam: Lparam) -> u16 { return u16((u32(lParam) >> 16) & 0xffff); }
  732. LOWORD_W :: proc(wParam: Wparam) -> u16 { return u16(wParam); }
  733. LOWORD_L :: proc(lParam: Lparam) -> u16 { return u16(lParam); }
  734. is_key_down :: #force_inline proc(key: Key_Code) -> bool { return get_async_key_state(i32(key)) < 0; }
  735. MAX_PATH :: 0x00000104;
  736. MAX_PATH_WIDE :: 0x8000;
  737. HANDLE_FLAG_INHERIT :: 1;
  738. HANDLE_FLAG_PROTECT_FROM_CLOSE :: 2;
  739. FILE_BEGIN :: 0;
  740. FILE_CURRENT :: 1;
  741. FILE_END :: 2;
  742. FILE_SHARE_READ :: 0x00000001;
  743. FILE_SHARE_WRITE :: 0x00000002;
  744. FILE_SHARE_DELETE :: 0x00000004;
  745. FILE_GENERIC_ALL :: 0x10000000;
  746. FILE_GENERIC_EXECUTE :: 0x20000000;
  747. FILE_GENERIC_WRITE :: 0x40000000;
  748. FILE_GENERIC_READ :: 0x80000000;
  749. FILE_APPEND_DATA :: 0x0004;
  750. STD_INPUT_HANDLE :: -10;
  751. STD_OUTPUT_HANDLE :: -11;
  752. STD_ERROR_HANDLE :: -12;
  753. CREATE_NEW :: 1;
  754. CREATE_ALWAYS :: 2;
  755. OPEN_EXISTING :: 3;
  756. OPEN_ALWAYS :: 4;
  757. TRUNCATE_EXISTING :: 5;
  758. INVALID_FILE_ATTRIBUTES :: -1;
  759. FILE_ATTRIBUTE_READONLY :: 0x00000001;
  760. FILE_ATTRIBUTE_HIDDEN :: 0x00000002;
  761. FILE_ATTRIBUTE_SYSTEM :: 0x00000004;
  762. FILE_ATTRIBUTE_DIRECTORY :: 0x00000010;
  763. FILE_ATTRIBUTE_ARCHIVE :: 0x00000020;
  764. FILE_ATTRIBUTE_DEVICE :: 0x00000040;
  765. FILE_ATTRIBUTE_NORMAL :: 0x00000080;
  766. FILE_ATTRIBUTE_TEMPORARY :: 0x00000100;
  767. FILE_ATTRIBUTE_SPARSE_FILE :: 0x00000200;
  768. FILE_ATTRIBUTE_REPARSE_Point :: 0x00000400;
  769. FILE_ATTRIBUTE_COMPRESSED :: 0x00000800;
  770. FILE_ATTRIBUTE_OFFLINE :: 0x00001000;
  771. FILE_ATTRIBUTE_NOT_CONTENT_INDEXED :: 0x00002000;
  772. FILE_ATTRIBUTE_ENCRYPTED :: 0x00004000;
  773. FILE_TYPE_DISK :: 0x0001;
  774. FILE_TYPE_CHAR :: 0x0002;
  775. FILE_TYPE_PIPE :: 0x0003;
  776. Monitor_Info :: struct {
  777. size: u32,
  778. monitor: Rect,
  779. work: Rect,
  780. flags: u32,
  781. }
  782. Window_Placement :: struct {
  783. length: u32,
  784. flags: u32,
  785. show_cmd: u32,
  786. min_pos: Point,
  787. max_pos: Point,
  788. normal_pos: Rect,
  789. }
  790. Bitmap_Info_Header :: struct {
  791. size: u32,
  792. width, height: i32,
  793. planes, bit_count: i16,
  794. compression: u32,
  795. size_image: u32,
  796. x_pels_per_meter: i32,
  797. y_pels_per_meter: i32,
  798. clr_used: u32,
  799. clr_important: u32,
  800. }
  801. Bitmap_Info :: struct {
  802. using header: Bitmap_Info_Header,
  803. colors: [1]Rgb_Quad,
  804. }
  805. Paint_Struct :: struct {
  806. hdc: Hdc,
  807. erase: Bool,
  808. rc_paint: Rect,
  809. restore: Bool,
  810. inc_update: Bool,
  811. rgb_reserved: [32]byte,
  812. }
  813. Rgb_Quad :: struct {blue, green, red, reserved: byte}
  814. Key_Code :: enum i32 {
  815. Unknown = 0x00,
  816. Lbutton = 0x01,
  817. Rbutton = 0x02,
  818. Cancel = 0x03,
  819. Mbutton = 0x04,
  820. Xbutton1 = 0x05,
  821. Xbutton2 = 0x06,
  822. Back = 0x08,
  823. Tab = 0x09,
  824. Clear = 0x0C,
  825. Return = 0x0D,
  826. Shift = 0x10,
  827. Control = 0x11,
  828. Menu = 0x12,
  829. Pause = 0x13,
  830. Capital = 0x14,
  831. Kana = 0x15,
  832. Hangeul = 0x15,
  833. Hangul = 0x15,
  834. Junja = 0x17,
  835. Final = 0x18,
  836. Hanja = 0x19,
  837. Kanji = 0x19,
  838. Escape = 0x1B,
  839. Convert = 0x1C,
  840. NonConvert = 0x1D,
  841. Accept = 0x1E,
  842. ModeChange = 0x1F,
  843. Space = 0x20,
  844. Prior = 0x21,
  845. Next = 0x22,
  846. End = 0x23,
  847. Home = 0x24,
  848. Left = 0x25,
  849. Up = 0x26,
  850. Right = 0x27,
  851. Down = 0x28,
  852. Select = 0x29,
  853. Print = 0x2A,
  854. Execute = 0x2B,
  855. Snapshot = 0x2C,
  856. Insert = 0x2D,
  857. Delete = 0x2E,
  858. Help = 0x2F,
  859. Num0 = '0',
  860. Num1 = '1',
  861. Num2 = '2',
  862. Num3 = '3',
  863. Num4 = '4',
  864. Num5 = '5',
  865. Num6 = '6',
  866. Num7 = '7',
  867. Num8 = '8',
  868. Num9 = '9',
  869. A = 'A',
  870. B = 'B',
  871. C = 'C',
  872. D = 'D',
  873. E = 'E',
  874. F = 'F',
  875. G = 'G',
  876. H = 'H',
  877. I = 'I',
  878. J = 'J',
  879. K = 'K',
  880. L = 'L',
  881. M = 'M',
  882. N = 'N',
  883. O = 'O',
  884. P = 'P',
  885. Q = 'Q',
  886. R = 'R',
  887. S = 'S',
  888. T = 'T',
  889. U = 'U',
  890. V = 'V',
  891. W = 'W',
  892. X = 'X',
  893. Y = 'Y',
  894. Z = 'Z',
  895. Lwin = 0x5B,
  896. Rwin = 0x5C,
  897. Apps = 0x5D,
  898. Numpad0 = 0x60,
  899. Numpad1 = 0x61,
  900. Numpad2 = 0x62,
  901. Numpad3 = 0x63,
  902. Numpad4 = 0x64,
  903. Numpad5 = 0x65,
  904. Numpad6 = 0x66,
  905. Numpad7 = 0x67,
  906. Numpad8 = 0x68,
  907. Numpad9 = 0x69,
  908. Multiply = 0x6A,
  909. Add = 0x6B,
  910. Separator = 0x6C,
  911. Subtract = 0x6D,
  912. Decimal = 0x6E,
  913. Divide = 0x6F,
  914. F1 = 0x70,
  915. F2 = 0x71,
  916. F3 = 0x72,
  917. F4 = 0x73,
  918. F5 = 0x74,
  919. F6 = 0x75,
  920. F7 = 0x76,
  921. F8 = 0x77,
  922. F9 = 0x78,
  923. F10 = 0x79,
  924. F11 = 0x7A,
  925. F12 = 0x7B,
  926. F13 = 0x7C,
  927. F14 = 0x7D,
  928. F15 = 0x7E,
  929. F16 = 0x7F,
  930. F17 = 0x80,
  931. F18 = 0x81,
  932. F19 = 0x82,
  933. F20 = 0x83,
  934. F21 = 0x84,
  935. F22 = 0x85,
  936. F23 = 0x86,
  937. F24 = 0x87,
  938. Numlock = 0x90,
  939. Scroll = 0x91,
  940. Lshift = 0xA0,
  941. Rshift = 0xA1,
  942. Lcontrol = 0xA2,
  943. Rcontrol = 0xA3,
  944. Lmenu = 0xA4,
  945. Rmenu = 0xA5,
  946. ProcessKey = 0xE5,
  947. Attn = 0xF6,
  948. Crsel = 0xF7,
  949. Exsel = 0xF8,
  950. Ereof = 0xF9,
  951. Play = 0xFA,
  952. Zoom = 0xFB,
  953. Noname = 0xFC,
  954. Pa1 = 0xFD,
  955. OemClear = 0xFE,
  956. }