Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrdlicka committed Nov 28, 2024
0 parents commit f1c353a
Show file tree
Hide file tree
Showing 6 changed files with 327 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[target.i686-pc-windows-msvc]
rustflags="-C target-feature=+crt-static"

[target.x86-64-pc-windows-msvc]
rustflags="-C target-feature=+crt-static"

[target.i686-pc-windows-gnu]
rustflags="-C target-feature=+crt-static"

[target.x86-64-pc-windows-gnu]
rustflags="-C target-feature=+crt-static"
37 changes: 37 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: i686-pc-windows-msvc
- name: Build x64
run: cargo build --verbose --release --target x86_64-pc-windows-msvc
- name: Build x86
run: cargo build --verbose --release --target i686-pc-windows-msvc
- uses: actions/upload-artifact@v4
with:
path: target/*/release/*.exe

fmt:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt
- uses: actions-rust-lang/rustfmt@v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
173 changes: 173 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "aerotest"
version = "0.1.0"
edition = "2021"

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

[dependencies]
windows = { version = "0.58.0", features = ["Win32_UI_WindowsAndMessaging", "Win32_Graphics_Dwm", "Win32_Graphics_Gdi", "Win32_UI_Controls", "Win32_System_LibraryLoader"] }
96 changes: 96 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#![windows_subsystem = "windows"]

use std::ffi::c_void;
use std::mem::size_of;

use windows::core::*;
use windows::Win32::Foundation::*;
use windows::Win32::Graphics::Dwm::*;
use windows::Win32::Graphics::Gdi::*;
use windows::Win32::System::LibraryLoader::*;
use windows::Win32::UI::Controls::*;
use windows::Win32::UI::WindowsAndMessaging::*;

const AERO_WINDOW_CLASS_NAME: PCSTR = s!("AeroWindow");

fn main() -> Result<()> {
unsafe {
let instance = GetModuleHandleA(None)?;
let black_brush = HBRUSH(GetStockObject(BLACK_BRUSH).0); // Don't ask me why

let class = WNDCLASSA {
lpfnWndProc: Some(wndproc),
hInstance: instance.into(),
lpszClassName: AERO_WINDOW_CLASS_NAME,
hbrBackground: black_brush,
..Default::default()
};

if RegisterClassA(&class) == 0 {
return Err(Error::from_win32());
}

let hwnd = CreateWindowExA(
WS_EX_OVERLAPPEDWINDOW,
AERO_WINDOW_CLASS_NAME,
s!("Aero Window"),
WS_OVERLAPPEDWINDOW,
0,
0,
600,
400,
None,
None,
instance,
None,
)?;

let margins = MARGINS {
cxLeftWidth: -1,
cxRightWidth: -1,
cyTopHeight: -1,
cyBottomHeight: -1,
};

DwmExtendFrameIntoClientArea(hwnd, &margins)?;

// Enable dark mode and Mica on Windows 11+
_ = DwmSetWindowAttribute(
hwnd,
DWMWA_USE_IMMERSIVE_DARK_MODE,
(&TRUE) as *const _ as *const c_void,
size_of::<BOOL>().try_into()?,
);
_ = DwmSetWindowAttribute(
hwnd,
DWMWA_SYSTEMBACKDROP_TYPE,
(&DWMSBT_MAINWINDOW) as *const _ as *const c_void,
size_of::<DWM_SYSTEMBACKDROP_TYPE>().try_into()?,
);

_ = ShowWindow(hwnd, SW_NORMAL);

let mut msg = Default::default();

while GetMessageA(&mut msg, None, 0, 0).into() {
_ = TranslateMessage(&msg);
DispatchMessageA(&msg);
}

Ok(())
}
}

unsafe extern "system" fn wndproc(hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> LRESULT {
match msg {
WM_CLOSE => {
DestroyWindow(hwnd).unwrap();
LRESULT(0)
}
WM_DESTROY => {
PostQuitMessage(0);
LRESULT(0)
}
_ => DefWindowProcA(hwnd, msg, wparam, lparam),
}
}

0 comments on commit f1c353a

Please sign in to comment.