1、获取本程序的运行目录
TCHAR AppPathName[MAX_PATH];
HINSTANCE hwnd = AfxGetAppModuleState()->m_hCurrentInstanceHandle;
GetModuleFileName(hwnd,AppPathName,MAX_PATH);
CString strModulePath(AppPathName);
int nBinPos=strModulePath.ReverseFind(_T('\\'));
if(nBinPos!=-1)
strModulePath = strModulePath.Left(nBinPos);
2、由下往上发送消息(发送字符串消息)
下不能获得上的对象,比如不能获得CMainFrame对象,只能以发送消息的形式进行通信
发送消息:
CString strName = "我是。。。。";
char* chName = strName.GetBuffer(strName.GetLength());
AfxGetMainWnd()->SendMessage(WM_MESSAGE_USER111, (WPARAM)chName, NULL); //1
//AfxGetMainWnd()->SendMessage(WM_MESSAGE_USER111, 0, *(LPARAM*)&strName); //2
消息响应:
ON_MESSAGE(WM_MESSAGE_USER111, OnCommandOpenReport)
处理消息:
LRESULT CMainFrame::OnCommandOpenReport( WPARAM wParam, LPARAM lParam )
{
CString strCurReportName = (char*)wParam; //1
//CString strPathFile = *(CString*)(LPARAM*)&lParam; //2
return 0L;
}