#desktop-applications #desktop #wallpaper #window #winapi #create #own

wallpaper-app

This library provides the functionality to create your own application, displayed as a desktop wallpaper

9 releases

0.1.8 Jul 4, 2023
0.1.7 Jun 25, 2023

#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 downloads per month

Apache-2.0

32KB
465 lines

wallpaper-app

This library is designed to make it easy to create your own desktop. You can use it to create an application window and place it in the desktop so that your window is below the icons.

For now, it supports only Windows!

Examples

An example of using the library in a project: https://github.com/KiritoMC03/live-wallpapers

This library uses winapi crate for best control, but you don't have to use only it in your projects, because there are already many wrapper-crates for creating windowed applications!

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

Code example:

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
}

Dependencies

~245–485KB