Merge pull request #14 from MirkoCovizzi/issue-13
Windows: Add message box
This commit is contained in:
commit
45ea5387b4
1 changed files with 31 additions and 20 deletions
|
@ -14,15 +14,41 @@ use self::winapi::um::wingdi::{
|
||||||
PIXELFORMATDESCRIPTOR,
|
PIXELFORMATDESCRIPTOR,
|
||||||
};
|
};
|
||||||
use self::winapi::um::winuser::{
|
use self::winapi::um::winuser::{
|
||||||
CreateWindowExA, DefWindowProcA, DispatchMessageA, GetDC, PeekMessageA, PostQuitMessage,
|
CreateWindowExA, DefWindowProcA, DispatchMessageA, GetDC, MessageBoxA, PeekMessageA,
|
||||||
RegisterClassA, TranslateMessage, CS_HREDRAW, CS_OWNDC, CS_VREDRAW, CW_USEDEFAULT, MSG,
|
PostQuitMessage, RegisterClassA, TranslateMessage, CS_HREDRAW, CS_OWNDC, CS_VREDRAW,
|
||||||
PM_REMOVE, WM_DESTROY, WM_QUIT, WNDCLASSA, WS_CAPTION, WS_CHILD, WS_CLIPSIBLINGS,
|
CW_USEDEFAULT, MB_ICONERROR, MB_OK, MB_TOPMOST, MSG, PM_REMOVE, WM_DESTROY, WM_QUIT, WNDCLASSA,
|
||||||
WS_MAXIMIZEBOX, WS_MINIMIZEBOX, WS_POPUPWINDOW, WS_SIZEBOX, WS_VISIBLE,
|
WS_CAPTION, WS_CHILD, WS_CLIPSIBLINGS, WS_MAXIMIZEBOX, WS_MINIMIZEBOX, WS_POPUPWINDOW,
|
||||||
|
WS_SIZEBOX, WS_VISIBLE,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::Parent::WithParent;
|
use crate::Parent::WithParent;
|
||||||
use crate::WindowOpenOptions;
|
use crate::WindowOpenOptions;
|
||||||
|
|
||||||
|
unsafe fn message_box(title: &str, msg: &str) {
|
||||||
|
let title = (title.to_owned() + "\0").as_ptr() as *const i8;
|
||||||
|
let msg = (msg.to_owned() + "\0").as_ptr() as *const i8;
|
||||||
|
MessageBoxA(null_mut(), msg, title, MB_ICONERROR | MB_OK | MB_TOPMOST);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
@ -30,22 +56,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
|
||||||
|
|
Loading…
Add table
Reference in a new issue