# Native Windows GUI
Welcome to Native Windows GUI (aka NWG). A rust library to develop native GUI applications on the desktop for Microsoft Windows.
NWG is a very light wrapper over WINAPI. It allows you, the developer, to handle
the quirks and rough edges of the API by providing a simple, safe and rust-like interface.
Native Windows GUI keeps things simple. This means small compile times, minimal resource usage,
less time searching the documentation and more time for you to develop your application.
Of course, you don't have to take my word for it, check out the [showcase](../showcase) and the
[examples](examples).
This is the 3rd and final version of NWG. It is considered "mature" or, as I would say
"the backlog is empty, and it will most likely stay that way". This version implements pretty much
everything required to develop applications on Windows. Don't bother using the older versions as they
have "irreconcilable design decisions" and cannot support some key features. Future development will be done
in other libraries.
If you've managed to read through this introduction, you should know that my twitter handle
is [#gdube_dev](https://twitter.com/gdube_dev) and you can support this project with [*GitHub Sponsors*](https://github.com/sponsors/gabdube).
Any support is greatly appreciated.
## Installation
To use NWG in your project add it to cargo.toml:
```toml
[dependencies]
native-windows-gui = "1.0.12"
native-windows-derive = "1.0.3" # Optional. Only if the derive macro is used.
```
And then, in main.rs or lib.rs :
```rust
extern crate native_windows_gui as nwg;
extern crate native_windows_derive as nwd; // Optional. Only if the derive macro is used.
```
### Rust 2018 aliasing
You can skip the `extern crate` define in your source code by adding the following code in `Cargo.toml`
Note that procedural macros still require an `extern crate` definition, so this wont work with `native-windows-derive`
```toml
[dependencies]
nwg = {version = "^1.0.12", package = "native-windows-gui"}
```
## Trying it out
See it for yourself. NWG has plenty of examples and a fully interactive test suite. The only thing you need to do is:
```bash
git clone git@github.com:gabdube/native-windows-gui.git
cd native-windows-gui/native-windows-gui # Running the tests from the workspace screws up the features
cargo test everything --features "all" # For the test suite
cargo run --example basic
cargo run --example calculator
cargo run --example message_bank
cargo run --example image_decoder_d --features "extern-canvas"
cargo run --example partials --features "listbox frame combobox"
cargo run --example system_tray --features "tray-notification message-window menu cursor"
cargo run --example dialog_multithreading_d --features "notice"
cargo run --example image_decoder_d --features "image-decoder file-dialog"
cargo run --example month_name_d --features "winnls textbox"
cargo run --example splash_screen_d --features "image-decoder"
cargo run --example drop_files_d --features "textbox"
cd examples/opengl_canvas
cargo run
# The closest thing to a real application in the examples
cd ../examples/sync-draw
cargo run
# Requires the console to be run as Admin because of the embed resource
cd ../examples/embed_resources
cargo run
```
### Cross-compiling from Ubuntu
Requirement: MinGW compiler
sudo apt install gcc-mingw-w64-x86-64
Requirement: Rust support
rustup target add x86_64-pc-windows-gnu
Compiling and running basic example:
cargo build --release --target=x86_64-pc-windows-gnu
cargo build --release --target=x86_64-pc-windows-gnu --example basic
wine target/x86_64-pc-windows-gnu/release/examples/basic.exe
## Supported features
- The WHOLE winapi control library [(reference)](https://docs.microsoft.com/en-us/windows/win32/controls/individual-control-info)
- Some very niche controls are not supported: flat scroll bar, ip control, rebar, and pager.
- Menus and menu bar
- Image and font resource
- BMP
- ICO
- CUR
- PNG*
- GIF*
- JPG*
- TIFF*
- DDS*
- *: Extended image formats with the Windows Imaging Component (WIC).
- Localization support
- Uses Windows National Language Support internally [(reference)](https://docs.microsoft.com/en-us/windows/win32/intl/national-language-support)
- Tooltip
- System tray notification
- Cursor handling
- A full clipboard wrapper
- Partial templates support
- Split large application into chunks
- Dynamic controls support
- Add/Remove controls at runtime
- Bind or unbind new events at runtime
- Multithreaded application support
- Communicate to the GUI thread from another thread
- Run multiple windows on different threads
- Simple layout configurations
- FlexboxLayout
- GridLayout
- Drag and drop
- Drop files from the desktop to a window
- The most common dialog boxes
- File dialog (save, open, open folder)
- Font dialog
- Color dialog
- A canvas that can be used by external rendering APIs
- High-DPI aware
- Support for accessibility functions
- Tab navigation
- Support for low level system message capture (HWND, MSG, WPARAM, LPARAM)
- Cross compiling and testing from Linux to Windows with Wine and mingw.
- Not all features are supported (but the majority are, thanks WINE!)
- See `https://zork.net/~st/jottings/rust-windows-and-debian.html` for the steps to follow
## Performance
This was measured on a `Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz, 3401 Mhz, 4 Core(s), 8 Logical Processor(s)`
In release mode, the `basic` example weighs **163kb** on disk and takes **900kb** in memory. Launch time is instantaneous.
The interactive test suite (with every feature and 100s of tests) weighs **931 kb** on disk and takes **8MB** in memory. Launch time is still instantaneous.
Initial build time takes around **22 seconds** for a basic application. This is mainly due to `winapi-rs` initial compile time. Subsequent compile time takes around **0.7 seconds**.
## Development
The development of this library is considered "done". By that, I mean that
there won't be any change to the API. Issues can be raised if a bug is found or
if some area in the documentation is unclear. If I overlooked a very important feature,
it will most likely be added.
## License
NWG uses the MIT license
## Code example
### With native windows derive
```rust
#![windows_subsystem = "windows"]
/*!
A very simple application that shows your name in a message box.
Unlike `basic_d`, this example uses layout to position the controls in the window
*/
extern crate native_windows_gui as nwg;
extern crate native_windows_derive as nwd;
use nwd::NwgUi;
use nwg::NativeUi;
#[derive(Default, NwgUi)]
pub struct BasicApp {
#[nwg_control(size: (300, 115), position: (300, 300), title: "Basic example", flags: "WINDOW|VISIBLE")]
#[nwg_events( OnWindowClose: [BasicApp::say_goodbye] )]
window: nwg::Window,
#[nwg_layout(parent: window, spacing: 1)]
grid: nwg::GridLayout,
#[nwg_control(text: "Heisenberg", focus: true)]
#[nwg_layout_item(layout: grid, row: 0, col: 0)]
name_edit: nwg::TextInput,
#[nwg_control(text: "Say my name")]
#[nwg_layout_item(layout: grid, col: 0, row: 1, row_span: 2)]
#[nwg_events( OnButtonClick: [BasicApp::say_hello] )]
hello_button: nwg::Button
}
impl BasicApp {
fn say_hello(&self) {
nwg::modal_info_message(&self.window, "Hello", &format!("Hello {}", self.name_edit.text()));
}
fn say_goodbye(&self) {
nwg::modal_info_message(&self.window, "Goodbye", &format!("Goodbye {}", self.name_edit.text()));
nwg::stop_thread_dispatch();
}
}
fn main() {
nwg::init().expect("Failed to init Native Windows GUI");
nwg::Font::set_global_family("Segoe UI").expect("Failed to
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【Rust】rust开发封装的windows gui源码。 【实例简介】:rust开发封装的windows gui源码。 rust native-windows-gui 【核心代码】 ├── native-windows-gui │ ├── Cargo.toml │ ├── build.rs │ ├── examples │ │ ├── basic.rs │ │ ├── basic_barebone.rs │ │ ├── basic_d.rs │ │ ├── basic_drawing_d.rs │ │ ├── basic_layout.rs │ │ ├── basic_layout_d.rs │ │ ├── calculator.rs │ │ ├── calculator_d.rs │ │ ├── clipboard.rs │ │ ├── custom_font_d.rs │ │ ├── dataview_d.rs │ │ ├── dialog_multithreading_d
资源推荐
资源详情
资源评论
收起资源包目录
rust开发封装的windows gui源码 (252个子文件)
popcorn.bmp 64KB
ferris.bmp 44KB
ball.bmp 2KB
ice.cur 4KB
phong.frag 1KB
.gitignore 51B
.gitignore 21B
.gitignore 8B
suzanne.glb 280KB
teapot.glb 114KB
box.glb 2KB
pencil.ico 37KB
eraser.ico 37KB
love.ico 17KB
cog.ico 4KB
cat.jpg 14KB
embed_resources.exe.manifest 1KB
hdpi_plotting.exe.manifest 861B
readme.md 15KB
weird_cat.png 14KB
splash.png 13KB
list_3.png 613B
list_1.png 553B
list_2.png 379B
list_0.png 304B
embed_resources.rc 381B
hdpi_plotting.rc 68B
control_test.rs 59KB
list_view.rs 46KB
window.rs 43KB
treeview.rs 33KB
main.rs 30KB
flexbox_layout.rs 26KB
tabs.rs 25KB
plotters_d2d.rs 25KB
events.rs 23KB
rich_text_box.rs 23KB
combo_box.rs 23KB
text_input.rs 23KB
list_box.rs 22KB
grid_layout.rs 21KB
resources_helper.rs 19KB
date_picker.rs 17KB
rich_label.rs 17KB
label.rs 17KB
glb.rs 17KB
text_box.rs 17KB
number_select.rs 16KB
locale.rs 16KB
tooltip.rs 16KB
window_helper.rs 16KB
plotting_d.rs 16KB
tray_notification.rs 15KB
partials.rs 15KB
scroll_bar.rs 15KB
track_bar.rs 14KB
menu.rs 14KB
richedit.rs 14KB
check_box.rs 14KB
window.rs 14KB
radio_button.rs 14KB
main.rs 13KB
progress_bar.rs 13KB
button.rs 13KB
clipboard.rs 12KB
extern_canvas.rs 12KB
opengl_canvas.rs 12KB
image_frame.rs 12KB
dyn_layout.rs 11KB
embed.rs 11KB
animation_timer.rs 11KB
calculator.rs 10KB
bitmap.rs 10KB
image_decoder.rs 10KB
font.rs 9KB
main.rs 9KB
file_dialog.rs 9KB
message_box.rs 9KB
menu.rs 9KB
shared_memory.rs 8KB
image_list.rs 8KB
icon.rs 8KB
data.rs 7KB
plotters.rs 7KB
treeview_d2.rs 7KB
mod.rs 7KB
control_base.rs 7KB
partials_d.rs 7KB
cursor.rs 7KB
status_bar.rs 7KB
common_types.rs 7KB
frame.rs 6KB
echo_richtext_d.rs 6KB
mod.rs 6KB
calculator_d.rs 6KB
image_decoder.rs 6KB
cursor.rs 6KB
handle_from_control.rs 6KB
rich_label_d.rs 6KB
message_bank.rs 6KB
共 252 条
- 1
- 2
- 3
资源评论
hyzixue
- 粉丝: 41
- 资源: 165
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- bdwptqmxgj11.zip
- onnxruntime-win-x86
- onnxruntime-win-x64-gpu-1.20.1.zip
- vs2019 c++20 语法规范 头文件 <ratio> 的源码阅读与注释,处理分数的存储,加减乘除,以及大小比较等运算
- 首次尝试使用 Win,DirectX C++ 中的形状渲染套件.zip
- 预乘混合模式是一种用途广泛的三合一混合模式 它已经存在很长时间了,但似乎每隔几年就会被重新发现 该项目包括使用预乘 alpha 的描述,示例和工具 .zip
- 项目描述 DirectX 引擎支持版本 9、10、11 库 Microsoft SDK 功能相机视图、照明、加载网格、动画、蒙皮、层次结构界面、动画控制器、网格容器、碰撞系统 .zip
- 项目 wiki 文档中使用的代码教程的源代码库.zip
- 面向对象的通用GUI框架.zip
- 基于Java语言的PlayerBase游戏角色设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功