windows function2 - yamaumima/hello.github.io GitHub Wiki

CWinApp类的基类:CObject->CCmdTarget->CWinThread->CWinApp

一、CWinApp类成员变量:

1、WinMain的四个参数:

// Startup args (do not change)

HINSTANCE m_hInstance;//进程句柄,用于加载程序内资源等功能。

HINSTANCE m_hPrevInstance;//暂时无用

LPTSTR m_lpCmdLine; //进程启动前,以字符串形式传入的一些数据。

int m_nCmdShow; //进程启动前,要求进程以什么显示状态出现。

2、应用程序名

// Running args (can be changed in InitInstance)

LPCTSTR m_pszAppName;

(a、ExeName中获取,b、AFX_IDS_APP_TITLE中获取,c、CWinApp构造函数)

// (from constructor or AFX_IDS_APP_TITLE)

LPCTSTR m_pszExeName; // executable name (no spaces)

LPCTSTR m_pszHelpFilePath; // default based on module path

LPCTSTR m_pszProfileName; // default based on app name

LPCTSTR m_pszRegistryKey; // used for registry entries

3、基类中的成员变量:

CWnd* m_pMainWnd; // main window (usually same AfxGetApp()->m_pMainWnd)

CWnd* m_pActiveWnd; // active main window (may not be m_pMainWnd)

BOOL m_bAutoDelete; // enables 'delete this' after thread termination

// only valid while running

HANDLE m_hThread; // this thread's HANDLE

operator HANDLE() const;

DWORD m_nThreadID; // this thread's ID

二、CWinApp类成员函数:

CWinApp(LPCTSTR lpszAppName=NULL);可以通过构造函数修改AppName。

HCURSOR LoadCursor( UINT nIDResource ) const;

HCURSOR LoadStandardCursor(LPCTSTR szCur)const;

HICON LoadIcon( UINT nIDResource ) const;

HICON LoadStandardIcon(LPCTSTR szIcon) const;

缺省保存进入app.ini,如果调用SetRegistryKey函数之后,配置数据将写入到注册表对应的键值下

UINT GetProfileInt( LPCTSTR lpszSection, LPCTSTR lpszEntry, int nDefault );

CString GetProfileString(LPCTSTR szSection, LPCTSTR szEntry, LPCTSTR szDefault = NULL );

BOOL WriteProfileInt(LPCTSTR szSection, LPCTSTR szEntry, int nValue );

BOOL WriteProfileString(LPCTSTR szSect, LPCTSTR szEntry, LPCTSTR lpszValue );

void SetRegistryKey( LPCTSTR lpszRegistryKey );

void SetDialogBkColor(COLORREF clrBk = RGB(192, 192, 192), COLORREF clrText = RGB(0, 0, 0) );

三、Afx开头的MFC全局函数:

AfxGetApp():获取theApp对象地址;

AfxGetThread():获取theApp对象地址;

AfxGetInstanceHandle():获取theApp.m_hInstance进程句柄。

AfxGetResourceHandle(): 一般情况下ResourceHandle就是InstanceHandle。

AfxGetAppName():获取CWinApp类成员变量theApp.m_pszAppName字符串;

### AfxGetMainWnd():调用了CWinApp类基类函数GetMainWnd();

优先返回m_pMainWnd,如果m_pMainWnd为空,就通过GetActiveWindow函数获取一个激活的窗口。

GetModuleFileName:API函数用于获取执行文件或者DLL模块的具体路径和文件名