30 days of. Net [Windows Mobile applications]-day 02: Bluetooth Manager)

Source: Internet
Author: User

For the original article, see day 02: Bluetooth
Manager

Requirement

To save power, page Brooks wants to complete the Bluetooth switch step by step.

Implementation

The technologies used include P/invoke Bluetooth API, picturebox, State and notification broker API.

Read my previousArticleYou will know that enabling and disabling Bluetooth in Windows Mobile means P/invoke bthsetmode ().

. Net
Windows Embedded source tools for Bluetooth development under Compact framework

. Net
32feet. Net for Bluetooth development under Compact framework

. Net
Bluetooth virtual serial port developed under the Compact framework

[Dllimport ( " Bthutil. dll " )]
Private   Static   Extern   Int Bthgetmode ( Out Radiomode dwmode );
[Dllimport ( " Bthutil. dll " )]
Private   Static   Extern   Int Bthsetmode (radiomode dwmode );

 

Status change function, if the externalProgramAfter the Bluetooth status is changed, the current program needs to be notified and process the change.

Using Microsoft. windowsmobile. status;
Systemstate initialize thstatepoweron =   New Systemstate (systemproperty. cmdthstatepoweron );
Descrithstatepoweron. Changed + =   New Changeeventhandler (effecthstatepoweron_changed );

VoidExport thstatepoweron_changed (ObjectSender, changeeventargs ARGs)
{
Updatescreen ();
}

The State and configurications broker API is used here, and the Microsoft. windowsmobile. Status library must be referenced. Systemstate (systemproperty. bluetoothstatepoweron) specifies the status monitoring type, which generates the system status object of the Bluetooth switch, bluetoothstatepoweron. changed + = new changeeventhandler (descrithstatepoweron_changed) subscribes to the change message of the Bluetooth switch system status, and processes the message using descrithstatepoweron_changed.

State and configurications brokerz API is a very important API that can monitor registry changes. The Registry in windowns is a small database that maintains system information and application information. State and configurications brokerz API provides the Registry monitoring function to monitor system information and application information changes. This information includes camera status, ActiveSync, power status, SMS, scheduled task, call information, Bluetooth status, network connection status, modem status, and so on. Therefore, this API is widely used in the development of system information-related events. For more information, see the following link.

Added the function of automatically disabling programs.

 

Private   Void Timer_tick ( Object Sender, eventargs E)
{
Textbox. Text =   String . Empty;

For ( Int I =   10 ; I >   0 ; I -- )
{
Textbox. Text + =   String . Format ( " Auto shutdown in {0} seconds "   + Environment. newline, I );
Thread. Sleep ( 1000 );
}

 This. Close ();
}

This. Timer. Interval= 60000;

After the program runs for 1 minute, it automatically closes itself. There was a 10-second countdown before the program was closed, so that the user knew that the program was not crash but automatically closed, which was a manifestation of user-friendly design.

Emulator debugging

Because emulator of Windows Mobile does not support Bluetooth directlySource codeDebugging must be performed on the real device. For convenience, you can try debugging on the emulator. Refer
Dr. Shi's article uses Bluetooth and Dmitry klionsky Bluetooth for Microsoft device emulator on the Windows Mobile simulator.

 

Installer: Effecthmanager. Cab

SourceCode: Descrithmanager.zip


 

References:
Msdn: State and
Communications Broker

 

. NET Compact framework, WinCE, Windows Mobile Development Series

Jake's blog in blog Park --Simplified development and wireless life

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.