Skip to content
This repository has been archived by the owner on Sep 24, 2019. It is now read-only.

Commit

Permalink
Tentative implementation of the whole ignoring Win-D (Show Desktop) f…
Browse files Browse the repository at this point in the history
…unctionality
  • Loading branch information
growse committed Dec 24, 2011
1 parent 5c127c8 commit ba8bbf0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
26 changes: 25 additions & 1 deletion Feedling/Classes/NativeMethods.cs
Expand Up @@ -15,12 +15,24 @@ class NativeMethods
{
private NativeMethods() { }

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

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

[DllImportAttribute("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll", SetLastError = true)]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

[DllImport("user32.dll", SetLastError = true)]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

[DllImport("user32.dll", SetLastError = true)]
private static extern UInt32 GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
Expand All @@ -39,6 +51,7 @@ class NativeMethods
const UInt32 WS_EX_TOOLWINDOW = 0x00000080;
const Int32 GWL_EXSTYLE = (-20);
const Int32 WM_NCLBUTTONDOWN = 0xA1;
const int GWL_HWNDPARENT = -8;
static readonly IntPtr HT_CAPTION = new IntPtr(0x2);
static readonly IntPtr HWND_BOTTOM = new IntPtr(1);

Expand All @@ -48,7 +61,7 @@ public static void SendWpfWindowBack(Window window)
SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
}

public static void SetWindowLongToolWindow(Window window)
public static void HideFromAltTab(Window window)
{
var wh = new WindowInteropHelper(window);
var exStyle = GetWindowLong(wh.Handle, GWL_EXSTYLE);
Expand All @@ -61,5 +74,16 @@ public static void MakeWindowMovable(Window window)
ReleaseCapture();
SendMessage(wh.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, IntPtr.Zero);
}

public static void SetParentWindowToDesktop(Window window)
{
var hWnd = new WindowInteropHelper(window).Handle;
var hprog = FindWindowEx(
FindWindowEx(
FindWindow("Progman", "Program Manager"), IntPtr.Zero, "SHELLDLL_DefView", ""),
IntPtr.Zero, "SysListView32", "FolderView");

SetWindowLong(hWnd, GWL_HWNDPARENT, hprog);
}
}
}
14 changes: 5 additions & 9 deletions Feedling/FeedWin.xaml.cs
Expand Up @@ -5,8 +5,6 @@
See LICENSE file for license details.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
Expand Down Expand Up @@ -298,7 +296,7 @@ private void GetFeedType(object state)
{
rssfeed.Updated += rssfeed_Updated;
Log.Debug("Kicking off the watcher thread");
var t = new Thread(rssfeed.Watch);
var t = new Thread(rssfeed.Watch) {IsBackground = true};
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
Expand Down Expand Up @@ -359,10 +357,8 @@ private void PinToDesktop()
{
pinned = true;
RedrawWin();

Topmost = false;
NativeMethods.SendWpfWindowBack(this);
Cursor = Cursors.Arrow;
// NativeMethods.SendWpfWindowBack(this);
// Cursor = Cursors.Arrow;
}

/// <summary>
Expand All @@ -372,7 +368,6 @@ private void UnpinFromDesktop()
{
pinned = false;
RedrawWin();
Topmost = true;
}
#endregion

Expand Down Expand Up @@ -430,7 +425,8 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
Left = fci.Position.X;
Top = fci.Position.Y;
FeedwinManager.thisinst.ToggleMoveMode += thisinst_ToggleMoveMode;
NativeMethods.SetWindowLongToolWindow(this);
NativeMethods.HideFromAltTab(this);
NativeMethods.SetParentWindowToDesktop(this);
}

void thisinst_ToggleMoveMode(bool obj)
Expand Down
2 changes: 1 addition & 1 deletion Feedling/FeedwinManager.xaml.cs
Expand Up @@ -128,7 +128,7 @@ public FeedwinManager()
//
quititem.Name = "quititem";
quititem.Size = new System.Drawing.Size(157, 22);
quititem.Text = "Quit";
quititem.Text = Properties.Resources.FeedwinManager_FeedwinManager_Quit;
quititem.Click += quititem_Click;

contextmenustrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
Expand Down
9 changes: 9 additions & 0 deletions Feedling/Properties/Resources.Designer.cs

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

3 changes: 3 additions & 0 deletions Feedling/Properties/Resources.resx
Expand Up @@ -176,4 +176,7 @@ Error was {0}</value>
<data name="FeedwinManager_feedimportbtn_Click_Invalid_Config_file">
<value xml:space="preserve">Invalid Config file</value>
</data>
<data name="FeedwinManager_FeedwinManager_Quit">
<value xml:space="preserve">Quit</value>
</data>
</root>

0 comments on commit ba8bbf0

Please sign in to comment.