当前位置:编程学习 > C#/ASP.NET >>

能不能给一个在VS2005写VC程序加入消息处理函数的例子!!!

  
 
   使用 重写 DefWndProc或者消息映射都可以,我就是不知道在哪里 添加代码啊!!VC2005和VC6完全不同啊,
谢谢 --------------------编程问答-------------------- 我现在的form1.h中代码:

#pragma once

#include "windows.h"


namespace MsgReceiver {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
#define UM_PROGRESS WM_USER+100

/// <summary>
/// Form1 摘要
///
/// 警告: 如果更改此类的名称,则需要更改
///          与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
///          “资源文件名”属性。否则,
///          设计器将不能与此窗体的关联
///          本地化资源正确交互。
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
}


protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}

private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->SuspendLayout();
// 
// Form1
// 
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 266);
this->Name = L"Form1";
this->Text = L"消息接收者";
this->ResumeLayout(false);

}
#pragma endregion

};
}
--------------------编程问答-------------------- #pragma once

#include "windows.h"


namespace MsgReceiver {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
#define UM_PROGRESS WM_USER+100

/// <summary>
/// Form1 摘要
///
/// 警告: 如果更改此类的名称,则需要更改
///          与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
///          “资源文件名”属性。否则,
///          设计器将不能与此窗体的关联
///          本地化资源正确交互。
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
}


protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}

private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->SuspendLayout();
// 
// Form1
// 
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 266);
this->Name = L"Form1";
this->Text = L"消息接收者";
this->Click += gcnew System::EventHandler(this, &Form1::Form1_Click);
this->ResumeLayout(false);

}
#pragma endregion
System::Void DefWndProc(System::Windows::Forms::Message^ message){
switch(message->Msg){
case UM_PROGRESS:{
//通过指定资源ID获得相应的索引
   Console::WriteLine("收到消息"); 
   break;
}
default:
break;
}
return Form1::DefWndProc(message);
}

private: System::Void Form1_Click(System::Object^  sender, System::EventArgs^  e) {
 }
};
}


//以上是我的代码,但是收不到任何消息  --------------------编程问答-------------------- 不好意思,只会MFC --------------------编程问答-------------------- 自己顶一下

--------------------编程问答-------------------- 你在那里永久天道哪个文件里在你调用之前。
如果你是想改变窗体的风格建议你使用AfxRegisterWndClass
补充:.NET技术 ,  VC.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,