Featured image of post Rust में MessageBox प्रदर्शित करें

Rust में MessageBox प्रदर्शित करें

आप नीचे दिए गए चरणों का पालन करके Rust में MessageBox प्रदर्शित कर सकते हैं।

  1. Rust स्थापित करें। Rust के साथ शुरुआत कैसे करें देखें
  2. कमांड प्रॉम्प्ट में cargo new --bin MessageBox चलाएँ।
  3. MessageBox निर्देशिका में जाएँ।
  4. Cargo.toml खोलें और नीचे दिए गए अनुसार संशोधित करें।
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
[package]
name = "hello_world"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
winapi = "0.2.7"
user32-sys = "0.2.0"
  1. src\main.rs खोलें और नीचे दिए गए अनुसार संशोधित करें।
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
extern crate user32;
extern crate winapi;

use std::ffi::CString;
use user32::MessageBoxA;
use winapi::winuser::{MB_OK, MB_ICONINFORMATION};

fn main() {
    let lp_text = CString::new("Hello, world!").unwrap();
    let lp_caption = CString::new("MessageBox Example").unwrap();

    unsafe {
        MessageBoxA(
            std::ptr::null_mut(),
            lp_text.as_ptr(),
            lp_caption.as_ptr(),
            MB_OK | MB_ICONINFORMATION
        );
    }
}
  1. कमांड प्रॉम्प्ट में cargo run चलाएँ। img.png

  2. रिलीज़ बिल्ड बनाने के लिए cargo build --release चलाएँ।

संदर्भ

Hello World MesssageBox example in Rust

comments powered by Disqus
निर्मित Hugo के साथ
थीम Stack द्वारा डिज़ाइन किया गया Jimmy