最近在学习MFC底层,通过看书受到启发,决定抛开书自己来独立写一下主要核心代码!
先定义一个MYMSGSTRUCT消息结构体和一个MYMSG宏.
struct mymsgstruct...{
UNIT mymeesage;
LONG (*ptr)( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
}
MYMSG(x) ( sizeof(x) / sizeof(x[0]) )
......
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
{
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 {
if((LOWORD)wParam==commodmsg[i].mymessage) [Page]
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 )
{
....
}
....
通过函数指针来实现类中的成员函数!
阅读(319) | 评论(0) | 转发(0) |