GithubHelp home page GithubHelp logo

y15un / winsafe Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rodrigocfd/winsafe

0.0 0.0 0.0 49.54 MB

Windows API and GUI in safe, idiomatic Rust.

Home Page: https://crates.io/crates/winsafe

License: MIT License

Rust 100.00%

winsafe's Introduction

WinSafe

Crates.io Docs.rs Lines of code License: MIT

Windows API and GUI in safe, idiomatic Rust.

WinSafe has:

  • high-level structs to build native Win32 GUI applications;
  • low-level Win32 API constants, functions and structs related to GUI.

If you're looking for a comprehensive Win32 coverage, take a look at winapi or windows crates, which are unsafe, but have everything.

WinSafe documentation:

Current status

This crate is still in alpha stage. Below is an estimated progress of feature groups:

Feature group Estimated progress
User windows (main, modal and control) Progress
Native controls Progress
Window messages Progress
Overall Win32 APIs Progress

Usage

Add the dependency in your Cargo.toml:

[dependencies]
winsafe = { version = "0.0.9", features = [] }

Then you must enable the Cargo features you want to be included โ€“ these modules are named after native Windows DLL and library names, mostly.

The following Cargo features are available so far:

Feature Description
advapi Advapi32.dll, for Windows Registry
comctl ComCtl32.dll, for Common Controls
comdlg ComDlg32.dll, for the old Common Dialogs
dshow DirectShow
gdi Gdi32.dll, the Windows GDI
gui The WinSafe high-level GUI structs
kernel Kernel32.dll, all others will include it
msimg Msimg32.dll
ole OLE and basic COM support
oleaut OLE Automation
shell Shell32.dll, the COM-based Windows Shell
shlwapi Shlwapi.dll, for some Shell functions
user User32.dll, the basic Windows GUI support
uxtheme UxTheme.dll, extended window theming
version Version.dll, to manipulate *.exe version info

Note that a Cargo feature may depend on other features, which will be enabled automatically.

Example

Note: You can find several examples in the dedicated repo: github.com/rodrigocfd/winsafe-examples

WinSafe allows you to create windows in two ways:

  • programmatically defining parameters; or
  • loading dialogs from a .res file created with a WYSIWYG resource editor.

The example below creates a window with a button programmatically. Note how the click event is handled with a closure:

Example 01

[dependencies]
winsafe = { version = "0.0.9", features = ["gui"] }
#![windows_subsystem = "windows"]

use winsafe::prelude::*;
use winsafe::{gui, POINT, SIZE, WinResult};

fn main() {
    let my = MyWindow::new();  // instantiate our main window
    if let Err(e) = my.wnd.run_main(None) { // ... and run it
        eprintln!("{}", e);
    }
}


#[derive(Clone)]
pub struct MyWindow {
    wnd:       gui::WindowMain, // responsible for managing the window
    btn_hello: gui::Button,     // a button
}

impl MyWindow {
    pub fn new() -> MyWindow {
        let wnd = gui::WindowMain::new( // instantiate the window manager
            gui::WindowMainOpts {
                title: "My window title".to_owned(),
                size: SIZE::new(300, 150),
                ..Default::default() // leave all other options as default
            },
        );

        let btn_hello = gui::Button::new(
            &wnd, // the window manager is the parent of our button
            gui::ButtonOpts {
                text: "&Click me".to_owned(),
                position: POINT::new(20, 20),
                ..Default::default()
            },
        );

        let new_self = Self { wnd, btn_hello };
        new_self.events(); // attach our events
        new_self
    }

    fn events(&self) {
        self.btn_hello.on().bn_clicked({
            let wnd = self.wnd.clone(); // clone so it can be passed into the closure
            move || {
                wnd.hwnd().SetWindowText("Hello, world!")?;
                Ok(())
            }
        });
    }
}

License

Licensed under MIT license, see LICENSE.md for details.

winsafe's People

Contributors

rodrigocfd avatar y15un avatar roblabla avatar sollyucko avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.