microsoft / windows-rs

Rust for Windows
https://kennykerr.ca/rust-getting-started/
Apache License 2.0
10.41k stars 488 forks source link

Feature request: String constants like `PROGRESS_CLASSA` should be directly usable #2088

Closed monax3 closed 2 years ago

monax3 commented 2 years ago

Motivation

Currently, string constants such as the common control class names are generated as &str which results in duplicated frustrating to use constants:

pub const PROGRESS_CLASS: &'static str = "msctls_progress32";
pub const PROGRESS_CLASSA: &'static str = "msctls_progress32";
pub const PROGRESS_CLASSW: &'static str = "msctls_progress32";

The purpose of these constants is to be able to use them directly when creating a window so they should exist in a form where they can be passed directly to CreateWindowExA/CreateWindowExW, either as a PCSTR/PCWSTR (preferably) or as a &CStr/&HSTRING or [u8]/[u16].

Before:

let progress_class = std::ffi::CString::new(PROGRESS_CLASS).unwrap();
let hwnd = CreateWindowA(.., PCSTR(progress_class.as_ptr().cast::<u8>()), ..);

After:

let hwnd = CreateWindowA(.., PROGRES_CLASSA, ..);

Drawbacks

No response

Rationale and alternatives

No response

Additional context

No response

kennykerr commented 2 years ago

Yes, I have already created an issue for the win32 metadata to capture this information here: https://github.com/microsoft/win32metadata/issues/1008

Feel free to chime in on that issue and hopefully they will get it implemented.