Use OpenNetCF to add a taskbar icon for Windows CE/Windows Mobile

Source: Internet
Author: User

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?
  1. Using OpenNETCF. Windows. Forms;
  2. /// <Summary>
  3. /// Set the taskbar icon.
  4. /// </Summary>
  5. /// <Param name = "policyicon"> input a policyicon instance through reference. </Param>
  6. Private void initpolicyicon (policyicon)
  7. {
  8. // You can use the click or double-click event as needed. To keep the event consistent with the WinCE system, I chose double-click.
  9. NotifyIcon. DoubleClick + = new EventHandler (notifyIcon_DoubleClick );
  10. Policyicon. Icon = this. Icon; // here, the Icon of the form is referenced to assign values to the Icon attribute.
  11. Policyicon. Text = "the prompt Text you want to display when the tray icon is held down. ";
  12. Policyicon. Visible = true;
  13. }
  14. Void policyicon_doubleclick (object sender, EventArgs e)
  15. {
  16. This. Show (); // display the main form.
  17. }

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?
  1. Yyicon nic = new NotifyIcon ();
  2. 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.

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.