Hello All,
I have been searching around and trying things with the bubble notify on PPC
2002 with the OpenNetCF and can not seem to get it working or come up with a
good example on any forums.
is there a sample out there that works without doing code changes?
regards,
Jay
I ripped out all the function of this application and changed some
names - but it's mostly all there. It compiles - and it DID work when
it was whole, but take a look - if nothing else there's some good HTML
formatting tricks in there.
-a
using System;
using System.Collections;
using System.Windows.Forms;
using OpenNETCF.Notification;
using OpenNETCF.Windows.Forms;
namespace NotificationNS.Misc.UpdateManager
{
/// <summary>
/// TestNotification is a hidden Windows forms application responsible
/// for doing 2 things and notifying the user of the status. Upon
completion, the
/// application closes itself and let's the user know it's done.
/// </summary>
public class TestNotification : System.Windows.Forms.Form
{
private const int DOING_SOMETHING = 0; // Notification ID
private const int DOING_SOMETHING_ELSE = 1; // Notification ID
private const int NOTIFICATION_TIMEOUT = 10;// Time for notification
to persist
private NotificationEngine notEngine; // Notification engine
public TestNotification(string[ ] args)
{
InitializeComponent();
// Create and bind the GUID for the notification engine
OpenNETCF.GuidEx guidEx = OpenNETCF.GuidEx.NewGuid();
Guid guid = new Guid(guidEx.ToByteArray());
notEngine = new NotificationEngine(guid);
// Set up event handler for the form
this.notEngine.NotificationDismiss += new
NotificationEventHandler(notEngine_NotificationDismiss);
this.Load += new EventHandler(appNotification_Loaded);
this.Closing += new
System.ComponentModel.CancelEventHandler(this.TestNotification_Closing);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// TestNotification
//
this.ClientSize = new System.Drawing.Size(240, 320);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
ApplicationEx.Run(new TestNotification(args));
}
private void appNotification_Loaded(object sender, EventArgs arg)
{
this.Hide();
startUpdateProcess();
}
/// <summary>
/// startUpdateProcess is called when the Notification is started to
spawn the download
/// thread and create the initial notification.
/// </summary>
private void startUpdateProcess()
{
System.Threading.ThreadPool.QueueUserWorkItem(
new System.Threading.WaitCallback(doSomething));
string htmlText = "<html><body><form method=\'POST\' action=>" +
"<p> Downloading updated CAB from server.</p>" +
"<p> Click 'OK' to dismiss this notification.</p>" +
"<p align=right><input type=button name='OK'
value='OK'></p></form></body></html>";
addNotification(DOING_SOMETHING,htmlText,NOTIFICATION_TIMEOUT,NotificationFlags.ForceMessage);
}
/// <summary>
/// Private method to add a notification to the Notification Engine
to be added to
/// the task bar of the Pocket PC.
/// </summary>
/// <param name="notID">ID of the Notification to be added</param>
/// <param name="html">HTML text of the message to be displayed to
the device.
/// This may contain text, links, and buttons.</param>
/// <param name="duration">Seconds until the notification is
dismissed by the OS.</param>
/// <param name="notFlags">Dictates the urgency and display methods
of the nofication.</param>
private void addNotification(int notID, string html, int duration,
NotificationFlags notFlags)
{
Notification not = new Notification();
not.Duration = duration;
not.Flags = notFlags;
not.HTML = html;
not.ID = Convert.ToInt32(notID);
not.Title = "Title";
not.Priority = Priority.Inform;
notEngine.Add(not);
}
private void removeNotification(int notId)
{
notEngine.Remove(notId);
}
private void updateNotification(Notification not, string html)
{
// Get notification with notifyId from notEngine
notEngine.Update(UpdateMask.Html, not);
}
private void doSomething(object param)
{
removeNotification(DOING_SOMETHING);
string htmlText = "<html><body><form method=\'POST\' action=>" +
"<p> Done some stuff. Click 'OK'.</p>" +
"<p align=right><input type=button name='OK'
value='OK'></p></form></body></html>";
addNotification(DOING_SOMETHING_ELSE,htmlText,NOTIFICATION_TIMEOUT,NotificationFlags.ForceMessage);
}
private void notEngine_NotificationDismiss(object sender,
NotificationEventArgs args)
{
switch (args.ID)
{
case (DOING_SOMETHING): // First notification
break;
case (DOING_SOMETHING_ELSE): // Second notification
MessageBox.Show("All Done");
ApplicationEx.Exit();
break;
default: // Shouldn't ever get here
MessageBox.Show("Notification Exception with ID: " +
args.ID.ToString() + ". Please contact administrator for support with
update process",
"Notification Error", MessageBoxButtons.OKCancel,
MessageBoxIcon.Hand,
MessageBoxDefaultButton.Button1);
break;
}
}
private void TestNotification_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
this.Dispose(true);
}
}
}