读书人

MFC窗口过程的有关问题

发布时间: 2013-03-12 11:19:35 作者: rapoo

MFC窗口过程的问题
MFC自己有一个窗口过程吧,但是如果我自己建立一个窗口过程,他怎么分辨的呢?
窗口过程的作用是??谢谢 mfc 窗口过程
[解决办法]
mfc
的消息route 你没看过吧!

看这个!http://blog.csdn.net/wangyao1052/article/details/8045017
[解决办法]
一个窗口过程对应一个线程
也就是说默认MFC会为你提供一个主线程,也就是派生自CWinApp的CMyApp类对应的run()

如果你要重新建立一个窗口过程,那就要从CWinThread派生出一个新的类
然后重写这个类的run,这就是你要的窗口过程
这样的话你肯定就能识别自己的线程处理函数了
[解决办法]
这里就是消息循环
在你的派生类里重写run就能响应你感兴趣的消息


int CWinThread::Run()
{
ASSERT_VALID(this);

// for tracking the idle time state
BOOL bIdle = TRUE;
LONG lIdleCount = 0;

// acquire and dispatch messages until a WM_QUIT message is received.
for (;;)
{
// phase1: check to see if we can do idle work
while (bIdle &&
!::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE))
{
// call OnIdle while in bIdle state
if (!OnIdle(lIdleCount++))
bIdle = FALSE; // assume "no idle" state
}

// phase2: pump messages while available
do
{
// pump message, but quit on WM_QUIT
if (!PumpMessage())
return ExitInstance();

// reset "no idle" state after pumping "normal" message
if (IsIdleMessage(&m_msgCur))
{
bIdle = TRUE;
lIdleCount = 0;
}

} while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE));
}

ASSERT(FALSE); // not reachable
}

读书人网 >VC/MFC

热点推荐