Trait WindowsApi
pub trait WindowsApi: Send + Sync {
Show 35 methods
// Required methods
fn set_console_title(&self, title: &str) -> Result<()>;
fn get_console_title(&self, buffer: &mut [u16]) -> i32;
fn get_os_version(&self) -> String;
fn arrange_console(
&self,
x: i32,
y: i32,
width: i32,
height: i32,
) -> Result<()>;
fn set_console_text_attribute(
&self,
attributes: CONSOLE_CHARACTER_ATTRIBUTES,
) -> Result<()>;
fn get_console_screen_buffer_info(
&self,
) -> Result<CONSOLE_SCREEN_BUFFER_INFO>;
fn fill_console_output_attribute(
&self,
attribute: u16,
length: u32,
coord: COORD,
) -> Result<u32>;
fn scroll_console_screen_buffer(
&self,
scroll_rect: SMALL_RECT,
scroll_target: COORD,
fill_char: CHAR_INFO,
) -> Result<()>;
fn set_console_cursor_position(&self, position: COORD) -> Result<()>;
fn get_std_handle(&self, handle_type: STD_HANDLE) -> Result<HANDLE>;
fn read_console_input(&self, buffer: &mut [INPUT_RECORD]) -> Result<u32>;
fn set_console_border_color(&self, color: &COLORREF) -> Result<()>;
fn write_console_input(
&self,
buffer: &[INPUT_RECORD],
number_written: &mut u32,
) -> Result<()>;
fn get_last_error(&self) -> u32;
fn generate_console_ctrl_event(
&self,
ctrl_event: u32,
process_group_id: u32,
) -> Result<()>;
fn get_stdout_handle(&self) -> Result<HANDLE>;
fn get_console_screen_buffer_info_with_handle(
&self,
handle: HANDLE,
) -> Result<CONSOLE_SCREEN_BUFFER_INFO>;
fn create_process_raw(
&self,
application: &str,
command_line: PWSTR,
startup_info: &mut STARTUPINFOW,
process_info: &mut PROCESS_INFORMATION,
) -> Result<()>;
fn get_window_handle_for_process(&self, process_id: u32) -> HWND;
fn get_console_window(&self) -> HWND;
fn get_foreground_window(&self) -> HWND;
fn set_foreground_window(&self, hwnd: HWND) -> Result<()>;
fn get_console_mode(&self, handle: HANDLE) -> Result<CONSOLE_MODE>;
fn set_console_mode(&self, handle: HANDLE, mode: CONSOLE_MODE) -> Result<()>;
fn get_exit_code(&self, handle: HANDLE) -> Result<u32>;
fn move_window(
&self,
hwnd: HWND,
x: i32,
y: i32,
width: i32,
height: i32,
repaint: bool,
) -> Result<()>;
fn get_window_placement(&self, hwnd: HWND) -> Result<WINDOWPLACEMENT>;
fn show_window(&self, hwnd: HWND, cmd_show: SHOW_WINDOW_CMD) -> Result<bool>;
fn focus_window_with_automation(&self, hwnd: HWND) -> Result<()>;
fn is_window(&self, hwnd: HWND) -> bool;
fn open_process(
&self,
access: u32,
inherit: bool,
process_id: u32,
) -> Result<HANDLE>;
fn initialize_com_library(&self, coinit: COINIT) -> Result<()>;
fn get_system_metrics(&self, index: SYSTEM_METRICS_INDEX) -> i32;
fn set_process_dpi_awareness(
&self,
value: PROCESS_DPI_AWARENESS,
) -> Result<()>;
// Provided method
fn create_process_with_args(
&self,
application: &str,
args: Vec<String>,
) -> Option<PROCESS_INFORMATION> { ... }
}Expand description
Trait for Windows API operations to enable mocking in tests.
This trait abstracts Windows API calls to allow for unit testing without actual system interaction. All console and system operations should go through this trait.
Required Methods§
fn set_console_title(&self, title: &str) -> Result<()>
fn set_console_title(&self, title: &str) -> Result<()>
fn get_console_title(&self, buffer: &mut [u16]) -> i32
fn get_console_title(&self, buffer: &mut [u16]) -> i32
fn get_os_version(&self) -> String
fn get_os_version(&self) -> String
fn arrange_console(&self, x: i32, y: i32, width: i32, height: i32) -> Result<()>
fn arrange_console(&self, x: i32, y: i32, width: i32, height: i32) -> Result<()>
Arranges the console window position and size.
§Arguments
x- The x coordinate to move the window toy- The y coordinate to move the window towidth- The width in pixels to resize the window toheight- The height in pixels to resize the window to
§Returns
Result indicating success or failure of the operation