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.
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!
toml
[dependencies]
wallpaper-app = "0.1.7"
winapi = { version = "0.3.9", features = ["winuser", "processthreadsapi", "libloaderapi", "errhandlingapi", "impl-default"] }
```rust 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 wallpaperapp::createdesktopwindowfast;
fn main() { // Sets the process-default DPI awareness to system-DPI awareness. // Allows you to ignore interface scaling in Windows. unsafe { SetProcessDPIAware(); } let windowhandle = createdesktopwindowfast("Live", Some(windowprocedure)); // Some code... buildapp(); loopgraphics(windowhandle); }
// A callback function, which you define in your application, that processes messages sent to a window. pub unsafe extern "system" fn windowprocedure(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM,) -> LRESULT { match msg { WMNCCREATE => { println!("NC Create"); // About this code and GWLPUSERDATA you can read here: // https://learn.microsoft.com/en-us/windows/win32/learnwin32/managing-application-state- let createstruct: *mut CREATESTRUCTW = lparam as mut _; if createstruct.is_null() { return 0; } let boxed_i32_ptr = (createstruct).lpCreateParams; SetWindowLongPtrW(hwnd, GWLPUSERDATA, boxedi32ptr as LONGPTR); return 1; } WMCREATE => println!("WM Create"), WMCLOSE => drop(DestroyWindow(hwnd)), WMDESTROY => { let ptr = GetWindowLongPtrW(hwnd, GWLPUSERDATA) as *mut i32; drop(Box::fromraw(ptr)); println!("Cleaned up the box."); PostQuitMessage(0); } WMERASEBKGND => return 1, WMPAINT => paintframe(hwnd, getappdata()), // paintframe() - your function _ => return DefWindowProcW(hwnd, msg, wparam, l_param), }
0
} ```