Setup unique class naming for windows on Windows
This commit is contained in:
parent
5d429fd5ae
commit
f75177e9b6
|
@ -9,4 +9,4 @@ edition = "2018"
|
|||
[dependencies]
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
winapi = { version = "0.3.8", features = ["libloaderapi", "winuser", "windef", "minwindef"] }
|
||||
winapi = { version = "0.3.8", features = ["libloaderapi", "winuser", "windef", "minwindef", "guiddef", "combaseapi"] }
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
extern crate winapi;
|
||||
|
||||
use self::winapi::_core::mem::MaybeUninit;
|
||||
use self::winapi::shared::guiddef::GUID;
|
||||
use self::winapi::shared::minwindef::{LPARAM, LPVOID, LRESULT, UINT, WPARAM};
|
||||
use self::winapi::shared::windef::{HBRUSH, HICON, HMENU, HWND};
|
||||
use self::winapi::um::combaseapi::CoCreateGuid;
|
||||
use self::winapi::um::libloaderapi::GetModuleHandleA;
|
||||
use self::winapi::um::winuser::{
|
||||
CreateWindowExA, DefWindowProcA, DispatchMessageA, PeekMessageA, PostQuitMessage,
|
||||
|
@ -47,13 +49,31 @@ pub unsafe extern "system" fn wnd_proc(
|
|||
|
||||
pub fn create_window(w: WindowOpenOptions) {
|
||||
unsafe {
|
||||
// We generate a unique name for the new window class to prevent name collisions
|
||||
let mut guid: GUID = MaybeUninit::uninit().assume_init();
|
||||
CoCreateGuid(&mut guid);
|
||||
let class_name = format!(
|
||||
"Baseview-{}-{}-{}-{}{}{}{}{}{}{}{}\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 hinstance = GetModuleHandleA(0 as *const i8);
|
||||
let wnd_class = WNDCLASSA {
|
||||
// todo: for OpenGL, will use it later
|
||||
style: CS_OWNDC | CS_HREDRAW | CS_VREDRAW,
|
||||
lpfnWndProc: Some(wnd_proc),
|
||||
hInstance: hinstance,
|
||||
lpszClassName: "BaseviewClass\0".as_ptr() as *const i8,
|
||||
lpszClassName: class_name.as_ptr() as *const i8,
|
||||
cbClsExtra: 0,
|
||||
cbWndExtra: 0,
|
||||
hIcon: 0 as HICON,
|
||||
|
@ -65,7 +85,8 @@ pub fn create_window(w: WindowOpenOptions) {
|
|||
|
||||
let _hwnd = CreateWindowExA(
|
||||
0,
|
||||
"BaseviewClass\0".as_ptr() as *const i8,
|
||||
class_name.as_ptr() as *const i8,
|
||||
// todo: change title based on options struct
|
||||
"Baseview\0".as_ptr() as *const i8,
|
||||
// todo: fine for now, will have to change with a parent
|
||||
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
||||
|
|
Loading…
Reference in a new issue