Question

I am trying to apply a region to a window outside my application using

[DllImport("user32.dll")]
static extern IntPtr SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);

[DllImport("gdi32.dll")]
static extern IntPtr CreateRectRgn(int x1, int y1, int x2, int y2);

internal void Cut(IntPtr handle)
{
    SetWindowRgn(handle, CreateRectRgn(0, 0, 100, 200), true);
}

But it does not cut the window border in Windows 7. Note it is not clickable but does move when the border that is within the region is dragged.

notepad is not cut properly

What am I missing?

Was it helpful?

Solution

Looks like you can't according to this similar question. So I figured there's two options.

1. Turn off Aero

Windows basic theme works

2. Get rid of the border

In my case I didn't need the border so I used SetWindowLong to remove it

var style = GetWindowLong(handle, GWL_STYLE);
style &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
SetWindowLong(handle, GWL_STYLE, style);

Notepad with region + removed border

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top