跟踪MFC的源码

appcore.app

CWinApp::CWinApp(LPCTSTR lpszAppName)
{
 if (lpszAppName != NULL)
  m_pszAppName = _tcsdup(lpszAppName);
 else
  m_pszAppName = NULL;


 // initialize CWinThread state
 AFX_MODULE_STATE* pModuleState = _AFX_CMDTARGET_GETSTATE();
 ENSURE(pModuleState);
 AFX_MODULE_THREAD_STATE* pThreadState = pModuleState->m_thread;
 ENSURE(pThreadState);
 ASSERT(AfxGetThread() == NULL);
 pThreadState->m_pCurrentWinThread = this;
 ASSERT(AfxGetThread() == this);
 m_hThread = ::GetCurrentThread();
 m_nThreadID = ::GetCurrentThreadId();

 // initialize CWinApp state
 ASSERT(afxCurrentWinApp == NULL); // only one CWinApp object please
 pModuleState->m_pCurrentWinApp = this;
 ASSERT(AfxGetApp() == this);

 // in non-running state until WinMain
 m_hInstance = NULL;
 m_hLangResourceDLL = NULL;
 m_pszHelpFilePath = NULL;
 m_pszProfileName = NULL;
 m_pszRegistryKey = NULL;
 m_pszExeName = NULL;
 m_pRecentFileList = NULL;
 m_pDocManager = NULL;
 m_atomApp = m_atomSystemTopic = NULL;
 m_lpCmdLine = NULL;
 m_pCmdInfo = NULL;

 // initialize wait cursor state
 m_nWaitCursorCount = 0;
 m_hcurWaitCursorRestore = NULL;

 // initialize current printer state
 m_hDevMode = NULL;
 m_hDevNames = NULL;
 m_nNumPreviewPages = 0;     // not specified (defaults to 1)

 // initialize DAO state
 m_lpfnDaoTerm = NULL;   // will be set if AfxDaoInit called

 // other initialization
 m_bHelpMode = FALSE;
 m_eHelpType = afxWinHelp;
 m_nSafetyPoolSize = 512;        // default size
}


#include<appmodul.cpp>

extern "C" int WINAPI
_tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
 __in LPTSTR lpCmdLine, int nCmdShow)
{
 // call shared/exported WinMain
 return AfxWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
}

#include <winmain.cpp>

int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
 __in LPTSTR lpCmdLine, int nCmdShow)
{
 ASSERT(hPrevInstance == NULL);

 int nReturnCode = -1;
 CWinThread* pThread = AfxGetThread();
 CWinApp* pApp = AfxGetApp();

 // AFX internal initialization
 if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
  goto InitFailure;

 // App global initializations (rare)
 if (pApp != NULL && !pApp->InitApplication())
  goto InitFailure;

 // Perform specific initializations
 if (!pThread->InitInstance())
 {
  if (pThread->m_pMainWnd != NULL)
  {
   TRACE(traceAppMsg, 0, "Warning: Destroying non-NULL m_pMainWnd\n");
   pThread->m_pMainWnd->DestroyWindow();
  }
  nReturnCode = pThread->ExitInstance();
  goto InitFailure;
 }
 nReturnCode = pThread->Run();

InitFailure:
#ifdef _DEBUG
 // Check for missing AfxLockTempMap calls
 if (AfxGetModuleThreadState()->m_nTempMapLock != 0)
 {
  TRACE(traceAppMsg, 0, "Warning: Temp map lock count non-zero (%ld).\n",
   AfxGetModuleThreadState()->m_nTempMapLock);
 }
 AfxLockTempMaps();
 AfxUnlockTempMaps(-1);
#endif

 AfxWinTerm();
 return nReturnCode;
}

#include<appinit.cpp>

BOOL AFXAPI AfxWinInit(HINSTANCE hInstance, HINSTANCE hPrevInstance,
 __in LPTSTR lpCmdLine, int nCmdShow)
{
 ASSERT(hPrevInstance == NULL);


 // handle critical errors and avoid Windows message boxes
 SetErrorMode(SetErrorMode(0) |
  SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);

 // set resource handles
 AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
 pModuleState->m_hCurrentInstanceHandle = hInstance;
 pModuleState->m_hCurrentResourceHandle = hInstance;
 pModuleState->CreateActivationContext();

 // fill in the initial state for the application
 CWinApp* pApp = AfxGetApp();
 if (pApp != NULL)
 {
  // Windows specific initialization (not done if no CWinApp)
  pApp->m_hInstance = hInstance;
  hPrevInstance; // Obsolete.
  pApp->m_lpCmdLine = lpCmdLine;
  pApp->m_nCmdShow = nCmdShow;
  pApp->SetCurrentHandles();
 }

 // initialize thread specific data (for main thread)
 if (!afxContextIsDLL)
  AfxInitThread();

 // Initialize CWnd::m_pfnNotifyWinEvent
 HMODULE hModule = ::GetModuleHandle(_T("user32.dll"));
 if (hModule != NULL)
 {
  CWnd::m_pfnNotifyWinEvent = (CWnd::PFNNOTIFYWINEVENT)::GetProcAddress(hModule, "NotifyWinEvent");
 }

 return TRUE;
}

#include<thrdcore.cpp>
void AFXAPI AfxInitThread()
{
 if (!afxContextIsDLL)
 {
  // set message filter proc
  _AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
  ASSERT(pThreadState->m_hHookOldMsgFilter == NULL);
  pThreadState->m_hHookOldMsgFilter = ::SetWindowsHookEx(WH_MSGFILTER,
   _AfxMsgFilterHook, NULL, ::GetCurrentThreadId());
 }
}

#include<thrdcore.cpp>
// Message Filter processing (WH_MSGFILTER)
LRESULT CALLBACK _AfxMsgFilterHook(int code, WPARAM wParam, LPARAM lParam)
{
 CWinThread* pThread;
 if (afxContextIsDLL || (code < 0 && code != MSGF_DDEMGR) ||
  (pThread = AfxGetThread()) == NULL)
 {
  return ::CallNextHookEx(_afxThreadState->m_hHookOldMsgFilter,
   code, wParam, lParam);
 }
 ASSERT(pThread != NULL);
 return (LRESULT)pThread->ProcessMessageFilter(code, (LPMSG)lParam);
}

#include<appcore.cpp>
BOOL CWinApp::InitApplication()
{
 if (CDocManager::pStaticDocManager != NULL)
 {
  if (m_pDocManager == NULL)
   m_pDocManager = CDocManager::pStaticDocManager;
  CDocManager::pStaticDocManager = NULL;
 }

 if (m_pDocManager != NULL)
  m_pDocManager->AddDocTemplate(NULL);
 else
  CDocManager::bStaticInit = FALSE;

 LoadSysPolicies();

 return TRUE;
}

#include<MyExample.cpp>
BOOL CMyExampleApp::InitInstance()
{
 // 如果一个运行在 Windows XP 上的应用程序清单指定要
 // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
 //则需要 InitCommonControlsEx()。否则,将无法创建窗口。
 INITCOMMONCONTROLSEX InitCtrls;
 InitCtrls.dwSize = sizeof(InitCtrls);
 // 将它设置为包括所有要在应用程序中使用的
 // 公共控件类。
 InitCtrls.dwICC = ICC_WIN95_CLASSES;
 InitCommonControlsEx(&InitCtrls);

 CWinApp::InitInstance();

 // 初始化 OLE 库
 if (!AfxOleInit())
 {
  AfxMessageBox(IDP_OLE_INIT_FAILED);
  return FALSE;
 }
 AfxEnableControlContainer();
 // 标准初始化
 // 如果未使用这些功能并希望减小
 // 最终可执行文件的大小,则应移除下列
 // 不需要的特定初始化例程
 // 更改用于存储设置的注册表项
 // TODO: 应适当修改该字符串,
 // 例如修改为公司或组织名
 SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
 // 若要创建主窗口,此代码将创建新的框架窗口
 // 对象,然后将其设置为应用程序的主窗口对象
 CMainFrame* pFrame = new CMainFrame;
 if (!pFrame)
  return FALSE;
 m_pMainWnd = pFrame;
 // 创建并加载框架及其资源
 pFrame->LoadFrame(IDR_MAINFRAME,
  WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
  NULL);


 // 唯一的一个窗口已初始化,因此显示它并对其进行更新
 pFrame->ShowWindow(SW_SHOW);
 pFrame->UpdateWindow();
 // 仅当具有后缀时才调用 DragAcceptFiles
 //  在 SDI 应用程序中,这应在 ProcessShellCommand  之后发生
 return TRUE;
}

#include<appcore.cpp>
BOOL CWinApp::InitInstance()
{
 InitLibId();
 m_hLangResourceDLL = LoadAppLangResourceDLL();
 if(m_hLangResourceDLL != NULL)
 {
  AfxSetResourceHandle(m_hLangResourceDLL);
  _AtlBaseModule.SetResourceInstance(m_hLangResourceDLL);
 }

 return TRUE;
}

#include <winfrm.cpp>
void CFrameWnd::AddFrameWnd()
{
 // hook it into the CFrameWnd list
 AFX_MODULE_THREAD_STATE* pState = _AFX_CMDTARGET_GETSTATE()->m_thread;
 pState->m_frameList.AddHead(this);
}

#include <winfrm.cpp>
BOOL CFrameWnd::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle,
 CWnd* pParentWnd, CCreateContext* pContext)
{
 // only do this once
 ASSERT_VALID_IDR(nIDResource);
 ASSERT(m_nIDHelp == 0 || m_nIDHelp == nIDResource);

 m_nIDHelp = nIDResource;    // ID for help context (+HID_BASE_RESOURCE)

 CString strFullString;
 if (strFullString.LoadString(nIDResource))
  AfxExtractSubString(m_strTitle, strFullString, 0);    // first sub-string

 VERIFY(AfxDeferRegisterClass(AFX_WNDFRAMEORVIEW_REG));

 // attempt to create the window
 LPCTSTR lpszClass = GetIconWndClass(dwDefaultStyle, nIDResource);
 CString strTitle = m_strTitle;
 if (!Create(lpszClass, strTitle, dwDefaultStyle, rectDefault,
   pParentWnd, ATL_MAKEINTRESOURCE(nIDResource), 0L, pContext))
 {
  return FALSE;   // will self destruct on failure normally
 }

 // save the default menu handle
 ASSERT(m_hWnd != NULL);
 m_hMenuDefault = ::GetMenu(m_hWnd);

 // load accelerator resource
 LoadAccelTable(ATL_MAKEINTRESOURCE(nIDResource));

 if (pContext == NULL)   // send initial update
  SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE);

 return TRUE;
}


#include<afximpl.h>
#define AfxDeferRegisterClass(fClass) AfxEndDeferRegisterClass(fClass)


#include <wincore.cpp>
BOOL AFXAPI AfxEndDeferRegisterClass(LONG fToRegister)
{
 // mask off all classes that are already registered
 AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
 fToRegister &= ~pModuleState->m_fRegisteredClasses;
 if (fToRegister == 0)
  return TRUE;

 LONG fRegisteredClasses = 0;

 // common initialization
 WNDCLASS wndcls;
 memset(&wndcls, 0, sizeof(WNDCLASS));   // start with NULL defaults
 wndcls.lpfnWndProc = DefWindowProc;
 wndcls.hInstance = AfxGetInstanceHandle();
 wndcls.hCursor = afxData.hcurArrow;

 INITCOMMONCONTROLSEX init;
 init.dwSize = sizeof(init);

 // work to register classes as specified by fToRegister, populate fRegisteredClasses as we go
 if (fToRegister & AFX_WND_REG)
 {
  // Child windows - no brush, no icon, safest default class styles
  wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  wndcls.lpszClassName = _afxWnd;
  if (AfxRegisterClass(&wndcls))
   fRegisteredClasses |= AFX_WND_REG;
 }
 if (fToRegister & AFX_WNDOLECONTROL_REG)
 {
  // OLE Control windows - use parent DC for speed
  wndcls.style |= CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  wndcls.lpszClassName = _afxWndOleControl;
  if (AfxRegisterClass(&wndcls))
   fRegisteredClasses |= AFX_WNDOLECONTROL_REG;
 }
 if (fToRegister & AFX_WNDCONTROLBAR_REG)
 {
  // Control bar windows
  wndcls.style = 0;   // control bars don't handle double click
  wndcls.lpszClassName = _afxWndControlBar;
  wndcls.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  if (AfxRegisterClass(&wndcls))
   fRegisteredClasses |= AFX_WNDCONTROLBAR_REG;
 }
 if (fToRegister & AFX_WNDMDIFRAME_REG)
 {
  // MDI Frame window (also used for splitter window)
  wndcls.style = CS_DBLCLKS;
  wndcls.hbrBackground = NULL;
  if (_AfxRegisterWithIcon(&wndcls, _afxWndMDIFrame, AFX_IDI_STD_MDIFRAME))
   fRegisteredClasses |= AFX_WNDMDIFRAME_REG;
 }
 if (fToRegister & AFX_WNDFRAMEORVIEW_REG)
 {
  // SDI Frame or MDI Child windows or views - normal colors
  wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  wndcls.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
  if (_AfxRegisterWithIcon(&wndcls, _afxWndFrameOrView, AFX_IDI_STD_FRAME))
   fRegisteredClasses |= AFX_WNDFRAMEORVIEW_REG;
 }
 if (fToRegister & AFX_WNDCOMMCTLS_REG)
 {
  // this flag is compatible with the old InitCommonControls() API
  init.dwICC = ICC_WIN95_CLASSES;
  fRegisteredClasses |= _AfxInitCommonControls(&init, AFX_WIN95CTLS_MASK);
  fToRegister &= ~AFX_WIN95CTLS_MASK;
 }
 if (fToRegister & AFX_WNDCOMMCTL_UPDOWN_REG)
 {
  init.dwICC = ICC_UPDOWN_CLASS;
  fRegisteredClasses |= _AfxInitCommonControls(&init, AFX_WNDCOMMCTL_UPDOWN_REG);
 }
 if (fToRegister & AFX_WNDCOMMCTL_TREEVIEW_REG)
 {
  init.dwICC = ICC_TREEVIEW_CLASSES;
  fRegisteredClasses |= _AfxInitCommonControls(&init, AFX_WNDCOMMCTL_TREEVIEW_REG);
 }
 if (fToRegister & AFX_WNDCOMMCTL_TAB_REG)
 {
  init.dwICC = ICC_TAB_CLASSES;
  fRegisteredClasses |= _AfxInitCommonControls(&init, AFX_WNDCOMMCTL_TAB_REG);
 }
 if (fToRegister & AFX_WNDCOMMCTL_PROGRESS_REG)
 {
  init.dwICC = ICC_PROGRESS_CLASS;
  fRegisteredClasses |= _AfxInitCommonControls(&init, AFX_WNDCOMMCTL_PROGRESS_REG);
 }
 if (fToRegister & AFX_WNDCOMMCTL_LISTVIEW_REG)
 {
  init.dwICC = ICC_LISTVIEW_CLASSES;
  fRegisteredClasses |= _AfxInitCommonControls(&init, AFX_WNDCOMMCTL_LISTVIEW_REG);
 }
 if (fToRegister & AFX_WNDCOMMCTL_HOTKEY_REG)
 {
  init.dwICC = ICC_HOTKEY_CLASS;
  fRegisteredClasses |= _AfxInitCommonControls(&init, AFX_WNDCOMMCTL_HOTKEY_REG);
 }
 if (fToRegister & AFX_WNDCOMMCTL_BAR_REG)
 {
  init.dwICC = ICC_BAR_CLASSES;
  fRegisteredClasses |= _AfxInitCommonControls(&init, AFX_WNDCOMMCTL_BAR_REG);
 }
 if (fToRegister & AFX_WNDCOMMCTL_ANIMATE_REG)
 {
  init.dwICC = ICC_ANIMATE_CLASS;
  fRegisteredClasses |= _AfxInitCommonControls(&init, AFX_WNDCOMMCTL_ANIMATE_REG);
 }
 if (fToRegister & AFX_WNDCOMMCTL_INTERNET_REG)
 {
  init.dwICC = ICC_INTERNET_CLASSES;
  fRegisteredClasses |= _AfxInitCommonControls(&init, AFX_WNDCOMMCTL_INTERNET_REG);
 }
 if (fToRegister & AFX_WNDCOMMCTL_COOL_REG)
 {
  init.dwICC = ICC_COOL_CLASSES;
  fRegisteredClasses |= _AfxInitCommonControls(&init, AFX_WNDCOMMCTL_COOL_REG);
 }
 if (fToRegister & AFX_WNDCOMMCTL_USEREX_REG)
 {
  init.dwICC = ICC_USEREX_CLASSES;
  fRegisteredClasses |= _AfxInitCommonControls(&init, AFX_WNDCOMMCTL_USEREX_REG);
 }
 if (fToRegister & AFX_WNDCOMMCTL_DATE_REG)
 {
  init.dwICC = ICC_DATE_CLASSES;
  fRegisteredClasses |= _AfxInitCommonControls(&init, AFX_WNDCOMMCTL_DATE_REG);
 }
 if (fToRegister & AFX_WNDCOMMCTL_LINK_REG)
 {
  init.dwICC = ICC_LINK_CLASS;
  fRegisteredClasses |= _AfxInitCommonControls(&init, AFX_WNDCOMMCTL_LINK_REG);
 }


 // save new state of registered controls
 pModuleState->m_fRegisteredClasses |= fRegisteredClasses;

 // special case for all common controls registered, turn on AFX_WNDCOMMCTLS_REG
 if ((pModuleState->m_fRegisteredClasses & AFX_WIN95CTLS_MASK) == AFX_WIN95CTLS_MASK)
 {
  pModuleState->m_fRegisteredClasses |= AFX_WNDCOMMCTLS_REG;
  fRegisteredClasses |= AFX_WNDCOMMCTLS_REG;
 }

 // must have registered at least as mamy classes as requested
 return (fToRegister & fRegisteredClasses) == fToRegister;
}


#include<wincore.cpp>
/////////////////////////////////////////////////////////////////////////////
// Standard init called by WinMain

AFX_STATIC BOOL AFXAPI _AfxRegisterWithIcon(WNDCLASS* pWndCls,
 LPCTSTR lpszClassName, UINT nIDIcon)
{
 pWndCls->lpszClassName = lpszClassName;
 HINSTANCE hInst = AfxFindResourceHandle(
  ATL_MAKEINTRESOURCE(nIDIcon), ATL_RT_GROUP_ICON);
 if ((pWndCls->hIcon = ::LoadIcon(hInst, ATL_MAKEINTRESOURCE(nIDIcon))) == NULL)
 {
  // use default icon
  pWndCls->hIcon = ::LoadIcon(NULL, IDI_APPLICATION);
 }
 return AfxRegisterClass(pWndCls);
}

#include<wincore.cpp>
BOOL AFXAPI AfxRegisterClass(WNDCLASS* lpWndClass)
{
 WNDCLASS wndcls;  
 if (AfxCtxGetClassInfo(lpWndClass->hInstance, lpWndClass->lpszClassName,
  &wndcls))
 {
  // class already registered
  return TRUE;
 }

 if (!::AfxCtxRegisterClass(lpWndClass))
 {
  TRACE(traceAppMsg, 0, _T("Can't register window class named %s\n"),
   lpWndClass->lpszClassName);
  return FALSE;
 }

 BOOL bRet = TRUE;

 if (afxContextIsDLL)
 {
  AfxLockGlobals(CRIT_REGCLASSLIST);
  TRY
  {
   // class registered successfully, add to registered list
   AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
   pModuleState->m_strUnregisterList+=lpWndClass->lpszClassName;
   pModuleState->m_strUnregisterList+='\n';
  }
  CATCH_ALL(e)
  {
   AfxUnlockGlobals(CRIT_REGCLASSLIST);
   THROW_LAST();
   // Note: DELETE_EXCEPTION not required.
  }
  END_CATCH_ALL
  AfxUnlockGlobals(CRIT_REGCLASSLIST);
 }

 return bRet;
}


#include<winfrm.cpp>
LPCTSTR CFrameWnd::GetIconWndClass(DWORD dwDefaultStyle, UINT nIDResource)
{
 ASSERT_VALID_IDR(nIDResource);
 HINSTANCE hInst = AfxFindResourceHandle(
  ATL_MAKEINTRESOURCE(nIDResource), ATL_RT_GROUP_ICON);
 HICON hIcon = ::LoadIcon(hInst, ATL_MAKEINTRESOURCE(nIDResource));
 if (hIcon != NULL)
 {
  CREATESTRUCT cs;
  memset(&cs, 0, sizeof(CREATESTRUCT));
  cs.style = dwDefaultStyle;
  PreCreateWindow(cs);
   // will fill lpszClassName with default WNDCLASS name
   // ignore instance handle from PreCreateWindow.

  WNDCLASS wndcls;
  if (cs.lpszClass != NULL &&
   AfxCtxGetClassInfo(AfxGetInstanceHandle(), cs.lpszClass, &wndcls) &&
   wndcls.hIcon != hIcon)
  {
   // register a very similar WNDCLASS
   return AfxRegisterWndClass(wndcls.style,
    wndcls.hCursor, wndcls.hbrBackground, hIcon);
  }
 }
 return NULL;        // just use the default
}


#include<MainFrm.cpp>
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
 if( !CFrameWnd::PreCreateWindow(cs) )
  return FALSE;
 // TODO: 在此处通过修改
 //  CREATESTRUCT cs 来修改窗口类或样式

 cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
 cs.lpszClass = AfxRegisterWndClass(0);
 return TRUE;
}


#include<winfrm.cpp>
BOOL CFrameWnd::PreCreateWindow(CREATESTRUCT& cs)
{
 if (cs.lpszClass == NULL)
 {
  VERIFY(AfxDeferRegisterClass(AFX_WNDFRAMEORVIEW_REG));
  cs.lpszClass = _afxWndFrameOrView;  // COLOR_WINDOW background
 }

 if (cs.style & FWS_ADDTOTITLE)
  cs.style |= FWS_PREFIXTITLE;

 cs.dwExStyle |= WS_EX_CLIENTEDGE;

 return TRUE;
}


LPCTSTR AFXAPI AfxRegisterWndClass(UINT nClassStyle,
 HCURSOR hCursor, HBRUSH hbrBackground, HICON hIcon)
{
 // Returns a temporary string name for the class
 //  Save in a CString if you want to use it for a long time
 LPTSTR lpszName = AfxGetThreadState()->m_szTempClassName;

 // generate a synthetic name for this class
 HINSTANCE hInst = AfxGetInstanceHandle();

 if (hCursor == NULL && hbrBackground == NULL && hIcon == NULL)
 {
  ATL_CRT_ERRORCHECK_SPRINTF(_sntprintf_s(lpszName, _AFX_TEMP_CLASS_NAME_SIZE, _AFX_TEMP_CLASS_NAME_SIZE - 1, _T("Afx:%p:%x"), hInst, nClassStyle));
 }
 else
 {
  ATL_CRT_ERRORCHECK_SPRINTF(_sntprintf_s(lpszName, _AFX_TEMP_CLASS_NAME_SIZE, _AFX_TEMP_CLASS_NAME_SIZE - 1, _T("Afx:%p:%x:%p:%p:%p"), hInst, nClassStyle,
   hCursor, hbrBackground, hIcon));
 }
 
 // see if the class already exists
 WNDCLASS wndcls;
 if (::AfxCtxGetClassInfo(hInst, lpszName, &wndcls))
 {
  // already registered, assert everything is good
  ASSERT(wndcls.style == nClassStyle);

  // NOTE: We have to trust that the hIcon, hbrBackground, and the
  //  hCursor are semantically the same, because sometimes Windows does
  //  some internal translation or copying of those handles before
  //  storing them in the internal WNDCLASS retrieved by GetClassInfo.
  return lpszName;
 }

 // otherwise we need to register a new class
 wndcls.style = nClassStyle;
 wndcls.lpfnWndProc = DefWindowProc;
 wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
 wndcls.hInstance = hInst;
 wndcls.hIcon = hIcon;
 wndcls.hCursor = hCursor;
 wndcls.hbrBackground = hbrBackground;
 wndcls.lpszMenuName = NULL;
 wndcls.lpszClassName = lpszName;
 if (!AfxRegisterClass(&wndcls))
  AfxThrowResourceException();

 // return thread-local pointer
 return lpszName;
}

#include<winfrm.cpp>
BOOL CFrameWnd::Create(LPCTSTR lpszClassName,
 LPCTSTR lpszWindowName,
 DWORD dwStyle,
 const RECT& rect,
 CWnd* pParentWnd,
 LPCTSTR lpszMenuName,
 DWORD dwExStyle,
 CCreateContext* pContext)
{
 HMENU hMenu = NULL;
 if (lpszMenuName != NULL)
 {
  // load in a menu that will get destroyed when window gets destroyed
  HINSTANCE hInst = AfxFindResourceHandle(lpszMenuName, ATL_RT_MENU);
  if ((hMenu = ::LoadMenu(hInst, lpszMenuName)) == NULL)
  {
   TRACE(traceAppMsg, 0, "Warning: failed to load menu for CFrameWnd.\n");
   PostNcDestroy();            // perhaps delete the C++ object
   return FALSE;
  }
 }

 m_strTitle = lpszWindowName;    // save title for later

 if (!CreateEx(dwExStyle, lpszClassName, lpszWindowName, dwStyle,
  rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
  pParentWnd->GetSafeHwnd(), hMenu, (LPVOID)pContext))
 {
  TRACE(traceAppMsg, 0, "Warning: failed to create CFrameWnd.\n");
  if (hMenu != NULL)
   DestroyMenu(hMenu);
  return FALSE;
 }

 return TRUE;
}


BOOL CWnd::CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName,
 LPCTSTR lpszWindowName, DWORD dwStyle,
 int x, int y, int nWidth, int nHeight,
 HWND hWndParent, HMENU nIDorHMenu, LPVOID lpParam)
{
 ASSERT(lpszClassName == NULL || AfxIsValidString(lpszClassName) ||
  AfxIsValidAtom(lpszClassName));
 ENSURE_ARG(lpszWindowName == NULL || AfxIsValidString(lpszWindowName));
 
 // allow modification of several common create parameters
 CREATESTRUCT cs;
 cs.dwExStyle = dwExStyle;
 cs.lpszClass = lpszClassName;
 cs.lpszName = lpszWindowName;
 cs.style = dwStyle;
 cs.x = x;
 cs.y = y;
 cs.cx = nWidth;
 cs.cy = nHeight;
 cs.hwndParent = hWndParent;
 cs.hMenu = nIDorHMenu;
 cs.hInstance = AfxGetInstanceHandle();
 cs.lpCreateParams = lpParam;

 if (!PreCreateWindow(cs))
 {
  PostNcDestroy();
  return FALSE;
 }

 AfxHookWindowCreate(this);
 HWND hWnd = ::AfxCtxCreateWindowEx(cs.dwExStyle, cs.lpszClass,
   cs.lpszName, cs.style, cs.x, cs.y, cs.cx, cs.cy,
   cs.hwndParent, cs.hMenu, cs.hInstance, cs.lpCreateParams);

#ifdef _DEBUG
 if (hWnd == NULL)
 {
  TRACE(traceAppMsg, 0, "Warning: Window creation failed: GetLastError returns 0x%8.8X\n",
   GetLastError());
 }
#endif

 if (!AfxUnhookWindowCreate())
  PostNcDestroy();        // cleanup if CreateWindowEx fails too soon

 if (hWnd == NULL)
  return FALSE;
 ASSERT(hWnd == m_hWnd); // should have been set in send msg hook
 return TRUE;
}

#include<wincore.cpp>
void AFXAPI AfxHookWindowCreate(CWnd* pWnd)
{
 _AFX_THREAD_STATE* pThreadState = _afxThreadState.GetData();
 if (pThreadState->m_pWndInit == pWnd)
  return;

 if (pThreadState->m_hHookOldCbtFilter == NULL)
 {
  pThreadState->m_hHookOldCbtFilter = ::SetWindowsHookEx(WH_CBT,
   _AfxCbtFilterHook, NULL, ::GetCurrentThreadId());
  if (pThreadState->m_hHookOldCbtFilter == NULL)
   AfxThrowMemoryException();
 }
 ASSERT(pThreadState->m_hHookOldCbtFilter != NULL);
 ASSERT(pWnd != NULL);
 ASSERT(pWnd->m_hWnd == NULL);   // only do once

 ASSERT(pThreadState->m_pWndInit == NULL);   // hook not already in progress
 pThreadState->m_pWndInit = pWnd;
}


#include<wincore.cpp>
LRESULT CALLBACK
_AfxCbtFilterHook(int code, WPARAM wParam, LPARAM lParam)
{
 _AFX_THREAD_STATE* pThreadState = _afxThreadState.GetData();
 if (code != HCBT_CREATEWND)
 {
  // wait for HCBT_CREATEWND just pass others on...
  return CallNextHookEx(pThreadState->m_hHookOldCbtFilter, code,
   wParam, lParam);
 }

 ASSERT(lParam != NULL);
 LPCREATESTRUCT lpcs = ((LPCBT_CREATEWND)lParam)->lpcs;
 ASSERT(lpcs != NULL);

 CWnd* pWndInit = pThreadState->m_pWndInit;
 BOOL bContextIsDLL = afxContextIsDLL;
 if (pWndInit != NULL || (!(lpcs->style & WS_CHILD) && !bContextIsDLL))
 {
  // Note: special check to avoid subclassing the IME window
  if (_afxDBCS)
  {
   // check for cheap CS_IME style first...
   if (GetClassLong((HWND)wParam, GCL_STYLE) & CS_IME)
    goto lCallNextHook;

   // get class name of the window that is being created
   LPCTSTR pszClassName;
   TCHAR szClassName[_countof("ime")+1];
   if (DWORD_PTR(lpcs->lpszClass) > 0xffff)
   {
    pszClassName = lpcs->lpszClass;
   }
   else
   {
    szClassName[0] = '\0';
    GlobalGetAtomName((ATOM)lpcs->lpszClass, szClassName, _countof(szClassName));
    pszClassName = szClassName;
   }

   // a little more expensive to test this way, but necessary...
   if (::AfxInvariantStrICmp(pszClassName, _T("ime")) == 0)
    goto lCallNextHook;
  }

  ASSERT(wParam != NULL); // should be non-NULL HWND
  HWND hWnd = (HWND)wParam;
  WNDPROC oldWndProc;
  if (pWndInit != NULL)
  {
   AFX_MANAGE_STATE(pWndInit->m_pModuleState);

   // the window should not be in the permanent map at this time
   ASSERT(CWnd::FromHandlePermanent(hWnd) == NULL);

   // connect the HWND to pWndInit...
   pWndInit->Attach(hWnd);
   // allow other subclassing to occur first
   pWndInit->PreSubclassWindow();

   WNDPROC *pOldWndProc = pWndInit->GetSuperWndProcAddr();
   ASSERT(pOldWndProc != NULL);

   // subclass the window with standard AfxWndProc
   WNDPROC afxWndProc = AfxGetAfxWndProc();
   oldWndProc = (WNDPROC)SetWindowLongPtr(hWnd, GWLP_WNDPROC,
    (DWORD_PTR)afxWndProc);
   ASSERT(oldWndProc != NULL);
   if (oldWndProc != afxWndProc)
    *pOldWndProc = oldWndProc;

   pThreadState->m_pWndInit = NULL;
  }
  else
  {
   ASSERT(!bContextIsDLL);   // should never get here

   static ATOM s_atomMenu = 0;
   bool bSubclass = true;   

   if (s_atomMenu == 0)
   {
    WNDCLASSEX wc;
    memset(&wc, 0, sizeof(WNDCLASSEX));
    wc.cbSize = sizeof(WNDCLASSEX);
    s_atomMenu = (ATOM)::AfxCtxGetClassInfoEx(NULL, _T("#32768"), &wc);
   }

   // Do not subclass menus.
   if (s_atomMenu != 0)
   {
    ATOM atomWnd = (ATOM)::GetClassLongPtr(hWnd, GCW_ATOM);
    if (atomWnd == s_atomMenu)
      bSubclass = false;
   }
   else
   {   
    TCHAR szClassName[256];
    if (::GetClassName(hWnd, szClassName, 256))
    {
     szClassName[255] = NULL;
     if (_tcscmp(szClassName, _T("#32768")) == 0)
      bSubclass = false;
    }
   }   
   if (bSubclass)
   {
    // subclass the window with the proc which does gray backgrounds
    oldWndProc = (WNDPROC)GetWindowLongPtr(hWnd, GWLP_WNDPROC);
    if (oldWndProc != NULL && GetProp(hWnd, _afxOldWndProc) == NULL)
    {
     SetProp(hWnd, _afxOldWndProc, oldWndProc);
     if ((WNDPROC)GetProp(hWnd, _afxOldWndProc) == oldWndProc)
     {
      GlobalAddAtom(_afxOldWndProc);
      SetWindowLongPtr(hWnd, GWLP_WNDPROC, (DWORD_PTR)_AfxActivationWndProc);
      ASSERT(oldWndProc != NULL);
     }
    }
   }
  }
 }

lCallNextHook:
 LRESULT lResult = CallNextHookEx(pThreadState->m_hHookOldCbtFilter, code,
  wParam, lParam);

#ifndef _AFXDLL
 if (bContextIsDLL)
 {
  ::UnhookWindowsHookEx(pThreadState->m_hHookOldCbtFilter);
  pThreadState->m_hHookOldCbtFilter = NULL;
 }
#endif
 return lResult;
}

#include<wincore.cpp>
LRESULT CALLBACK
AfxWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
 // special message which identifies the window as using AfxWndProc
 if (nMsg == WM_QUERYAFXWNDPROC)
  return 1;

 // all other messages route through message map
 CWnd* pWnd = CWnd::FromHandlePermanent(hWnd);
 ASSERT(pWnd != NULL);     
 ASSERT(pWnd==NULL || pWnd->m_hWnd == hWnd);
 if (pWnd == NULL || pWnd->m_hWnd != hWnd)
  return ::DefWindowProc(hWnd, nMsg, wParam, lParam);
 return AfxCallWndProc(pWnd, hWnd, nMsg, wParam, lParam);
}


#include<wincore.cpp>
// Official way to send message to a CWnd

LRESULT AFXAPI AfxCallWndProc(CWnd* pWnd, HWND hWnd, UINT nMsg,
 WPARAM wParam = 0, LPARAM lParam = 0)
{
 _AFX_THREAD_STATE* pThreadState = _afxThreadState.GetData();
 MSG oldState = pThreadState->m_lastSentMsg;   // save for nesting
 pThreadState->m_lastSentMsg.hwnd = hWnd;
 pThreadState->m_lastSentMsg.message = nMsg;
 pThreadState->m_lastSentMsg.wParam = wParam;
 pThreadState->m_lastSentMsg.lParam = lParam;

#ifdef _DEBUG
 _AfxTraceMsg(_T("WndProc"), &pThreadState->m_lastSentMsg);
#endif

 // Catch exceptions thrown outside the scope of a callback
 // in debug builds and warn the user.
 LRESULT lResult;
 TRY
 {
#ifndef _AFX_NO_OCC_SUPPORT
  // special case for WM_DESTROY
  if ((nMsg == WM_DESTROY) && (pWnd->m_pCtrlCont != NULL))
   pWnd->m_pCtrlCont->OnUIActivate(NULL);    
#endif

  // special case for WM_INITDIALOG
  CRect rectOld;
  DWORD dwStyle = 0;
  if (nMsg == WM_INITDIALOG)
   _AfxPreInitDialog(pWnd, &rectOld, &dwStyle);

  // delegate to object's WindowProc
  lResult = pWnd->WindowProc(nMsg, wParam, lParam);

  // more special case for WM_INITDIALOG
  if (nMsg == WM_INITDIALOG)
   _AfxPostInitDialog(pWnd, rectOld, dwStyle);
 }
 CATCH_ALL(e)
 {
  lResult = AfxProcessWndProcException(e, &pThreadState->m_lastSentMsg);
  TRACE(traceAppMsg, 0, "Warning: Uncaught exception in WindowProc (returning %ld).\n",
   lResult);
  DELETE_EXCEPTION(e);
 }
 END_CATCH_ALL

 pThreadState->m_lastSentMsg = oldState;
 return lResult;
}

#include<thrdcore.cpp>
BOOL CWinThread::PumpMessage()
{
  return AfxInternalPumpMessage();
}


#include<thrdcore.cpp>
BOOL AFXAPI AfxInternalPumpMessage()
{
 _AFX_THREAD_STATE *pState = AfxGetThreadState();

 if (!::GetMessage(&(pState->m_msgCur), NULL, NULL, NULL))
 {
#ifdef _DEBUG
  TRACE(traceAppMsg, 1, "CWinThread::PumpMessage - Received WM_QUIT.\n");
   pState->m_nDisablePumpCount++; // application must die
#endif
  // Note: prevents calling message loop things in 'ExitInstance'
  // will never be decremented
  return FALSE;
 }

#ifdef _DEBUG
  if (pState->m_nDisablePumpCount != 0)
 {
   TRACE(traceAppMsg, 0, "Error: CWinThread::PumpMessage called when not permitted.\n");
   ASSERT(FALSE);
 }
#endif

#ifdef _DEBUG
 _AfxTraceMsg(_T("PumpMessage"), &(pState->m_msgCur));
#endif

  // process this message

 if (pState->m_msgCur.message != WM_KICKIDLE && !AfxPreTranslateMessage(&(pState->m_msgCur)))
 {
  ::TranslateMessage(&(pState->m_msgCur));
  ::DispatchMessage(&(pState->m_msgCur));
 }
  return TRUE;
}


#include<wincore.cpp>
// main WindowProc implementation
LRESULT CWnd::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
 // OnWndMsg does most of the work, except for DefWindowProc call
 LRESULT lResult = 0;
 if (!OnWndMsg(message, wParam, lParam, &lResult))
  lResult = DefWindowProc(message, wParam, lParam);
 return lResult;
}

#include<wincore.cpp>
BOOL CWnd::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
 LRESULT lResult = 0;
 union MessageMapFunctions mmf;
 mmf.pfn = 0;
 CInternalGlobalLock winMsgLock;
 // special case for commands
 if (message == WM_COMMAND)
 {
  if (OnCommand(wParam, lParam))
  {
   lResult = 1;
   goto LReturnTrue;
  }
  return FALSE;
 }

 // special case for notifies
 if (message == WM_NOTIFY)
 {
  NMHDR* pNMHDR = (NMHDR*)lParam;
  if (pNMHDR->hwndFrom != NULL && OnNotify(wParam, lParam, &lResult))
   goto LReturnTrue;
  return FALSE;
 }

 // special case for activation
 if (message == WM_ACTIVATE)
  _AfxHandleActivate(this, wParam, CWnd::FromHandle((HWND)lParam));

 // special case for set cursor HTERROR
 if (message == WM_SETCURSOR &&
  _AfxHandleSetCursor(this, (short)LOWORD(lParam), HIWORD(lParam)))
 {
  lResult = 1;
  goto LReturnTrue;
 }

   // special case for windows that contain windowless ActiveX controls
   BOOL bHandled;

   bHandled = FALSE;
   if ((m_pCtrlCont != NULL) && (m_pCtrlCont->m_nWindowlessControls > 0))
   {
   if (((message >= WM_MOUSEFIRST) && (message <= AFX_WM_MOUSELAST)) ||
   ((message >= WM_KEYFIRST) && (message <= WM_IME_KEYLAST)) ||
   ((message >= WM_IME_SETCONTEXT) && (message <= WM_IME_KEYUP)))
   {
   bHandled = m_pCtrlCont->HandleWindowlessMessage(message, wParam, lParam, &lResult);
   }
   }
   if (bHandled)
   {
   goto LReturnTrue;
   }

 const AFX_MSGMAP* pMessageMap; pMessageMap = GetMessageMap();
 UINT iHash; iHash = (LOWORD((DWORD_PTR)pMessageMap) ^ message) & (iHashMax-1);
 winMsgLock.Lock(CRIT_WINMSGCACHE);
 AFX_MSG_CACHE* pMsgCache; pMsgCache = &_afxMsgCache[iHash];
 const AFX_MSGMAP_ENTRY* lpEntry;
 if (message == pMsgCache->nMsg && pMessageMap == pMsgCache->pMessageMap)
 {
  // cache hit
  lpEntry = pMsgCache->lpEntry;
  winMsgLock.Unlock();
  if (lpEntry == NULL)
   return FALSE;

  // cache hit, and it needs to be handled
  if (message < 0xC000)
   goto LDispatch;
  else
   goto LDispatchRegistered;
 }
 else
 {
  // not in cache, look for it
  pMsgCache->nMsg = message;
  pMsgCache->pMessageMap = pMessageMap;

  for (/* pMessageMap already init'ed */; pMessageMap->pfnGetBaseMap != NULL;
   pMessageMap = (*pMessageMap->pfnGetBaseMap)())
  {
   // Note: catch not so common but fatal mistake!!
   //      BEGIN_MESSAGE_MAP(CMyWnd, CMyWnd)
   ASSERT(pMessageMap != (*pMessageMap->pfnGetBaseMap)());
   if (message < 0xC000)
   {
    // constant window message
    if ((lpEntry = AfxFindMessageEntry(pMessageMap->lpEntries,
     message, 0, 0)) != NULL)
    {
     pMsgCache->lpEntry = lpEntry;
     winMsgLock.Unlock();
     goto LDispatch;
    }
   }
   else
   {
    // registered windows message
    lpEntry = pMessageMap->lpEntries;
    while ((lpEntry = AfxFindMessageEntry(lpEntry, 0xC000, 0, 0)) != NULL)
    {
     UINT* pnID = (UINT*)(lpEntry->nSig);
     ASSERT(*pnID >= 0xC000 || *pnID == 0);
      // must be successfully registered
     if (*pnID == message)
     {
      pMsgCache->lpEntry = lpEntry;
      winMsgLock.Unlock();
      goto LDispatchRegistered;
     }
     lpEntry++;      // keep looking past this one
    }
   }
  }

  pMsgCache->lpEntry = NULL;
  winMsgLock.Unlock();
  return FALSE;
 }

LDispatch:
 ASSERT(message < 0xC000);

 mmf.pfn = lpEntry->pfn;

 switch (lpEntry->nSig)
 {
 default:
  ASSERT(FALSE);
  break;
 case AfxSig_l_p:
  {
   CPoint point(lParam);  
   lResult = (this->*mmf.pfn_l_p)(point);
   break;
  }  
 case AfxSig_b_D_v:
  lResult = (this->*mmf.pfn_b_D)(CDC::FromHandle(reinterpret_cast<HDC>(wParam)));
  break;

 case AfxSig_b_b_v:
  lResult = (this->*mmf.pfn_b_b)(static_cast<BOOL>(wParam));
  break;

 case AfxSig_b_u_v:
  lResult = (this->*mmf.pfn_b_u)(static_cast<UINT>(wParam));
  break;

 case AfxSig_b_h_v:
  lResult = (this->*mmf.pfn_b_h)(reinterpret_cast<HANDLE>(wParam));
  break;

 case AfxSig_i_u_v:
  lResult = (this->*mmf.pfn_i_u)(static_cast<UINT>(wParam));
  break;

 case AfxSig_C_v_v:
  lResult = reinterpret_cast<LRESULT>((this->*mmf.pfn_C_v)());
  break;

 case AfxSig_v_u_W:
  (this->*mmf.pfn_v_u_W)(static_cast<UINT>(wParam),
   CWnd::FromHandle(reinterpret_cast<HWND>(lParam)));
  break;

 case AfxSig_u_u_v:
  lResult = (this->*mmf.pfn_u_u)(static_cast<UINT>(wParam));
  break;

 case AfxSig_b_v_v:
  lResult = (this->*mmf.pfn_b_v)();
  break;

 case AfxSig_b_W_uu:
  lResult = (this->*mmf.pfn_b_W_u_u)(CWnd::FromHandle(reinterpret_cast<HWND>(wParam)),
   LOWORD(lParam), HIWORD(lParam));
  break;

 case AfxSig_b_W_COPYDATASTRUCT:
  lResult = (this->*mmf.pfn_b_W_COPYDATASTRUCT)(
   CWnd::FromHandle(reinterpret_cast<HWND>(wParam)),
   reinterpret_cast<COPYDATASTRUCT*>(lParam));
  break;

 case AfxSig_b_v_HELPINFO:
  lResult = (this->*mmf.pfn_b_HELPINFO)(reinterpret_cast<LPHELPINFO>(lParam));
  break;

 case AfxSig_CTLCOLOR:
  {
   // special case for OnCtlColor to avoid too many temporary objects
   ASSERT(message == WM_CTLCOLOR);
   AFX_CTLCOLOR* pCtl = reinterpret_cast<AFX_CTLCOLOR*>(lParam);
   CDC dcTemp;
   dcTemp.m_hDC = pCtl->hDC;
   CWnd wndTemp;
   wndTemp.m_hWnd = pCtl->hWnd;
   UINT nCtlType = pCtl->nCtlType;
   // if not coming from a permanent window, use stack temporary
   CWnd* pWnd = CWnd::FromHandlePermanent(wndTemp.m_hWnd);
   if (pWnd == NULL)
   {
#ifndef _AFX_NO_OCC_SUPPORT
    // determine the site of the OLE control if it is one
    COleControlSite* pSite;
    if (m_pCtrlCont != NULL && (pSite = (COleControlSite*)
     m_pCtrlCont->m_siteMap.GetValueAt(wndTemp.m_hWnd)) != NULL)
    {
     wndTemp.m_pCtrlSite = pSite;
    }
#endif
    pWnd = &wndTemp;
   }
   HBRUSH hbr = (this->*mmf.pfn_B_D_W_u)(&dcTemp, pWnd, nCtlType);
   // fast detach of temporary objects
   dcTemp.m_hDC = NULL;
   wndTemp.m_hWnd = NULL;
   lResult = reinterpret_cast<LRESULT>(hbr);
  }
  break;

 case AfxSig_CTLCOLOR_REFLECT:
  {
   // special case for CtlColor to avoid too many temporary objects
   ASSERT(message == WM_REFLECT_BASE+WM_CTLCOLOR);
   AFX_CTLCOLOR* pCtl = reinterpret_cast<AFX_CTLCOLOR*>(lParam);
   CDC dcTemp;
   dcTemp.m_hDC = pCtl->hDC;
   UINT nCtlType = pCtl->nCtlType;
   HBRUSH hbr = (this->*mmf.pfn_B_D_u)(&dcTemp, nCtlType);
   // fast detach of temporary objects
   dcTemp.m_hDC = NULL;
   lResult = reinterpret_cast<LRESULT>(hbr);
  }
  break;

 case AfxSig_i_u_W_u:
  lResult = (this->*mmf.pfn_i_u_W_u)(LOWORD(wParam),
   CWnd::FromHandle(reinterpret_cast<HWND>(lParam)), HIWORD(wParam));
  break;

 case AfxSig_i_uu_v:
  lResult = (this->*mmf.pfn_i_u_u)(LOWORD(wParam), HIWORD(wParam));
  break;

 case AfxSig_i_W_uu:
  lResult = (this->*mmf.pfn_i_W_u_u)(CWnd::FromHandle(reinterpret_cast<HWND>(wParam)),
   LOWORD(lParam), HIWORD(lParam));
  break;

 case AfxSig_i_v_s:
  lResult = (this->*mmf.pfn_i_s)(reinterpret_cast<LPTSTR>(lParam));
  break;

 case AfxSig_l_w_l:
  lResult = (this->*mmf.pfn_l_w_l)(wParam, lParam);
  break;

 case AfxSig_l_uu_M:
  lResult = (this->*mmf.pfn_l_u_u_M)(LOWORD(wParam), HIWORD(wParam),
   CMenu::FromHandle(reinterpret_cast<HMENU>(lParam)));
  break;
  
 case AfxSig_v_b_h:
     (this->*mmf.pfn_v_b_h)(static_cast<BOOL>(wParam),
   reinterpret_cast<HANDLE>(lParam));
  break;

 case AfxSig_v_h_v:
     (this->*mmf.pfn_v_h)(reinterpret_cast<HANDLE>(wParam));
  break;

 case AfxSig_v_h_h:
     (this->*mmf.pfn_v_h_h)(reinterpret_cast<HANDLE>(wParam),
   reinterpret_cast<HANDLE>(lParam));
  break;

 case AfxSig_v_v_v:
  (this->*mmf.pfn_v_v)();
  break;

 case AfxSig_v_u_v:
  (this->*mmf.pfn_v_u)(static_cast<UINT>(wParam));
  break;

 case AfxSig_v_u_u:
  (this->*mmf.pfn_v_u_u)(static_cast<UINT>(wParam), static_cast<UINT>(lParam));
  break;

 case AfxSig_v_uu_v:
  (this->*mmf.pfn_v_u_u)(LOWORD(wParam), HIWORD(wParam));
  break;

 case AfxSig_v_v_ii:
  (this->*mmf.pfn_v_i_i)(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
  break;

 case AfxSig_v_u_uu:
  (this->*mmf.pfn_v_u_u_u)(static_cast<UINT>(wParam), LOWORD(lParam), HIWORD(lParam));
  break;

 case AfxSig_v_u_ii:
  (this->*mmf.pfn_v_u_i_i)(static_cast<UINT>(wParam), LOWORD(lParam), HIWORD(lParam));
  break;

 case AfxSig_v_w_l:
  (this->*mmf.pfn_v_w_l)(wParam, lParam);
  break;

 case AfxSig_MDIACTIVATE:
  (this->*mmf.pfn_v_b_W_W)(m_hWnd == reinterpret_cast<HWND>(lParam),
   CWnd::FromHandle(reinterpret_cast<HWND>(lParam)),
   CWnd::FromHandle(reinterpret_cast<HWND>(wParam)));
  break;

 case AfxSig_v_D_v:
  (this->*mmf.pfn_v_D)(CDC::FromHandle(reinterpret_cast<HDC>(wParam)));
  break;

 case AfxSig_v_M_v:
  (this->*mmf.pfn_v_M)(CMenu::FromHandle(reinterpret_cast<HMENU>(wParam)));
  break;

 case AfxSig_v_M_ub:
  (this->*mmf.pfn_v_M_u_b)(CMenu::FromHandle(reinterpret_cast<HMENU>(wParam)),
   GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
  break;

 case AfxSig_v_W_v:
  (this->*mmf.pfn_v_W)(CWnd::FromHandle(reinterpret_cast<HWND>(wParam)));
  break;

 case AfxSig_v_v_W:
  (this->*mmf.pfn_v_W)(CWnd::FromHandle(reinterpret_cast<HWND>(lParam)));
  break;

 case AfxSig_v_W_uu:
  (this->*mmf.pfn_v_W_u_u)(CWnd::FromHandle(reinterpret_cast<HWND>(wParam)), LOWORD(lParam),
   HIWORD(lParam));
  break;

 case AfxSig_v_W_p:
  {
   CPoint point(lParam);
   (this->*mmf.pfn_v_W_p)(CWnd::FromHandle(reinterpret_cast<HWND>(wParam)), point);
  }
  break;

 case AfxSig_v_W_h:
  (this->*mmf.pfn_v_W_h)(CWnd::FromHandle(reinterpret_cast<HWND>(wParam)),
    reinterpret_cast<HANDLE>(lParam));
  break;

 case AfxSig_ACTIVATE:
  (this->*mmf.pfn_v_u_W_b)(LOWORD(wParam),
   CWnd::FromHandle(reinterpret_cast<HWND>(lParam)), HIWORD(wParam));
  break;

 case AfxSig_SCROLL:
 case AfxSig_SCROLL_REFLECT:
  {
   // special case for WM_VSCROLL and WM_HSCROLL
   ASSERT(message == WM_VSCROLL || message == WM_HSCROLL ||
    message == WM_VSCROLL+WM_REFLECT_BASE || message == WM_HSCROLL+WM_REFLECT_BASE);
   int nScrollCode = (short)LOWORD(wParam);
   int nPos = (short)HIWORD(wParam);
   if (lpEntry->nSig == AfxSig_SCROLL)
    (this->*mmf.pfn_v_u_u_W)(nScrollCode, nPos,
     CWnd::FromHandle(reinterpret_cast<HWND>(lParam)));
   else
    (this->*mmf.pfn_v_u_u)(nScrollCode, nPos);
  }
  break;

 case AfxSig_v_v_s:
  (this->*mmf.pfn_v_s)(reinterpret_cast<LPTSTR>(lParam));
  break;

 case AfxSig_v_u_cs:
  (this->*mmf.pfn_v_u_cs)(static_cast<UINT>(wParam), reinterpret_cast<LPCTSTR>(lParam));
  break;

 case AfxSig_OWNERDRAW:
  (this->*mmf.pfn_v_i_s)(static_cast<int>(wParam), reinterpret_cast<LPTSTR>(lParam));
  lResult = TRUE;
  break;

 case AfxSig_i_i_s:
  lResult = (this->*mmf.pfn_i_i_s)(static_cast<int>(wParam), reinterpret_cast<LPTSTR>(lParam));
  break;

 case AfxSig_u_v_p:
  {
   CPoint point(lParam);
   lResult = (this->*mmf.pfn_u_p)(point);
  }
  break;

 case AfxSig_u_v_v:
  lResult = (this->*mmf.pfn_u_v)();
  break;

 case AfxSig_v_b_NCCALCSIZEPARAMS:
  (this->*mmf.pfn_v_b_NCCALCSIZEPARAMS)(static_cast<BOOL>(wParam),
   reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam));
  break;

 case AfxSig_v_v_WINDOWPOS:
  (this->*mmf.pfn_v_v_WINDOWPOS)(reinterpret_cast<WINDOWPOS*>(lParam));
  break;

 case AfxSig_v_uu_M:
  (this->*mmf.pfn_v_u_u_M)(LOWORD(wParam), HIWORD(wParam), reinterpret_cast<HMENU>(lParam));
  break;

 case AfxSig_v_u_p:
  {
   CPoint point(lParam);
   (this->*mmf.pfn_v_u_p)(static_cast<UINT>(wParam), point);
  }
  break;

 case AfxSig_SIZING:
  (this->*mmf.pfn_v_u_pr)(static_cast<UINT>(wParam), reinterpret_cast<LPRECT>(lParam));
  lResult = TRUE;
  break;

 case AfxSig_MOUSEWHEEL:
  lResult = (this->*mmf.pfn_b_u_s_p)(LOWORD(wParam), (short)HIWORD(wParam),
   CPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)));
  if (!lResult)
   return FALSE;
  break;
 case AfxSig_l:
  lResult = (this->*mmf.pfn_l_v)();
  if (lResult != 0)
   return FALSE;
  break;
 }
 goto LReturnTrue;

LDispatchRegistered:    // for registered windows messages
 ASSERT(message >= 0xC000);
 ASSERT(sizeof(mmf) == sizeof(mmf.pfn));
 mmf.pfn = lpEntry->pfn;
 lResult = (this->*mmf.pfn_l_w_l)(wParam, lParam);

LReturnTrue:
 if (pResult != NULL)
  *pResult = lResult;
 return TRUE;
}

#include<winfrm.cpp>
BOOL CFrameWnd::OnCommand(WPARAM wParam, LPARAM lParam)
 // return TRUE if command invocation was attempted
{
 HWND hWndCtrl = (HWND)lParam;
 UINT nID = LOWORD(wParam);

 CFrameWnd* pFrameWnd = GetTopLevelFrame();
 ENSURE_VALID(pFrameWnd);
 if (pFrameWnd->m_bHelpMode && hWndCtrl == NULL &&
  nID != ID_HELP && nID != ID_DEFAULT_HELP && nID != ID_CONTEXT_HELP)
 {
  // route as help
  if (!SendMessage(WM_COMMANDHELP, 0, HID_BASE_COMMAND+nID))
   SendMessage(WM_COMMAND, ID_DEFAULT_HELP);
  return TRUE;
 }

 // route as normal command
 return CWnd::OnCommand(wParam, lParam);
}

posted on 2011-06-24 10:03  PeterBin  阅读(2213)  评论(0编辑  收藏  举报