Skip to content

Instantly share code, notes, and snippets.

@t-mat
Last active February 4, 2023 18:39
Show Gist options
  • Select an option

  • Save t-mat/91510f161ecd0bfb2269f107d655fc7e to your computer and use it in GitHub Desktop.

Select an option

Save t-mat/91510f161ecd0bfb2269f107d655fc7e to your computer and use it in GitHub Desktop.
[Win32] [Powershell] Set Desktop Small Icon
@setlocal enabledelayedexpansion & set "ARGS=%*" & powershell -nop -ex Bypass -c "Add-Type (gc '%~dpf0'|select -Skip 1|Out-String); exit [Program]::Main();" & exit /b !ERRORLEVEL!
using System;
using System.Runtime.InteropServices;
public static class Program {
[DllImport("user32.dll")]
static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
[DllImport("user32.dll", EntryPoint="GetWindowLongPtr")]
static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint="SetWindowLongPtr")]
private static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);
const int GWL_STYLE = -16;
const int LVS_TYPEMASK = 0x0003;
const int LVS_SMALLICON = 0x0002;
const string WC_LISTVIEW = "SysListView32";
const int WM_MOUSEWHEEL = 0x020A;
const int WHEEL_DELTA = 120;
const int MK_CONTROL = 8;
const int CtrlWheelDown = ((-WHEEL_DELTA) << 16) | MK_CONTROL;
public static int Main() {
IntPtr h = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Progman", "Program Manager");
h = FindWindowEx(h, IntPtr.Zero, "SHELLDLL_DefView", null);
h = FindWindowEx(h, IntPtr.Zero, WC_LISTVIEW, null);
var s = (long) GetWindowLongPtr(h, GWL_STYLE);
s &= ~LVS_TYPEMASK;
s |= LVS_SMALLICON;
SetWindowLongPtr64(h, GWL_STYLE, (IntPtr) s);
for (int i = 0; i < 16; ++i) {
SendMessage(h, WM_MOUSEWHEEL, CtrlWheelDown, IntPtr.Zero);
}
return 0; // exit code => !ERRORLEVEL!
}
}
@gpuido
Copy link
Copy Markdown

gpuido commented Sep 11, 2017

Very cool thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment