一:CString与LPCTSTR类型的数据可以相互赋值。
CString str="Sunshine";
LPCTSTR lps=str;
二:AfxGetApp()->LoadStandardCursor与AfxGetApp()->LoadCursor
当加载MFC内部定义的标准光标ID时,应用AfxGetApp()->LoadStandardCursor函数,LoadCursor不起作用。
三:继承CFrameWnd的类,不需要在虚函数PostNcDestroy中用delete this释放内存,而继承自CWnd类却要。
四:获取画刷句柄:(HBRUSH)(COLOR_3DFACE),(HBRUSH) ::GetStockObject(WHITE_BRUSH)
五:CalcWindowRect与SetWindowPos联合使用,为客户区设置精确的宽高。
CMainWindow::CMainWindow(void)
{
CString str=AfxRegisterWndClass(NULL,AfxGetApp()->LoadStandardCursor(IDC_CROSS),\
(HBRUSH)::GetStockObject(BLACK_BRUSH),AfxGetApp()->LoadStandardIcon(IDI_WINLOGO));
this->CreateEx(0,str,L"cyl",WS_OVERLAPPEDWINDOW,CRect(0,0,800,600),NULL,NULL);
CRect rect(0,0,200,100);
CalcWindowRect(&rect);
SetWindowPos(NULL,0,0,rect.Width(),rect.Height(),\
SWP_NOZORDER|SWP_NOMOVE|SWP_NOREDRAW);
CRect rc;
GetClientRect(&rc);
CString str1;
str1.Format(L"%d,%d",rc.Width(),rc.Height());
MessageBox(str1);
}
使用了CalcWindowRect,没有SetWindowPos,依然不能生效。
如果CRect rect(0,0,200,100);矩形设置过小,小于window标题栏3个按钮
的总宽度,则窗口会自动增加宽度,以容纳标题栏。