1
0
Fork 0

Windows: Refactor: move guid generation to fn

This commit is contained in:
Mirko Covizzi 2020-06-08 23:02:42 +02:00
parent 2d4db1575d
commit 9324b1b129

View file

@ -29,6 +29,25 @@ unsafe fn message_box(title: &str, msg: &str) {
); );
} }
unsafe fn generate_guid() -> String {
let mut guid: GUID = std::mem::zeroed();
CoCreateGuid(&mut guid);
format!(
"{:0X}-{:0X}-{:0X}-{:0X}{:0X}-{:0X}{:0X}{:0X}{:0X}{:0X}{:0X}\0",
guid.Data1,
guid.Data2,
guid.Data3,
guid.Data4[0],
guid.Data4[1],
guid.Data4[2],
guid.Data4[3],
guid.Data4[4],
guid.Data4[5],
guid.Data4[6],
guid.Data4[7]
)
}
pub struct Window; pub struct Window;
impl Window { impl Window {
@ -36,22 +55,7 @@ impl Window {
pub fn open(options: WindowOpenOptions) -> Self { pub fn open(options: WindowOpenOptions) -> Self {
unsafe { unsafe {
// We generate a unique name for the new window class to prevent name collisions // We generate a unique name for the new window class to prevent name collisions
let mut guid: GUID = std::mem::zeroed(); let class_name = format!("Baseview-{}", generate_guid());
CoCreateGuid(&mut guid);
let class_name = format!(
"Baseview-{:0X}-{:0X}-{:0X}-{:0X}{:0X}-{:0X}{:0X}{:0X}{:0X}{:0X}{:0X}\0",
guid.Data1,
guid.Data2,
guid.Data3,
guid.Data4[0],
guid.Data4[1],
guid.Data4[2],
guid.Data4[3],
guid.Data4[4],
guid.Data4[5],
guid.Data4[6],
guid.Data4[7]
);
let wnd_class = WNDCLASSA { let wnd_class = WNDCLASSA {
// todo: for OpenGL, will use it later // todo: for OpenGL, will use it later