首页 > 学院 > 开发设计 > 正文

MFC的Afx全局函数、其常宏、数据类型

2019-11-08 02:24:08
字体:
来源:转载
供稿:网友
一、Afx全局函数

  AfxBeginThread:开始一个新的线程

  AfxEndThread:结束一个旧的线程

  AfxFormatString1:类似PRintf一般地将字符串格式化

  AfxFormatString2:类似printf一般地将字符串格式化

  AfxMessageBox:类似Windows API 函数 MessageBox

  AfxOuputDebugString:将字符串输往除错装置

  AfxGetApp:获得application object (CWinApp派生对象)的指针

  AfxGetMainWnd:获得程序主窗口的指针

  AfxGetInstance:获得程序的instance handle

// global helpers for threadsCWinThread* AFXAPI AfxBeginThread(AFX_THREADPROC pfnThreadProc, LPVOID pParam,	int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0,	DWord dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL);
CWinThread* AFXAPI AfxBeginThread(CRuntimeClass* pThreadClass,	int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0,	DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL);CWinThread* AFXAPI AfxGetThread();MSG* AFXAPI AfxGetCurrentMessage();void AFXAPI AfxEndThread(UINT nExitCode, BOOL bDelete = TRUE);void AFXAPI AfxInitThread();void AFXAPI AfxTermThread(HINSTANCE hInstTerm = NULL);/*============================================================================*/// Global functions for access to the one and only CWinApp#define afxCurrentWinApp    AfxGetModuleState()->m_pCurrentWinApp#define afxCurrentInstanceHandle    AfxGetModuleState()->m_hCurrentInstanceHandle#define afxCurrentResourceHandle    AfxGetModuleState()->m_hCurrentResourceHandle#define afxCurrentAppName   AfxGetModuleState()->m_lpszCurrentAppName#define afxContextIsDLL     AfxGetModuleState()->m_bDLL#define afxRegisteredClasses    AfxGetModuleState()->m_fRegisteredClasses#define afxOccManager   AfxGetModuleState()->m_pOccManager// Advanced initialization: for overriding default WinMainBOOL AFXAPI AfxWinInit(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,	_In_z_ LPTSTR lpCmdLine, _In_ int nCmdShow);void AFXAPI AfxWinTerm();// Global Windows state data helper functions (inlines)#ifdef _AFXDLLULONG AFXAPI AfxGetDllVersion();#endifCWinApp* AFXAPI AfxGetApp();CWnd* AFXAPI AfxGetMainWnd();HINSTANCE AFXAPI AfxGetInstanceHandle();HINSTANCE AFXAPI AfxGetResourceHandle();void AFXAPI AfxSetResourceHandle(HINSTANCE hInstResource);LPCTSTR AFXAPI AfxGetAppName();AFX_DEPRECATED("AfxLoadLangResourceDLL(LPCTSTR pszFormat) has been deprecated, use AfxLoadLangResourceDLL(LPCTSTR pszFormat, LPCTSTR pszPath) instead")	HINSTANCE AFXAPI AfxLoadLangResourceDLL(LPCTSTR pszFormat);HINSTANCE AFXAPI AfxLoadLangResourceDLL(LPCTSTR pszFormat, LPCTSTR pszPath);// Use instead of PostQuitMessage in OLE server applicationsvoid AFXAPI AfxPostQuitMessage(int nExitCode);// Use AfxFindResourceHandle to find resource in chain of extension DLLs#ifndef _AFXDLL#define AfxFindResourceHandle(lpszResource, lpszType) AfxGetResourceHandle()#elseHINSTANCE AFXAPI AfxFindResourceHandle(LPCTSTR lpszName, LPCTSTR lpszType);#endif/// <summary>/// Deletes the subkeys and values of the specified key recursively.</summary>/// <returns> /// If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a nonzero error code defined in Winerror.h</returns>/// <param name="hKey">A handle to an open registry key.</param>/// <param name="lpSubKey">The name of the key to be deleted.</param>/// <param name="pTM">Pointer to CAtlTransactionManager object</param>LONG AFXAPI AfxDelRegTreeHelper(HKEY hParentKey, const CString& strKeyName, CAtlTransactionManager* pTM = NULL);class CRecentFileList;          // forward reference (see afxadv.h)class CDataRecoveryHandler;     // forward reference (see afxdatarecovery.h)// access to message filter in CWinAppCOleMessageFilter* AFXAPI AfxOleGetMessageFilter();/*============================================================================*/// CCommandLineInfo

二. MFC提供的主要宏:

       消息映射宏: 声明消息映射表 (将于3.2.2节介绍)宏DECLARE_MESSAGE_MAP、定义消息映射表宏BEGIN_MESSAGE_MAP和END_MESSAGE_MAP对、消息映射表入口宏ON_加消息名。

      动态 MFC对象宏: DECLARE_DYNCREATE和DECLARE_DYNAMIC, IMPLEMENT_DYNCREATE和MPLEMENT_DYNAMIC      运行时类宏: RUNTIME_CLASS      序列化宏: DECLARE_SERIAL和IMPLEMENT_SERIAL      诊断服务宏: ASSERT、VERIFY      跟踪服务宏: TRACE      异常处理宏: THROW 三、MFC数据类型  BOOL:布尔值,取值为TRUE or FALSE  BSTR:32-bit 字符指针  BYTE:8-bit整数,未带正负号  COLORREF:32-bit数值,代表一个颜色值  DWORD:32-bit整数,未带正负号  LONG:32-bit整数,带正负号  LPARAM:32-bit整数,作为窗口函数或callback函数的一个参数  LPCSTR:32-bit指针,指向一个常数字符串  LPSTR:32-bit指针,指向一个字符串  LPCTSTR:32-bit指针,指向一个常数字符串,此字符串可以移植到Unicode(世界性的字符集)和DBCS(亚洲字符集)  LPTSTR:32-bit指针,指向一个字符串,此字符串可以移植到Unicode和DBCS  LPVOID:32-bit指针,指向一个未指定类型的数据  LPRESULT:32-bit数值,作为窗口函数或callback函数的返回值  UINT:在Win16中是一个16-bit 未带正负号整数,在Win32中是一个32-bit 未带正负号整数,  WNDPROC:32-bit指针,指向一个窗口函数  WORD:16-bit 整数 ,未带正负号  WPARAM:窗口函数或callback函数的一个参数,在Win16中是16-bit,在Win32中是32-bit  下面这些是MFC独特的数据类型  POSITION:一个数值,代表collection对象(例如数组或链表)中的元素位置,常用于MFC collection classes(即数据处理类,如CArray)  LPCRECT:32-bit指针,指向一个不变的RECT结构
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表