?? 00000001.txt
字號:
--===BBS水木清華站∶精華區===--
-===BBS水木清華站∶精華區===-
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窗口一啟動就最大化和最小化?
該條兩條合并為一條了.
-===BBS水木清華站∶精華區===-
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -