CWinApp()的构造函数定义在appcore.cpp中,CWinApp类定义在afxwin.h
构造函数:CWinApp::CWinApp(LPCTSTR lpszAppName)
{
if (lpszAppName != <a href="https://www.baidu.com/s?wd=NULL&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBn1uhnjwWnvDvuhcLnjbd0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1cvPj63rHT4rHmkn10dPWm3Pf" target="_blank" class="baidu-highlight">NULL</a>)
m_pszAppName = _tcsdup(lpszAppName)
else
m_pszAppName = <a href="https://www.baidu.com/s?wd=NULL&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBn1uhnjwWnvDvuhcLnjbd0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1cvPj63rHT4rHmkn10dPWm3Pf" target="_blank" class="baidu-highlight">NULL</a>
// initialize CWinThread state
AFX_MODULE_STATE* pModuleState = _AFX_CMDTARGET_GETSTATE()
AFX_MODULE_THREAD_STATE* pThreadState = pModuleState->m_thread
ASSERT(AfxGetThread() == <a href="https://www.baidu.com/s?wd=NULL&脊滑茄tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBn1uhnjwWnvDvuhcLnjbd0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1cvPj63rHT4rHmkn10dPWm3Pf" target="_blank" class="baidu-highlight">NULL</a>)
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_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_nSafetyPoolSize = 512 // default size
}
MFC编程:http://images.163.com/images/it/books/vc/chap2/chap2_4.htmMFC编程里用的标准头文件#include <afxwin.h>
Win32 大多数API,用 #include <windows.h>
mfc都给封装起来了,所以自己不用写
mfc程族盯序的主函数是这样的,在appmodule.cpp里面
extern "C" int WINAPI
_tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
// call shared/exported WinMain
return AfxWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
}
//简单的mfc
//hello.cpp
#include <afxwin.h>
// Declare the application class
class CHelloApp : public CWinApp
{
public:
virtual BOOL InitInstance()
}
// Create an instance of the application class
CHelloApp HelloApp
// Declare the main window class
class CHelloWindow : public CFrameWnd
{
CStatic* cs
public:
CHelloWindow()
}
// The InitInstance function is called each
// time the application first executes.
BOOL CHelloApp::InitInstance()
{
m_pMainWnd = new CHelloWindow()
m_pMainWnd->ShowWindow(m_nCmdShow)
m_pMainWnd->UpdateWindow()
return TRUE
}
// The constructor for the window class
CHelloWindow::CHelloWindow()
{
// Create the window itself
Create(NULL,
"Hello World!!",
WS_OVERLAPPEDWINDOW,
CRect(0,0,200,200))
// Create a static label
cs = new CStatic()
cs->Create("hello world",
WS_CHILD|WS_VISIBLE|SS_CENTER,
CRect(50,80,150,150),
this)
}
Windows程序的主函数:这个函数就像我们学习C语言时程序的主函数main()的功能是一样的,他代表了程序的入口。但是这个函数看上去比main()似乎弊穗灶繁的多,如果是第一次看见这个函数肯定会感觉一头雾水,但是不要紧我们来看看这个函数各个参数的意义,(其实开始的时候完全可以不理会他们的意义)hInstance是本实例的句柄,句柄可以理解为 *** 作系统管理使用我们的应用程序的别名,它跟指针类似但又不同于指针,它的意义只有 *** 作租扮系统知道,也就是说 *** 作系统通过hInstance就可以找到我们现在的这个程序。hPrevInstance是前一个实例的句柄。szCmdLine:是命令行参数,iCmdShow是窗口的显示方式。现在我们没有必要清除每个参数的具体意义,在接下来的学习中我们用的最多的就是hInstance这个参数,但也不多,而且我们使用vc++时,无论有哪种程序生成方式这个函数一般都会自动生成。
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
http://huihua.hebtu.edu.cn/hhcmc/study/program1/program/program.htm
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)