i'm currently trying to get wndproc handling in wpf but without any success..
i need to get the event of window created, window activated and window destroid events.
here's what i tried so far
int uMsgNotify;
public MainWindow()
{
InitializeComponent();
WinApi.SetTaskmanWindow(new WindowInteropHelper(this).Handle);
WinApi.RegisterShellHookWindow(new WindowInteropHelper(this).Handle);
uMsgNotify = WinApi.RegisterWindowMessage("SHELLHOOK");
MainForm.ShowInTaskbar = false;
MainForm.ShowActivated = true;
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
source.AddHook(WndProc);
}
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
IntPtr handle;
if (msg == uMsgNotify)
{
switch (wParam.ToInt32())
{
case WinApi.HSHELL_WINDOWCREATED:
handle = lParam;
string windowName = GetWindowName(handle);
IntPtr hWnd = WinApi.FindWindow(null, windowName);
add_icon(windowName, handle);// add new task's icon in taskbar
break;
case WinApi.HSHELL_WINDOWACTIVATED:
handle = lParam;
break;
case WinApi.HSHELL_WINDOWDESTROYED:
handle = lParam;
del_icon(handle); //remove icon from taskbar
break;
}
}
return IntPtr.Zero;
}
private static string GetWindowName(IntPtr hWnd)
{
// Allocate correct string length first
int length = WinApi.GetWindowTextLength(hWnd);
StringBuilder sb = new StringBuilder(length + 1);
WinApi.GetWindowText(hWnd, sb, sb.Capacity);
return sb.ToString();
}
code doesn't give any kind of runtime error whatsoever.... but it wont work.. to make more sense i'm developing an alternate shell for windows for my gaming cafe... where it needs to have a kind of taskbar..
any help?