1)View/SubWindow communication:
--Inside SubWindow
CMyObject *pObject = new CMyObject;
pObject->SetProperties();
m_pView->PostMessage(WM_XXX, (WPARAM)pObject, NULL)
--Viw Msg handler
OnMessageXXX(WPARAM wparam, LPARAM lparam)
{
CMyObject *p = (CMyObject*)wparam;
if (p)
{
p->DoSth();
delete p;
}
2)Load Subwindow as Tabsheet
3)List ctrl, how to synchronize internal data structure and UI
4)SetTimer, WM_TIMER
5)Manually add command range
ON_COMMAND_RANGE(ID_start, ID_end, OnCmd) //case id, do something
ON_UPDATE_COMMAND_UI_RANGE(ID_start, ID_end, OnUpdateCmdUi) //case id, SetEnable, SetCheck
6)Customize menu
//remove "File" menu
GetParentFrame()->GetMenu()->RemoveMenu(0, MF_BYPOSITION);
7)Update status bar
i)
define a new string resource: ID_INDICATOR_MY
ii)
append this string to status indicators
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_MY
};
iii) set text
void CMyTestView::OnBnClickedButton1()
{
CStatusBar *pBar = &((CMainFrame*)GetParentFrame())->m_wndStatusBar;
pBar->SetPaneText(pBar->CommandToIndex(ID_INDICATOR_MY), "Msg");
}
8)Query close at application exit
void CMainFrame::OnClose()
{
char szCap[64];
GetWindowText(szCap, 64);
if (MessageBox("Are You Sure You Want to Quit", szCap, MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2) == IDNO)
return;
__super::OnClose();
}
9)Show/Hide toolbar
inside CMainFrame
ShowControlBar(&m_wndToolBar, !m_wndToolBar.IsVisible(), FALSE);
///
MFC get current directory
///
//GetModuleFileName (more accurated)
TCHAR szFullPath[MAX_PATH];
TCHAR szDir[_MAX_DIR];
TCHAR szDrive[_MAX_DRIVE];
CString strAppDir;
::GetModuleFileName(NULL, szFullPath, MAX_PATH);
_splitpath(szFullPath, szDrive, szDir, NULL, NULL);
strAppDir.Format(_T("%s%s"), szDrive, szDir);
// GetCurrentDirectory: output reault in debug mode(under IDE) and runtime mode is different
char szDir[MAX_PATH];
GetCurrentDirectory(MAX_PATH, szDir);
printf("szDir = %s/n", szDir);