最近在学习MFC底层,通过看书受到启发,决定抛开书自己来独立写一下主要核心代码!
先定义一个MYMSGSTRUCT消息结构体和一个MYMSG宏.
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1327ab569c1ae82736693a50b8e33378.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/0196c3df5ea9e936f21e9932cca91014.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
......
mymsgstruct mymsg[]={WM_COMMOD,OnCommod,WM_CHAR,OnChar,....}
mymsgstruct commodmsg[]={IDM_ABOUT,OnAbout,IDM_SAVEAS,OnSaveas....}
....
LRESULT CALLBACK WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
for(int i=0;i<MYMSG(mymsg);i++)
{
if(uMsg==mymsg[i].mymessage)
return mymsg[i].ptr( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
return DefWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
}
}
LONG OnCommod( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
for(int i=0;i<MYMSG(commodmsg);i++)
{
if((LOWORD)wParam==commodmsg[i].mymessage)
return commodmsg[i].ptr( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
return DefWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
}
}
LONG OnChar( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
....
}
....
通过函数指针来实现类中的成员函数!