general.odin 26 KB

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