general.odin 24 KB

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