From: http://blog.csdn.net/porscheyin/archive/2009/12/08/4960518.aspx
To meet the project requirements, you need to add a taskbar icon to the program developed in the system of WinCE 5.0, so that you can click or double-click the icon to restore the minimal program. The. NET Compact Framework does not support the NotifyIcon class of the full version. NET. So I am going to use P/Invoke to call the system dll for implementation. After some information is collected on the network, this method may cause the task bar icon to move left after the program ends. Therefore, we decided to use the policyicon class in the Smart Device Framework (SDF) Class Library launched by OpenNetCF.
The official website of OpenNetCF is the latest version of movie Device Framework (SDF) 2.3, which is divided into community edition (free of charge), Standard Edition ($50), Professional Edition ($500 ), the last two versions only support Visual Studio 2008, while the Free Community version also supports Visual Studio 2005. The biggest difference between the Community edition and the paid version is that there is no design-time support, and there are only a small number of control classes in the SDF, so it is not necessary to support the design, in my opinion, the Community edition is enough. If you have enough funds, you can choose Standard Edition or Professional Edition, and you will get a better development experience. Is the comparison of different versions.
The file is very small, only 1.99 M. Download and install it. Then add a reference to OpenNETCF. Windows. Forms. dll in Visual Studio, and the path is · \ Smart DeviceFramework \ Bin. (For example) (there is also a Samples folder under the SmartDevice Framework Directory, which contains many excellent examples for learning .)
After adding a reference, OpenNETCF. Windows. Forms appears in the reference node of the VS solution Resource Manager, as shown in.
The implementation code is as simple as using the policyicon class in. NET Framework:
View plaincopy to clipboardprint?
- Using OpenNETCF. Windows. Forms;
- /// <Summary>
- /// Set the taskbar icon.
- /// </Summary>
- /// <Param name = "policyicon"> input a policyicon instance through reference. </Param>
- Private void initpolicyicon (policyicon)
- {
- // You can use the click or double-click event as needed. To keep the event consistent with the WinCE system, I chose double-click.
- NotifyIcon. DoubleClick + = new EventHandler (notifyIcon_DoubleClick );
- Policyicon. Icon = this. Icon; // here, the Icon of the form is referenced to assign values to the Icon attribute.
- Policyicon. Text = "the prompt Text you want to display when the tray icon is held down. ";
- Policyicon. Visible = true;
- }
- Void policyicon_doubleclick (object sender, EventArgs e)
- {
- This. Show (); // display the main form.
- }
Using OpenNETCF. Windows. Forms; /// <summary> /// set the taskbar icon. /// </Summary> /// <param name = "policyicon"> You can reference A policyicon instance. </Param> private void initpolicyicon (policyicon) {// you can use the click or double-click event as needed. To stay consistent with the WinCE system, I double-click the event. Policyicon. DoubleClick + = new EventHandler (notifyIcon_DoubleClick); policyicon. Icon = this. Icon; // assign values to the Icon attribute by referencing the Icon of the form. Policyicon. Text = "the prompt Text you want to display when the tray icon is held down. "; Policyicon. Visible = true;} void policyicon_doubleclick (object sender, EventArgs e) {this. Show (); // display the main form .}
You can use it like this:
View plaincopy to clipboardprint?
- Yyicon nic = new NotifyIcon ();
- Initpolicyicon (nic );
NotifyIcon nic = new NotifyIcon (); initpolicyicon (nic );
The code above supports both Windows CE and Windows Mobile. Now, you can easily add the taskbar icon for the. NET program developed on Windows CE. Smart Device Framework makes up for it. net CF is insufficient. All calls to operating system services are encapsulated into this class library, so that developers Based on the hosted code platform can directly access the platform services without the tedious P/Invoke calls, yes. net cf developers are a good helper.