共用方式為


CWinApp::m_hInstance

對應於視窗的 hInstance 傳遞參數至 WinMain

HINSTANCE m_hInstance;

備註

m_hInstance 資料成員是控制代碼在 Windows 下的應用程式目前的執行個體。 這是由全域函式 AfxGetInstanceHandle傳回。 m_hInstance 是型別 HINSTANCE的公用變數。

範例

// Typically you do not need to pass the application's hInstance
// to Windows APIs directly because there are equivalent MFC
// member functions that pass the hInstance for you.  The following
// example is not typical:

HCURSOR hCursor;
hCursor = ::LoadCursor(AfxGetApp()->m_hInstance, 
   MAKEINTRESOURCE(IDC_MYCURSOR));

// A more direct way to get the application's hInstance is to
// call AfxGetInstanceHandle:
hCursor = ::LoadCursor(AfxGetInstanceHandle(), 
   MAKEINTRESOURCE(IDC_MYCURSOR));

// If you need the hInstance to load a resource, it is better
// to call AfxGetResourceHandle instead of AfxGetInstanceHandle:
hCursor = ::LoadCursor(AfxGetResourceHandle(), 
   MAKEINTRESOURCE(IDC_MYCURSOR));

// A better way to load the cursor resource is to call
// CWinApp::LoadCursor
hCursor = AfxGetApp()->LoadCursor(IDC_MYCURSOR);

需求

Header: afxwin.h

請參閱

參考

CWinApp 類別

階層架構圖