Develop WM application series with C ++ (3)-send SMS

Source: Internet
Author: User

Develop WM application series Article indexes using C ++

Introduction:

In the last section, we learned how to call a phone number in PPC. However, the phone number is hard-coded and cannot be used. Therefore, in this section, we use a cedit Control for users to enter numbers, fromProgramGet this number and call it. Of course, we will use the hello (SMS) text message provided by the wm6 SDK to send the instance. In this section, we will learn how to get strings from the cedit control and send SMS messages.

Body:

In the previous section, our user interface is as follows, but we can see that I dragged a button control to the bottom of the make it button and modified its caption attribute to send SMS. And a cedit control over the make it button.

 

Then, maybe in C #, the value of a textbox is directly inCodeBut in CPP, the cedit is a special control. For details, see the web search results. Here we just list a simple method. Right-click the cedit control and choose add variable.

In the Add variable wizard, set the variable type to "cedit" and the variable name to telnum. Keep others by default. Click Finish, in this way, we have created a variable telnum that references cedit. Next, modify the code of the make it button:

 

Make it code

  Void  Cmakecalldlg: onbnclickedbutton1 ()
{
Phonemakecallinfo callinfo;

Callinfo. cbsize = Sizeof (Callinfo );

Callinfo. dwflags = Pmcf_promptbeforecalling; // This parameter indicates that user permission is obtained before dialing, and pmcf_default indicates direct dialing.
Cstring telephone;
Telnum. getwindowtext (telephone ); // Get text from cedit and put it into telephone

Callinfo. pszdestaddress = Telephone;

If (Phonemakecall ( & Callinfo) = 0 )
{

}
Else
{
MessageBox (L " Dialg failed! " , L " Tips " , 0 );
}
}

 

The code is clearly visible, which is almost the same as the original one. It is nothing more than handling the phone number. Here, the last section has finally come to an end ~ Next, let's look at the SMS function. Originally, this function is very simple under. Net CF, but alas ~~ Forget it. Let's open the CPP Hello (SMS) instance under the wm6 SDK. After reading it, I find that I don't need to write too much. Here, I want to reiterate what I think is important, I opened the example and copied the sendsms () method to my makecalldlg. CPP, add SMS for the project. the reference of Lib, of course, is still illustrated here:

We added an SMS. Lib reference, which is also described in the SDK documentation ~.

If this is the case, go to makecalldlg. cpp and # include "SMS. H". In the code, declare the sendsms () method as follows:

 
  VoidSendsms (bool bsendconfirmation, bool busedefasmsmsc, maid, maid );

I believe you will surely see some clues from the sample program. I will not talk about it here. Here, we only need to add an event handler for the send SMS button. The method remains the same, add the following code to the method body:

 

  VoidCmakecalldlg: onbnclickedbutton2 ()
{
Cstring number;
Telnum. getwindowtext (number );
Sendsms (True,True, L"", Number, l"Test");
}

 

Here, bsendconfirmation indicates information receipt. busedefasmsmsc indicates whether to use the default SMS center number, lpszsmsc indicates the SMS center number, lpszrecipient indicates the recipient number, and the last one is the text message content. Run the following command:

Enter 10086 in the input box, and then click the "make it" button. Then, the system prompts whether to call the phone number. Click "yes" and you can see that the cell simulator can call the phone number:

Then, we hung up the phone and click send SMS. if the message is sent successfully, the following screen is displayed. We can also see the text message that we just sent from the cell simulator:

OK. Let's go here today, as usual. The sample code projects in the previous section and this section can all be used.Download hereTo.

Coming soon ~ Jack worships with prawns in their early years! Healthy and smooth! Hey ~~~~

Summary:

Today, we have come into contact with a cedit control. It seems that we will encounter it for a long time, so you can study it if you are free. Then, we also saw a sendsms method today. For details about this method, please refer to the msdn or wm6 SDK documentation.

Due to the rush of time, the text message of this program has not been tested on the real machine, and may have problems, such as the SMS center and recipient number. I hope you will pay attention to it during the test.

Problem:

It seems that these examples are relatively simple and there are no major problems at the moment. However, in general, what is the exception of String Conversion and the exception of type conversion, we are always new to CPP. We can only say one word. Persistence is victory! Haha ~~

Postscript:

It's also a new year's day. Have a good time off, so the next section may be updated later. Thank you for your support!

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.