【MFC系列-第11天】CWinApp类成员分析

11.1 资源管理器开发(C语言)

三种位运算

//#include <AtlBase.h>
//混合 c_file.attrib |= _A_HIDDEN|_A_RDONLY;
//判断使用if(c_file.attrib & _A_HIDDEN) 
//删除属性c_file.attrib&=~_A_HIDDENT;

11.2 资源管理器开发(API)

全局变量的定义和初始化
ExplorerDlg.h中定义

static LPCTSTR m_weeks[];

ExplorerDlg.cpp中赋值

LPCTSTR CExplorerDlg::m_weeks[] =
{
    
    
	_T("星期日"),
	_T("星期一"),
	_T("星期二"),
	_T("星期三"),
	_T("星期四"),
	_T("星期五"),
	_T("星期六"),
	NULL
};

11.3 资源管理器开发(MFC)

注意遍历方式

	BOOL b = ff.FindFile(szAddr + _T("\\*.*"));
	int i = 0;
	CString str;
	while(b)
	{
    
    
		b = ff.FindNextFile();
		if (ff.IsHidden() || ff.IsDots())
			continue;
		
		pList->InsertItem(i, ff.GetFileName());
		if (ff.IsDirectory())
			pList->SetItemText(i, 1, _T("文件夹"));
		else
		{
    
    
			str = ff.GetFileName();
			int n = str.ReverseFind(_T('.'));
			if(n>0)
				pList->SetItemText(i, 1, str.Mid(n+1) + _T("文件"));
			str.Format(_T("%d"), ff.GetLength());
			pList->SetItemText(i, 2, str);
		}
		FILETIME ftime;
		ff.GetLastWriteTime(&ftime);
		COleDateTime time(ftime);
		str.Format(_T("%d/%d/%d %s %d:%02d"), time.GetYear(), time.GetMonth(), time.GetDay(),
			m_weeks[time.GetDayOfWeek()-1],time.GetHour(),time.GetMinute());
		pList->SetItemText(i, 3, str);
		++i;
	};

11.4 CWinApp类成员变量

LPCSTR m_pszAppName:

a)第一先送入是在构造函数中送入,

CTestAApp::CTestAApp():CWinApp(_T("温馨提示"))
{
    
    
	// 支持重新启动管理器
	m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
}

b)第二优先是如果CWinApp构造函数没有送入,则去加载字符串表中的:AFX_IDS_APP_TITLE

c )最后什么都没有才去找执行文件名;

HINSTANCE m_hInstance; 应用程序当前进程的实例
LPTSTR m_lpCmdLine; 指向一个以NULL结尾的字符串,指定了应用程序的命令行
int m_nCmdShow; 用于主调进程指定启动后如何显示窗口
LPCTSTR m_pszProfileName; 应用程序的.INI文件名,一般和执行文件名相同。
LPCTSTR m_pszRegistryKey; 用于确定保存应用程序主要设置的完整注册表键
LPCTSTR m_pszExeName; 应用程序执行模块的名字(EXE或者DLL)
LPCTSTR m_pszHelpFilePath; 应用程序帮助文件的路径
HINSTANCE m_hInstance; 所有MFC程序资源的加载都是通过该句柄的调用来实现的;

11.5 CWinApp类成员函数

CWinApp(LPCTSTR lpszAppName=NULL); 构造函数,通过参数可给CWinApp类成员变量m_pszAppName赋值
HCURSOR LoadCursor( UINT nIDResource ) const; 从应用程序中加载光标资源
HCURSOR LoadStandardCursor(LPCTSTR szCur)const; 从系统中加载光标资源
HICON LoadIcon( UINT nIDResource ) const; 从应用程序中加载图标资源
HICON LoadStandardIcon(LPCTSTR szIcon) const; 从系统中加载图标资源

BOOL CNotepadApp::InitInstance()
{
    
    
	SetRegistryKey(_T("NotePad"));
	free((LPTSTR)m_pszProfileName);
	m_pszProfileName =(LPCTSTR) malloc(256);
	_tcscpy_s((LPTSTR)m_pszProfileName,128, _T("./notepad.ini"));
	CNotepadDlg dlg;
	m_pMainWnd = &dlg;
	INT_PTR nResponse = dlg.DoModal();

	return FALSE;
}

猜你喜欢

转载自blog.csdn.net/wlwdecs_dn/article/details/121392471