DoubleLi

qq: 517712484 wx: ldbgliet

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  4737 随笔 :: 2 文章 :: 542 评论 :: 1615万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

msdn上的解析

CWnd::SubclassWindow
BOOL SubclassWindow( HWND hWnd );

Return Value

Nonzero if the function is successful; otherwise 0.

Parameters

hWnd

A handle to the window.

Remarks

Call this member function to "dynamically subclass" a window and attach it to this CWnd object. When a window is dynamically subclassed, windows messages will route through the CWnd’s message map and call message handlers in the CWnd’s class first. Messages that are passed to the base class will be passed to the default message handler in the window. 

Subclass(子类化)是MFC中最常用的窗体技术之一。子类化完成两个工作:一是把窗体类对象attach到一个windows窗体实体中(即把一个窗体的hwnd赋给该类)。另外就是把该类对象的消息加入到消息路由中,使得该类可以捕获消息。

例如一个CEdit的派生类CMyEdit 只允许键入0-9, A-F, 则我们可以改写WM_CHAR消息响应函数,然后用SubclassWindow子类化到对话框的一个文本框实体上(可用GetDlgItem), 这样对话框上文本框的消息就会重定向到CMyEdit上。

SubDlgItem 与 SubclassWindow 区别不大,但前者只限定于对话框控件,后者是一切具有HWND的窗体

更详细的讨论可参见如下文章:

http://dev.csdn.net/article/16/16045.shtm

posted on   DoubleLi  阅读(625)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2012-08-27 C++中的预处理命令 .
2012-08-27 详解C/C++预处理器 .
2012-08-27 VC项目配置基础 (VC6.0 和VC2005)
2012-08-27 VS2008编译的程序在某些机器上运行提示“由于应用程序配置不正确,应用程序未能启动”的问题
2012-08-27 C 风格字符串,C++string类,MFC,CString类的区别。
2012-08-27 C++ sizeof用法 .
2012-08-27 关于字符数组 和 字符串比较 C++
点击右上角即可分享
微信分享提示