#桌面应用程序 #桌面 #壁纸 #窗口 #winapi #创建 #拥有

wallpaper-app

此库提供创建自己的应用程序的功能,作为桌面壁纸显示

9 个版本

0.1.8 2023 年 7 月 4 日
0.1.7 2023 年 6 月 25 日

#669 in GUI

Download history 3/week @ 2024-03-08 16/week @ 2024-03-15 33/week @ 2024-03-29 112/week @ 2024-04-19 11/week @ 2024-04-26

每月 59 次下载

Apache-2.0

32KB
465

wallpaper-app

此库旨在使创建自己的桌面变得容易。您可以使用它来创建应用程序窗口并将其放置在桌面上,使您的窗口位于图标下方。

目前,它只支持 Windows!

示例

在项目中使用此库的示例:https://github.com/KiritoMC03/live-wallpapers

此库使用 winapi crate 以获得最佳控制,但您不必在项目中仅使用它,因为已经有许多用于创建窗口应用程序的包装库!

[dependencies]
wallpaper-app = "0.1.7"
winapi = { version = "0.3.9", features = ["winuser", "processthreadsapi", "libloaderapi", "errhandlingapi", "impl-default"] }

代码示例

use winapi::shared::windef::HWND;
use winapi::shared::basetsd::LONG_PTR;

use winapi::shared::minwindef::{
    LPARAM,
    LRESULT,
    UINT,
    WPARAM,
};

use winapi::um::winuser::{
    CREATESTRUCTW,

    SetProcessDPIAware,
    DefWindowProcW,
    PostQuitMessage,
    DestroyWindow,
    GetWindowLongPtrW,
    SetWindowLongPtrW,

    GWLP_USERDATA,
    WM_CLOSE,
    WM_CREATE,
    WM_DESTROY,
    WM_NCCREATE,
    WM_PAINT,
    WM_ERASEBKGND,
};

use wallpaper_app::create_desktop_window_fast;

fn main() {
    // Sets the process-default DPI awareness to system-DPI awareness.
    // Allows you to ignore interface scaling in Windows.
    unsafe { SetProcessDPIAware(); }
    let window_handle = create_desktop_window_fast("Live", Some(window_procedure));
    // Some code...
    build_app();
    loop_graphics(window_handle);
}

// A callback function, which you define in your application, that processes messages sent to a window.
pub unsafe extern "system" fn window_procedure(hwnd: HWND, msg: UINT, w_param: WPARAM, l_param: LPARAM,) -> LRESULT {
    match msg {
        WM_NCCREATE => {
            println!("NC Create");
            // About this code and GWLP_USERDATA you can read here:
            // https://learn.microsoft.com/en-us/windows/win32/learnwin32/managing-application-state-
            let createstruct: *mut CREATESTRUCTW = l_param as *mut _;
            if createstruct.is_null() {
                return 0;
            }
            let boxed_i32_ptr = (*createstruct).lpCreateParams;
            SetWindowLongPtrW(hwnd, GWLP_USERDATA, boxed_i32_ptr as LONG_PTR);
            return 1;
        }
        WM_CREATE => println!("WM Create"),
        WM_CLOSE => drop(DestroyWindow(hwnd)),
        WM_DESTROY => {
            let ptr = GetWindowLongPtrW(hwnd, GWLP_USERDATA) as *mut i32;
            drop(Box::from_raw(ptr));
            println!("Cleaned up the box.");
            PostQuitMessage(0);
        }
        WM_ERASEBKGND => return 1,
        WM_PAINT => paint_frame(hwnd, get_app_data()), // paint_frame() - your function
        _ => return DefWindowProcW(hwnd, msg, w_param, l_param),
    }

    0
}

依赖项

~245–485KB