Skip to content

Commit

Permalink
Fix drawing, window state and mouse leaving bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Twometer committed Oct 2, 2020
1 parent ef756a8 commit c659286
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 9 deletions.
1 change: 1 addition & 0 deletions NoFences/FenceWindow.Designer.cs

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

21 changes: 16 additions & 5 deletions NoFences/FenceWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static NoFences.Win32.WindowUtil;
Expand Down Expand Up @@ -47,6 +48,7 @@ public FenceWindow(FenceInfo fenceInfo)
DropShadow.ApplyShadows(this);
BlurUtil.EnableBlur(Handle);
WindowUtil.HideFromAltTab(Handle);
DesktopUtil.GlueToDesktop(Handle);

var family = new FontFamily("Segoe UI");
titleFont = new Font(family, 17);
Expand All @@ -70,15 +72,22 @@ public FenceWindow(FenceInfo fenceInfo)

protected override void WndProc(ref Message m)
{
//Console.WriteLine(m.Msg.ToString("X4"));

// Remove border
if (m.Msg == 0x0083)
{
m.Result = IntPtr.Zero;
return;
}

// Mouse leave
if (m.Msg == 0x02a2) {
Minify();
}

// Prevent maximize
if ((m.Msg == WM_SYSCOMMAND) && m.WParam.ToInt32() == SC_MAXIMIZE)
if ((m.Msg == WM_SYSCOMMAND) && m.WParam.ToInt32() == 0xF032)
{
m.Result = IntPtr.Zero;
return;
Expand Down Expand Up @@ -205,6 +214,7 @@ private void Minify()
isMinified = true;
prevHeight = Height;
Height = titleHeight;
Refresh();
}
}

Expand Down Expand Up @@ -234,10 +244,6 @@ private void FenceWindow_DoubleClick(object sender, EventArgs e)

private void FenceWindow_Paint(object sender, PaintEventArgs e)
{
if ((DateTime.Now - lastRedraw).TotalMilliseconds < 1)
return;
lastRedraw = DateTime.Now;

e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

Expand Down Expand Up @@ -395,6 +401,11 @@ private void lockedToolStripMenuItem_Click(object sender, EventArgs e)
fenceInfo.Locked = lockedToolStripMenuItem.Checked;
Save();
}

private void FenceWindow_Load(object sender, EventArgs e)
{

}
}

}
Expand Down
1 change: 1 addition & 0 deletions NoFences/NoFences.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<Compile Include="Util\Extensions.cs" />
<Compile Include="Util\ThrottledExecution.cs" />
<Compile Include="Win32\BlurUtil.cs" />
<Compile Include="Win32\DesktopUtil.cs" />
<Compile Include="Win32\DropShadow.cs" />
<Compile Include="Win32\WindowUtil.cs" />
<EmbeddedResource Include="EditDialog.resx">
Expand Down
6 changes: 3 additions & 3 deletions NoFences/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NoFences")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyCopyright("Copyright © Twometer 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
32 changes: 32 additions & 0 deletions NoFences/Win32/DesktopUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace NoFences.Win32
{
public class DesktopUtil
{
[DllImport("user32.dll", SetLastError = true)]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpWindowClass, string lpWindowName);

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);


const int GWL_HWNDPARENT = -8;


public static void GlueToDesktop(IntPtr handle)
{
IntPtr hprog = FindWindowEx(FindWindowEx(FindWindow("Progman", "Program Manager"), IntPtr.Zero, "SHELLDLL_DefView", ""), IntPtr.Zero, "SysListView32", "FolderView");

SetWindowLong(handle, GWL_HWNDPARENT, hprog);
}
}
}
3 changes: 2 additions & 1 deletion NoFences/Win32/WindowUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class WindowUtil
public const int HTBOTTOMRIGHT = 17;

public const int WM_SYSCOMMAND = 274;
public const int SC_MAXIMIZE = 61490;
public const int SC_MAXIMIZE = 0xF030;
public const int SC_MINIMIZE = 0xF020;

public const UInt32 SWP_NOSIZE = 0x0001;
public const UInt32 SWP_NOMOVE = 0x0002;
Expand Down

0 comments on commit c659286

Please sign in to comment.