[DllImport("User32.dll", EntryPoint = "SendMessage")] private static extern int SendMessage( IntPtr hWnd, // handle to destination window int Msg, // message IntPtr wParam, // first message parameter string lParam // second message parameter
);
public enum WindowsMessage
{
WM_USER = 0x0400
}
const int WM_USER = 0x0400;
int testBytes = 0;
string str = "111";
public Form1()
{
InitializeComponent();
}
private delegate void TestDelegate(); private void StartMethod()
{
this.BeginInvoke(new TestDelegate(FasongXinxi));
}
private void button1_Click(object sender, EventArgs e)
{
StartMethod();
} private void FasongXinxi()
{
for (int j = 0; j < 30; j++)
{
testBytes = Encoding.Default.GetByteCount(str);
SendMessage(this.Handle, Convert.ToInt32(WindowsMessage.WM_USER), IntPtr.Zero, str);
Thread.Sleep(2000);
this.progressBar1.Value = j;
} } public void print(string content)
{
if ((content != null) || (content != ""))
{
this.listBox1.Items.Add(DateTime.Now.ToString() + " " + content);
this.listBox1.Refresh();
}
}
protected override void WndProc(ref Message m)
{
if (m.Msg == Convert.ToInt32(WindowsMessage.WM_USER))
{ byte[] myBytes = new byte[testBytes];
Marshal.Copy(m.LParam, myBytes, 0, testBytes);
string myTestResult = Encoding.Default.GetString(myBytes);
print(myTestResult);
}
base.WndProc(ref m);
}
}我想实现界面 与代码分离,代码循环运行 当有需要界面显示的消息,界面listbox添加消息,没有消息时,界面能动,拉滚动条等,但现在这个,它每次都是循环完30次之后,界面才能动,我想程序运行一条2条3条..界面都能拖动,请大家帮忙,我是个初学者,希望帮忙的朋友解释详细点,谢谢
);
public enum WindowsMessage
{
WM_USER = 0x0400
}
const int WM_USER = 0x0400;
int testBytes = 0;
string str = "111";
public Form1()
{
InitializeComponent();
}
private delegate void TestDelegate(); private void StartMethod()
{
this.BeginInvoke(new TestDelegate(FasongXinxi));
}
private void button1_Click(object sender, EventArgs e)
{
StartMethod();
} private void FasongXinxi()
{
for (int j = 0; j < 30; j++)
{
testBytes = Encoding.Default.GetByteCount(str);
SendMessage(this.Handle, Convert.ToInt32(WindowsMessage.WM_USER), IntPtr.Zero, str);
Thread.Sleep(2000);
this.progressBar1.Value = j;
} } public void print(string content)
{
if ((content != null) || (content != ""))
{
this.listBox1.Items.Add(DateTime.Now.ToString() + " " + content);
this.listBox1.Refresh();
}
}
protected override void WndProc(ref Message m)
{
if (m.Msg == Convert.ToInt32(WindowsMessage.WM_USER))
{ byte[] myBytes = new byte[testBytes];
Marshal.Copy(m.LParam, myBytes, 0, testBytes);
string myTestResult = Encoding.Default.GetString(myBytes);
print(myTestResult);
}
base.WndProc(ref m);
}
}我想实现界面 与代码分离,代码循环运行 当有需要界面显示的消息,界面listbox添加消息,没有消息时,界面能动,拉滚动条等,但现在这个,它每次都是循环完30次之后,界面才能动,我想程序运行一条2条3条..界面都能拖动,请大家帮忙,我是个初学者,希望帮忙的朋友解释详细点,谢谢
解决方案 »
- 求助!从表中获取主键编号最大值错误!
- 关于字符串乱码的问题
- 微软企业库调用oracle存储过程如何返回 【多个】 数据集?
- c# 通过快捷方式打开程序的时候,如何获取该快捷方式的名称,有没有办法实现呢?高手帮忙解答一下,谢谢!
- 网站编译的过程中出现下面的错误
- 关于C#中TEXTBOX的添加新的一行的问题。
- 水晶报表不用CRViewer控件如何动态显示数据报表?请给出代码!
- asp.net里。TextBox控件鼠标右键的粘贴问题。
- 求助,关于char
- 自己写的类,怎么样才能在使用时出现自动提示呢?
- NHibernate总是出错,帮帮我吧!
- 页面中在javascript里面存放的cookie怎么在C#里面获取...
Thread t1;
t1 = new Thread(new ThreadStart(StartMethod));
t1.Start();还是等运行完了界面才能动,
你们能说明白点么,谢谢
SendMessage是阻塞调用。要等消息处理完后才返回。所以只有SendMessage运行返回后,它后面的代码才执行。