Use notification in Windows Mobile console applications

Source: Internet
Author: User

Today, I saw a friend asking me howWindows MobileConsole ApplicationMicrosoft. WindowsCE. Forms. NotificationThis class. I did not study the use of this class, so I plan to try it.

GoogleFirstMsdnThe help is still Chinese. This technical resourceArticle《NotificationClassDescribes how to display and respond to user notifications.Windows CEFunction. The idea is that there is such a paragraph in the remarks,"Such provisionWindows CEManaged implementation of the notification function. OnlyPocket PCThis class is supported on." Obviously, we wantWm6For debugging, selectProfessional. Next we will explain it step by step.

1.InVisual Studio 2005InC #OfSmart DeviceUnder, selectWindows Mobile 6 Professional, SelectConsole ApplicationThat is, the console applicationProgram. After selecting the project name and path, click OK. For example1As shown in:

Figure1: New project page

2.Add 《NotificationClass"C #UnderCodeCopy all to the ProjectProgram. CS.

3.Compilation error found, prompt: "Not FoundSystem. Windows. Forms,System. DrawingAndMicrosoft. WindowsCE. Forms. Solution:RefenceRight-click, add the reference, and compile it, as shown in figure2As shown in:

Figure2: Add reference Interface

4.SelectWindows Mobile 6 Professional emulatorFor debugging, such3As shown in:

Figure3: Select a simulator for debugging

5.After the program is downloaded and run, the program immediately throws an exception.Value does not fall within the expected range", Such4As shown in:

Figure4: Program exception Interface

6.At this time, you have to perform one-step debugging to find the problem. I think it is a problem during initialization. Sure enoughConfignotificationFunction, execute to getNotificationOfIconThe program throws an exception. The code for this function is as follows:

Code
1 Private   Void Confignotification ()
2 {
3 // Create a notification.
4 Icationication1 =   New Microsoft. WindowsCE. Forms. Notification ();
5
6 Try
7 {
8 // Provide an icon for the notification to appear in the title bar when dismissed.
9 // Assumes an icon file is compiled with the Assembly as an embedded resource.
10 Assembly ASM = Assembly. getexecutingassembly ();
11 // Icationication1.icon = new icon (ASM. getmanifestresourcestream ("Y. ICO"), 16, 16 );
12
13 Icationication1.caption =   " Notification scenario-data download " ;
14
15 // If notification is urgent, set to true.
16 Icationication1.critical =   False ;
17
18 // Create the text for the notification.
19 // Use a stringbuilder for better performance.
20 Stringbuilder htmlstring =   New Stringbuilder ();
21
22 Htmlstring. append ( " <HTML> <body> " );
23 Htmlstring. append ( " <Font color = \ " # 0000ff \ " > <B> Data ready to download </B> </font> " );
24 Htmlstring. append ( " & Nbsp; <a href = \ " Settings \ " > Settings </a> " );
25 Htmlstring. append ( " <Br> <form method = \ " Get \ " Action = Policy> " );
26 Htmlstring. append ( " <Select name = \ " Lstbx \ " > " );
27 Htmlstring. append ( " <Option value = \ " 0 \ " > Start now </option> <option value = \ " 1 \ " > In 1 hr </option> " );
28 Htmlstring. append ( " <Option value = \ " 2 \ " > In 2 hrs </option> <option value = \ " 3 \ " > In 3 hrs </option> " );
29 Htmlstring. append ( " <Option value = \ " 4 \ " > In 4 hrs </option> </SELECT> " );
30 Htmlstring. append ( " <Input type = checkbox name = chkbx> Policy completion " );
31 Htmlstring. append ( " <Br> <input type = 'submit '> " );
32 Htmlstring. append ( " <Input type = button name = 'cmd: 2' value = 'postpone'> " );
33 Htmlstring. append ( " </Body> " );
34
35 // Set the text property to the HTML string.
36 Icationication1.text = Htmlstring. tostring ();
37
38 // Add event handlers.
39
40 Icationication1.balloonchanged + =   New Balloonchangedeventhandler (onballoonchanged );
41 Icationication1.responsesubmitted + =   New Responsesubmittedeventhandler (onresponsesubmitted );
42
43 }
44
45 Catch (Exception ex)
46 {
47MessageBox. Show (ex. Message );
48}
49
50
51 }
52

 

In fact, there are comments in the program, reminding the user to say, suppose thisIconCompiled as an embedded resource.

The simplest way to solve the problem isIconWell, I don't want to read it. Just block it and let's see how the program runs. ClickNotifyButton to pop up the user settings page, as shown in figure5As shown in:

Figure5:NotifyProgram running interface

Reference link:

Msdn:NotificationClass

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.