📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Web;
using System.Net;
namespace mms_send
{
public partial class Form1 : Form
{
public string sMmscUrl = "http://mmsc.monternet.com";
public string sProxyUrl = "10.0.0.172:80";
public MMessage mms = new MMessage();
public Image is_image;
public string file_path = "";
public Form1()
{
InitializeComponent();
}
private void add_file_Click(object sender, EventArgs e)
{
this.openFileDialog1.InitialDirectory = "D:\\Documents\\My Pictures";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
System.IO.StreamReader sr = new System.IO.StreamReader(openFileDialog1.FileName);
file_path = this.openFileDialog1.FileName.ToString();
mms.AddFile(file_path);
// MessageBox.Show(file_path);
Image is_image = Image.FromStream(sr.BaseStream);
Image TempImageTemp = is_image.GetThumbnailImage(this.pictureBox1.Size.Width, this.pictureBox1.Size.Height, null, IntPtr.Zero);
this.pictureBox1.Image = TempImageTemp;
sr.Close();
}
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
}
private void button1_Click(object sender, EventArgs e)
{
mms.AddTo (this.phone.Text.ToString());
mms.SetSubject(this.subject.Text.ToString());
string stat = Send(mms);
byte[] tmp = Encoding.UTF8.GetBytes(stat);
this.jieguo.Text = Encoding.Default.GetString(tmp);
}
public string Send(MMessage mm)
{
try
{
// 验证参数有效性
WebRequest wReq = WebRequest.Create(sMmscUrl);
HttpWebRequest hReq = (HttpWebRequest)wReq;
wReq.Headers.Clear();
if (sProxyUrl.Length > 0)
wReq.Proxy = new WebProxy(sProxyUrl);
wReq.ContentType = "application/vnd.wap.mms-message";
hReq.Accept = "application/vnd.wap.mms-message,text/plain,*/*";
wReq.Method = "POST";
hReq.KeepAlive = false;
hReq.UserAgent = "Nokia6681/2.0 (4.00.15) SymbianOS/8.0 Series60/2.6 Profile/MIDP-2.0 Configuration/CLDC-1.1";
// Write Post Dat
byte[] byMM = mm.GetContent();
hReq.ContentLength = byMM.Length;
Stream sReq = wReq.GetRequestStream();
sReq.Write(byMM, 0, byMM.Length);
sReq.Close();
// Http Request
WebResponse wRes = wReq.GetResponse();
HttpWebResponse hRes = (HttpWebResponse)wRes;
if (hRes.StatusCode == HttpStatusCode.OK)
{
Stream sRes = wRes.GetResponseStream();
StreamReader sr = new StreamReader(sRes);
string szResult = sr.ReadToEnd(); // 发送结果
// Parse result sring
return szResult;
}
}
catch (Exception e)
{
throw new Exception(e.Message);
}
return string.Empty;
}
private void button2_Click(object sender, EventArgs e)
{
this.openFileDialog1.InitialDirectory="E:\\mp3";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
System.IO.StreamReader sr = new System.IO.StreamReader(openFileDialog1.FileName);
file_path = this.openFileDialog1.FileName.ToString();
WMPLib.IWMPMedia iwmp= this.axWindowsMediaPlayer1.newMedia(file_path);
this.axWindowsMediaPlayer1.currentPlaylist.appendItem(iwmp);
this.axWindowsMediaPlayer1.Ctlcontrols.play();
mms.AddFile(file_path);
}
}
private void button3_Click(object sender, EventArgs e)
{
this.openFileDialog1.InitialDirectory = "D:\\Desktop";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
file_path = this.openFileDialog1.FileName.ToString();
this.content.Text = Encoding.Default.GetString(File.ReadAllBytes(file_path));
mms.AddFile(file_path);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -