当前位置:首页 > VC常用操作源码汇总
GetUniqueTempName (strFile) TRY {
//Create file and write data.Note that file is closed //in the destructor of the CFile object.
CFile file (strFile,CFile ::modeCreate | CFile:: modeWrite) //write data }
CATCH (CFileException, e) {
//error opening file }
END_CATCH …
Void GetuniqueTempName (CString& strTempName) {
//Get the temporary files directory. TCHAR szTempPath [MAX_PATH]
DWORD dwResult=:: GetTempPath (MAX_PATH, szTempPath) ASSERT (dwResult)
//Create a unique temporary file. TCHAR szTempFile [MAX_PATH]
UINT nResult=GetTempFileName (szTempPath, _T (\ASSERT (nResult) strTempName=szTempFile }
我怎样才能建立一个等待光标
调 用 BeginWaitCursor 函 数 来 启 动 等 待 光 标,调 用 EndWaitCursor 函 数 来 结 束 等 待 光 标。要 注 意,二 者 都 要 调 用 app 的 成 员 函 数,如 下 所 示: AfxGetApp()->BeginWaitCursor(); // 要做的事
AfxGetApp()->EndWaitCursor();
43
访问桌面窗口
静态函数CWnd:: GetDesktopWindow 返回桌面窗口的指针。下例说明了MFC函数CFrameWnd::BeginModalStae是如何使用该函数进入内部窗口列表的。 void CFrameWnd::BeginModalState () { …
//first count all windows that need to be disabled UINT nCount=0
HWND hWnd= :: GetWindow (:: GetDesktopWindow(), GW_CHILD) while (hWnd!=NULL) {
if (:: IsWindowEnabled (hwnd)
&& CWnd::FromHandlePermanent (hWnd)!=NULL && AfxIsDescendant (pParent->m_hWnd, hWnd)
&& :: SendMessage (hWnd, WM_DISABLEMODAL, 0, 0)==0) { ++nCount }
hWnd=:: GetWindow (hWnd, GW_HWNDNEXT) } …
怎样用COLORREF
COLORREF是一个32-bit整型数值,它代表了一种颜色。你可以使用RGB函数来初始化COLORREF。例如: COLORREF color = RGB(0, 255, 0);
RGB 函数接收三个0-255数值,一个代表红色,一个代表绿色,一个代表蓝色。在上面的例子中,红色和蓝色值都为0,所以在该颜色中没有红色和蓝色。绿色为最大值255。所以该颜色为绿色。0,0,0为黑色,255,255,255为白色。
另一种初始化COLORREF的方法如下所示: CColorDialog colorDialog; COLORREF color;
if(colorDialog.DoModal()==IDOK) {
color = colorDialog.GetColor();
44
}
这段代码使用了MFC中的颜色对话框,它需要文件。
在应用程序中循环浏览已经打开的文档、视图
使用CDocTemplate中未公开的GetFirstDocPosition()和GetNextDoc()函数。 使用CDocument中未公开的GetFirstViewPosition()和GetNextView()函数。 (83)数PreCreateWindow是干什么用的?
PreCreateWindow允许你在调用CreateWindow之前来改变窗口属性。
窗口标题栏的名称
防止把文档名预置成应用程序名:在PreCreateWindow函数中删除FWS_PREFIXTITLE标志的窗口样式: cs.style&=~FWS_PREFIXTITLE;
防止MFC在窗口标题栏上添加文档名:在PreCreateWindow函数中删除FWS_ADDTOTITLE标志的窗口样式:
cs.style&=~FWS_ADDTOTITLE;
45
共分享92篇相关文档