Hi,
jhow said:
A notification window is not quite what I'm looking for and I know
what I am trying to do is possible, because I've seen it done in at
least 3 other applications before. It is quite a common feature in
dictionary applications.
They probably are doing this by reparenting their window to the window which
represents the navbar.
Within C# / .NET CF it's all a bit of a hack (and I wouldn't really even
recommend doing it at the native level...) but if you follow these
instructions hopefully it's something close to what you want...
Start off by adding a new form to your project (I called it "IconForm"), and
set the following properties.
FormBorderStyle = none
MaximizeBox = false
ControlBox = false
Size = 24,24
Also make sure you delete the MainMenu instance.
Then add the following class to your project
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
public static class FormExtensions
{
public static void ReparentToNavBar(this Form form, Point location)
{
IntPtr hWndParent = FindWindow("HHTaskBar", null);
Reparent(form, hWndParent, location);
}
// Reparents "form" to be a child of "hWndParent" positioned
// using the x,y co-ordinates specified by "location".
public static void Reparent(this Form form, IntPtr hWndParent, Point
location)
{
IntPtr hWndChild = form.Handle;
// Remove the WS_POPUP window style and
// add the WS_CHILD window style
uint style = GetWindowLong(hWndChild, GWL_STYLE);
style &= ~WS_POPUP;
style |= WS_CHILD;
SetWindowLong(hWndChild, GWL_STYLE, style);
// Reparent the window
SetParent(hWndChild, hWndParent);
// Adjust the positioning of the form
form.Location = location;
}
private const uint WS_POPUP = 0x80000000;
private const uint WS_CHILD = 0x40000000;
private const uint WS_EX_TOPMOST = 0x00000008;
private const int GWL_STYLE = -16;
private const int GWL_EXSTYLE = -20;
[DllImport("coredll.dll")]
private static extern uint GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("coredll.dll")]
private static extern uint SetWindowLong(IntPtr hWnd, int nIndex, uint
dwNewLong);
[DllImport("coredll.dll")]
private static extern IntPtr FindWindow(string lpClassName, string
lpWindowName);
[DllImport("coredll.dll")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr
hWndNewParent);
}
Once this has been done, you should be able to add a button click event
handler or something similiar to invoke the code to add your custom window
to the nav bar. A code snippet similiar to the following should be
sufficient:
Form f = new IconForm(); // or what ever you named your custom form
f.Show();
f.ReparentToNavBar(new Point(45, 0));
And to remove it, you would simply execute
f.Close();
f.Dispose();
You should see that this window appears on the top of your screen, and
should be fairly visible throughout most applications (except those which
purposely hide the navbar). Its rather hacky though and potentially prone to
breaking.
Hope this helps,
Christopher Fairbairn