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

WanttoBe 2008-11-24 11:37:06


使用 重写 DefWndProc或者消息映射都可以,我就是不知道在哪里 添加代码啊!!VC2005和VC6完全不同啊,
谢谢
...全文
100 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
你在那里永久天道哪个文件里在你调用之前。
如果你是想改变窗体的风格建议你使用AfxRegisterWndClass
WanttoBe 2008-11-25
  • 打赏
  • 举报
回复
自己顶一下

liuweibit 2008-11-25
  • 打赏
  • 举报
回复
不好意思,只会MFC
WanttoBe 2008-11-24
  • 打赏
  • 举报
回复
#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) {
}
};
}


//以上是我的代码,但是收不到任何消息
WanttoBe 2008-11-24
  • 打赏
  • 举报
回复
我现在的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

};
}

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧