⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vc编程指南68篇(9).txt

📁 VC编程指南68篇
💻 TXT
字号:
61、如何查询和设置系统参数 
  
    在Windows 3.1 SDK中介绍过SDK函数SystemParametersInfo,调用该函数可 
以查询和设置系统参数,诸如按键的重复速率设置、鼠标双击延迟时间、图标字体 
以及桌面覆盖位图等等。 
  
//Create a font that is used for icon titles. 
LOGFONT stFont; 
:: SystemParametersInfo (SPIF_GETICONTITLELOGFONT, 
     sizeof (LOGFONT), &stFont, SPIF_SENDWININICHANGE); 
m_font.CreateFontIndirect (&stFont); 
  
//Change the wallpaper to leaves.bmp. 
:: SystemParametersInfo (SPI_SETDESKWALLPAPER, 0, 
       _T (" forest.bmp"), SPIF_UPDATEINIFILE); 
  
62、如何使用一个预定义的Windows光标 
  
    调用CWinApp:: LoadStandardCursor并传送光标标识符。 
     BOOL CSampleDialog:: OnSetCursor (CWnd* pWnd, UINT nHitTest, UINT message) 
{ 
     //Display wait cursor if busy. 
     if (m_bBusy) 
     { 
         SetCursor (AfxGetApp () ->LoadStandardCursor (IDC_WAIT)); 
         return TRUE; 
     } 
  
     return CDialog:: OnSetCursor (pWnd. nHitTest,message); 
} 
  
63、如何确定当前 聊环直媛? 
  
    调用SDK函数GetSystemMetrics,该函数可以检索有关windows显示信息,诸如 
标题大小、边界大小以及滚动条大小等等。 
  

//Initialize CSize object with screen size. 
CSize sizeScreen (GetSystemMetrics (SM_CXSCREEN), 
     GetSystemMetrics (SM_CYSCREEN)); 
  
64、如何检索原先的Task Manager应用程序使用的任务列表 
  
    原先的Task Manager应用程序显示顶层窗口的列表。为了显示该列表,窗口 
必须可见、包含一个标题以及不能被其他窗口拥有。调用CWnd:: GetWindow可以 
检索顶层窗口的列表,调用IsWindowVisible、GetWindowTextLength以及GetOwner 
可以确定窗口是否应该在列表中。下例将把TaskManager窗口的标题填充到列表中。 
  
void GetTadkList (CListBox&list) 
{ 
     CString strCaption;        //Caption of window. 
  
     list.ResetContent ();       //Clear list box. 
  
     //Get first Window in window list. 
     ASSERT_VALID (AfxGetMainWnd ()); 
     CWnd* pWnd=AfxGetMainWnd () ->GetWindow (GW_HWNDFIRST); 
  
     //Walk window list. 
     while (pWnd) 
     { 
         // I window visible, has a caption, and does not have an owner? 
         if (pWnd ->IsWindowVisible () && 
            pWnd ->GetWindowTextLength () &&! pWnd ->GetOwner ()) 
         { 
            //Add caption o window to list box. 
            pWnd ->GetWindowText  (strCaption); 
            list.AddString (strCaption); 
         } 
         //Get next window in window list. 
         pWnd=pWnd->GetWindow (GW_HWNDNEXT); 
     } 
} 
  
65、如何确定Windows和Windows系统目录 
  
    有两个SDK函数可以完成该功能。GetWindowsDirectory和GetSystemDirectory, 
下例说明了如何使用这两个函数: 
  
TCHAR szDir [MAX_PATH]; 
//Get the full path of the windows directory. 
:: GetWindowsDirectory (szDir, MAX_PATH); 
TRACE ("Windows directory %s\n", szDir); 
//Get the full path of the windows system directory. 
:: GetSystemDirectory (szDir, MAX_PATH); 
TRACE ("Windows system directory %s\n", szDir); 
  
66、在哪儿创建临文件 
  
    调用SDK函数GetTemPath可以确定临时文件的目录,该函数首先为临时路径 
检测TMP环境变量:如果没有指定TMP,检测TMP环境变量,然后返回到当前目录。 
下例说明了如何创建一个临时文件。 
     //get unique temporary file. 
     CString strFile; 
     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 ("~ex"),0,szTempfile); 
     ASSERT (nResult); 
  
     strTempName=szTempFile; 
} 
  
67、如何访问桌面窗口 
  
    静态函数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); 
     } 

} 
  
68、 
    12. 如何让窗口和 MDI窗口一启动就最大化和最小化? 
     该条两条合并为一条了. 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -