windows - 使用 Windows API 在 Rust 中创建弹出窗口

标签 windows winapi rust

我想以类似于 PowerShell 的方式在 Rust 中创建一个对话框或弹出窗口.

我正在努力寻找有关 Windows API 的文档。到目前为止我找到的最接近的是 the CreateDialogA macro (Rust winapi equivalent)。

我在上面找到了一些东西,比如 Creating a New Dialog Box (C++) , 但其中大部分不适用于 Rust 项目。

也许 dialoge template相关吗?

最佳答案

主.rs

extern crate winapi;

use std::ptr::null_mut as NULL;
use winapi::um::winuser;

fn main() {
    let l_msg: Vec<u16> = "Wassa wassa wassup\0".encode_utf16().collect();
    let l_title: Vec<u16> = "\u{20BF}itconnect\0".encode_utf16().collect();

    unsafe {
        winuser::MessageBoxW(NULL(), l_msg.as_ptr(), l_title.as_ptr(), winuser::MB_OK | winuser::MB_ICONINFORMATION);
    }
}

这使用了 MessageBoxW function .

参数 winuser::MB_OK 可以是 winuser::MB_OKwinuser::MB_OKCANCELwinuser::MB_ABORTRETRYIGNOREwinuser::MB_YESNOCANCELwinuser::MB_YESNOwinuser::MB_RETRYCANCELwinuser::MB_CANCELTRYCONTINUE.

参数 winuser::MB_ICONINFORMATION 可以是 winuser::MB_ICONHANDwinuser::MB_ICONQUESTIONwinuser::MB_ICONEXCLAMATIONwinuser::MB_ICONASTERISK

Cargo.toml 应该包括:

[dependencies.winapi]
version = "0.3"
features = ["winuser"]

popup

关于windows - 使用 Windows API 在 Rust 中创建弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53648377/

相关文章:

python - 在 Windows 上运行带有子进程的 R 脚本,子进程似乎丢失

c++ - 在使用 C++ 和 .NET 的 Windows 系统编程中,如何进行 System.Diagnostics::Process.Start() 调用并在原始窗口中输出?

c++ - "CoInitialize failed"当一个函数(来自库)包含在 VC++ MFC 项目中时

c++ - 远程线程的 DuplicateHandle 失败,错误为 ERROR_INVALID_HANDLE

rust - 模乘法

windows - 处理 Windows 批处理脚本中的引号

winapi - GDI裁剪的实现细节

c++ - 如何通过 API 退出 Win32 应用程序?

heroku - Unresolved 导入 `core::task::Wake`

error-handling - 有没有办法从std::io::Error获取OS错误代码?