📄 windows系统控制.htm
字号:
<tr><td><p></Br>前些天好象有人问过这个问题.<Br></Br>Use GetModuleFileName 获得应用程序的路径,然后去掉可执行文件名。<Br></Br>Example:<Br></Br>TCHAR exeFullPath[MAX_PATH]; // MAX_PATH在API中定义了吧,好象是128<Br></Br>GetModuleFileName(NULL,exeFullPath,MAX_PATH)<Br></Br></p></td></tr><tr><td><font color="0000FF"><a name="6">获得各种目录信息 </a></font></td></tr><tr><td><p></Br>Windows目录: Use "GetWindowsDirectory“<Br></Br>Windows下的system目录: Use "GetSystemDirectory"<Br></Br>temp目录: Use "GetTempPath "<Br></Br>当前目录: Use "GetCurrentDirectory"<Br></Br>请注意前两个函数的第一个参数为 目录变量名,后一个为缓冲区; 后两个相反.<Br></Br></p></td></tr><tr><td><font color="0000FF"><a name="7">在用户环境中如何确定系统显示元素的颜色 </a></font></td></tr><tr><td><p></Br>调用SDK函数GetSysColor可以获取一个特定显示元素的颜色。下例说明了如何在MFC函数CMainFrameWnd:: OnNcPaint中调用该函数设置窗口标题颜色。<Br></Br>void CMiniFrameWnd:: OnNcPaint ()<Br></Br>{<Br></Br>…<Br></Br>dc.SetTextColor (:: GetSysColor (m_bActive ?<Br></Br>COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT));<Br></Br>…<Br></Br>}<Br></Br></p></td></tr><tr><td><font color="0000FF"><a name="8">如何查询和设置系统参数 </a></font></td></tr><tr><td><p></Br>在Windows 3.1 SDK中介绍过SDK函数SystemParametersInfo,调用该函数可以查询和设置系统参数,诸如按键的重复速率设置、鼠标双击延迟时间、图标字体以及桌面覆盖位图等等。<Br></Br>//Create a font that is used for icon titles.<Br></Br>LOGFONT stFont;<Br></Br>:: SystemParametersInfo (SPIF_GETICONTITLELOGFONT,<Br></Br>sizeof (LOGFONT), &stFont, SPIF_SENDWININICHANGE);<Br></Br>m_font.CreateFontIndirect (&stFont);<Br></Br>//Change the wallpaper to leaves.bmp.<Br></Br>:: SystemParametersInfo (SPI_SETDESKWALLPAPER, 0,<Br></Br>_T (" forest.bmp"), SPIF_UPDATEINIFILE);<Br></Br></p></td></tr><tr><td><font color="0000FF"><a name="9">如何使用一个预定义的Windows光标 </a></font></td></tr><tr><td><p></Br>调用CWinApp:: LoadStandardCursor并传送光标标识符。<Br></Br>BOOL CSampleDialog:: OnSetCursor (CWnd* pWnd, UINT nHitTest, UINT message)<Br></Br>{<Br></Br>//Display wait cursor if busy.<Br></Br>if (m_bBusy)<Br></Br>{<Br></Br>SetCursor (AfxGetApp () ->LoadStandardCursor (IDC_WAIT));<Br></Br>return TRUE;<Br></Br>}<Br></Br>return CDialog:: OnSetCursor (pWnd. nHitTest,message);<Br></Br>}<Br></Br></p></td></tr><tr><td><font color="0000FF"><a name="10">如何确定当前屏幕分辨率 </a></font></td></tr><tr><td><p></Br>调用SDK函数GetSystemMetrics,该函数可以检索有关windows显示信息,诸如标题大小、边界大小以及滚动条大小等等。<Br></Br>//Initialize CSize object with screen size.<Br></Br>CSize sizeScreen (GetSystemMetrics (SM_CXSCREEN),<Br></Br>GetSystemMetrics (SM_CYSCREEN));<Br></Br></p></td></tr><tr><td><font color="0000FF"><a name="11">如何检索原先的Task Manager应用程序使用的任务列表 </a></font></td></tr><tr><td><p></Br>原先的Task Manager应用程序显示顶层窗口的列表。为了显示该列表,窗口<Br></Br>必须可见、包含一个标题以及不能被其他窗口拥有。调用CWnd:: GetWindow可以<Br></Br>检索顶层窗口的列表,调用IsWindowVisible、GetWindowTextLength以及GetOwner<Br></Br>可以确定窗口是否应该在列表中。下例将把TaskManager窗口的标题填充到列表中。<Br></Br>void GetTadkList (CListBox&list)<Br></Br>{<Br></Br>CString strCaption; //Caption of window.<Br></Br>list.ResetContent (); //Clear list box.<Br></Br>//Get first Window in window list.<Br></Br>ASSERT_VALID (AfxGetMainWnd ());<Br></Br>CWnd* pWnd=AfxGetMainWnd () ->GetWindow (GW_HWNDFIRST);<Br></Br>//Walk window list.<Br></Br>while (pWnd)<Br></Br>{<Br></Br>// I window visible, has a caption, and does not have an owner?<Br></Br>if (pWnd ->IsWindowVisible () &&<Br></Br>pWnd ->GetWindowTextLength () &&! pWnd ->GetOwner ())<Br></Br>{<Br></Br>//Add caption o window to list box.<Br></Br>pWnd ->GetWindowText (strCaption);<Br></Br>list.AddString (strCaption);<Br></Br>}<Br></Br>//Get next window in window list.<Br></Br>pWnd=pWnd->GetWindow (GW_HWNDNEXT);<Br></Br>}<Br></Br>}<Br></Br></p></td></tr><tr><td><font color="0000FF"><a name="12">如何确定Windows和Windows系统目录 </a></font></td></tr><tr><td><p></Br>有两个SDK函数可以完成该功能。GetWindowsDirectory和GetSystemDirectory,下例说明了如何使用这两个函数:<Br></Br>TCHAR szDir [MAX_PATH];<Br></Br>//Get the full path of the windows directory.<Br></Br>:: GetWindowsDirectory (szDir, MAX_PATH);<Br></Br>TRACE ("Windows directory %s\n", szDir);<Br></Br>//Get the full path of the windows system directory.<Br></Br>:: GetSystemDirectory (szDir, MAX_PATH);<Br></Br>TRACE ("Windows system directory %s\n", szDir);<Br></Br></p></td></tr><tr><td><font color="0000FF"><a name="13">在哪儿创建临文件 </a></font></td></tr><tr><td><p></Br>调用SDK函数GetTemPath可以确定临时文件的目录,该函数首先为临时路径检测TMP环境变量:如果没有指定TMP,检测TMP环境变量,然后返回到当前目录。下例说明了如何创建一个临时文件。<Br></Br>…<Br></Br>//get unique temporary file.<Br></Br>CString strFile;<Br></Br>GetUniqueTempName (strFile);<Br></Br>TRY<Br></Br>{<Br></Br>//Create file and write data.Note that file is closed<Br></Br>//in the destructor of the CFile object.<Br></Br>CFile file (strFile,CFile:: modeCreate | CFile:: modeWrite);<Br></Br>//write data<Br></Br>}<Br></Br>CATCH (CFileException, e)<Br></Br>{<Br></Br>//error opening file<Br></Br>}<Br></Br>END_CATCH<Br></Br>…<Br></Br>Void GetuniqueTempName (CString& strTempName)<Br></Br>{<Br></Br>//Get the temporary files directory.<Br></Br>TCHAR szTempPath [MAX_PATH];<Br></Br>DWORD dwResult=:: GetTempPath (MAX_PATH, szTempPath);<Br></Br>ASSERT (dwResult);<Br></Br>//Create a unique temporary file.<Br></Br>TCHAR szTempFile [MAX_PATH];<Br></Br>UINT nResult=GetTempFileName (szTempPath, _T ("~ex"),0,szTempfile);<Br></Br>ASSERT (nResult);<Br></Br>strTempName=szTempFile;<Br></Br>}<Br></Br></p></td></tr><tr><td><font color="0000FF"><a name="14">如何访问桌面窗口 </a></font></td></tr><tr><td><p></Br>静态函数CWnd:: GetDesktopWindow 返回桌面窗口的指针。下例说明了MFC函数CFrameWnd::BeginModalStae是如何使用该函数进入内部窗口列表的。<Br></Br>void CFrameWnd::BeginModalState ()<Br></Br>{<Br></Br>…<Br></Br>//first count all windows that need to be disabled<Br></Br>UINT nCount=0;<Br></Br>HWND hWnd=:: GetWindow (:: GetDesktopWindow (), GW_CHILD);<Br></Br>while (hWnd!=NULL)<Br></Br>{<Br></Br>if (:: IsWindowEnabled (hwnd) &&<Br></Br>CWnd::FromHandlePermanent (hWnd)!=NULL &&<Br></Br>AfxIsDescendant (pParent->m_hWnd, hWnd) &&<Br></Br>:: SendMessage (hWnd, WM_DISABLEMODAL, 0, 0)==0)<Br></Br>{<Br></Br>++nCount;<Br></Br>}<Br></Br>hWnd=:: GetWindow (hWnd, GW_HWNDNEXT);<Br></Br>}<Br></Br>…<Br></Br>}<Br></p></td></tr></table><p align="center"><img src="/logo.gif" align="center"><a href="/co/index.htm">北京美达美科技有限公司</a> 版权所有: 1998-1999</a></p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -