着实是不知道该怎么解决了, 从下午弄到现在... 背景总不是透明的. 本身没学过 windows 桌面应用开发, 边搜索边凑出来的,截图 , 拜托各位大佬能帮我看看怎么解决吗. 或者有什么别的思路可以给我个方向, 我想调整字号, 字体, 和大小.
或者有什么可以悬浮显示文字的应用有现成的吗? 可以鼠标穿透的
use std::ffi::OsStr;
use std::iter::once;
use std::os::windows::prelude::OsStrExt;
use windows::Win32::Graphics::Gdi::{GetDC, SetBkMode, SetTextColor, TextOutW, TRANSPARENT};
use windows::Win32::UI::WindowsAndMessaging::{GetDesktopWindow, SetWindowLongA};
unsafe fn print_message() {
let desk = GetDesktopWindow();
let dc = GetDC(desk);
SetTextColor(dc, 0x0000FF);
SetBkMode(dc, TRANSPARENT);
loop {
TextOutW(dc, 1000, 100, str_to_lpcwstr("中文").as_slice());
}
}
fn str_to_lpcwstr(str : &str) -> Vec<u16> {
OsStr::new(str).encode_wide().chain(once(0)).collect()
}
fn main() {
println!("Start!");
unsafe {
print_message()
}
}
[dependencies.windows]
version = "0.39.0"
features = [
"Data_Xml_Dom",
"Win32_Foundation",
"Win32_Security",
"Win32_System_Threading",
"Win32_UI_WindowsAndMessaging",
"Win32_Graphics_Gdi"
]
1
共 3 条评论, 1 页
评论区
写评论之前在reddit上看过一篇类似的回答 https://www.reddit.com/r/rust/comments/wj4x8v/comment/ijflfet/?utm_source=share&utm_medium=web2x&context=3
使用winit库可以以跨平台的方式设置窗口在最上层、透明
参考这个链接:https://www.cnblogs.com/findumars/p/5625176.html 核心是SetLayeredWindowAttributes 函数
参考下这个: https://docs.microsoft.com/en-us/archive/msdn-magazine/2014/june/windows-with-c-high-performance-window-layering-using-the-windows-composition-engine?utm_source=pocket_mylist