C++类中的成员WinProc

If you ever tried wrapping a window's functionality I bet the first thing you asked yourself was: "What am I going to do with the window procedure?". I also bet this was the first answer that crossed your mind: "I'm just going to declare it as a member function within my window wrapper class and then I'm gonna pass it to the WNDCLASSEX structure as the lpfnWndProc field."
Well, unfortunately that won't work. Why? Because member functions have an additional hidden parameter, the this pointer, so instead of LRESULT CALLBACK wndProc (HWND, UINT, WPARAM, LPARAM) your member function will be LRESULT CALLBACK memberWndProc (YourClassName *this, HWND, UINT, WPARAM, LPARAM) .
Obviously you won't be able to do the assignment wcx.lpfnWndProc = memberWndProc because the two function pointers are of different types.

So how do we solve this? We'll use a static member function that will act as a message router. A static member function can be called without creating an instance of the class, therefore it doesn't have the this pointer in its parameter list, allowing us to pass it as the lpfnWndProc member in WNDCLASSEX .

Message router you say? Yes, because the window procedure is going to be a static member function, we can't redefine its behavior in derived classes so we're gonna use a little hack. We're gonna declare another window procedure function that will be implemented in derived clasess and will do the actual message processing particular to each window. The static message router is going to determine which instance's window procedure to call by associating the window's HWND handle with a pointer to the derived class instance. This will be explained later.

03-16
WinProc是一个在Windows下通用的进程管理工具,它除了具有一般进程管理工具的所有功能,还有一些自己的特色。下面是功能简介: 进程信息查看:可以查看进程的详细信息,包括线程数、模块数、占用内存、文件路径及进程相关的进程、线程详细信息等。 进程优先级设置:你可以主观上控制进程的CPU占用时间。 杀进程:WinProc提供多种杀进程方式。 1.在进程列表中直接双击可以结束选定进程; 2.在进程列表中右击选定进程,在弹出菜单中选择“结束该进程之后所有进程”可以用来对付令人讨厌的一直跑出来的IE窗口; 3.将一个或者多个进程加入待结束进程列表,可是对多个进程同时进行操作,比如全部结束或者定时结束; 4.另外右击系统通知区的WinProc小图标,在弹出菜单的杀进程子菜单中选择所要结束的进程,可以快速结束进程,全都是鼠标操作。 定时操作:在WinProc中可以定时结束进程或者定时关机。 保存进程列表:以文本方式保存当前系统运行的进程列表,以备查看,比较平庸的一个功能。 进程黑名单:顾名思义,将进程加入进程黑名单后,该进程将无法被启动。至于这样做的意义何在,就看什么人怎么用了,呵呵。 锁定屏幕:当你离开电脑的时候可以将屏幕锁定,没有你的密码将无法解锁,但是别人可以在你的屏幕上给你留言,用用就知道了。 热键激活WinProc:可以按热键(F12)激活或者隐藏WinProc,而且需要说明的是该热键穿透力很强,你甚至可以在一些屏蔽了热键的程序中激活WinProc。 热键杀进程:这个功能是为了应急而设计的。比如你在上班时间打游戏的时候,老板突然出现...如果你事先把一些比较敏感的程序(这里是游戏)加入待结束进程列表的话,不要急,只要按一下ScrLock,那尴尬的一幕将不复出现。 快速重启、注销、关机:如果你什么都喜欢快的话,这个功能或许能帮上忙。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值