對(duì)話框顯示OK或CANCEL的簡(jiǎn)便方法
最近很忙,有時(shí)也犯點(diǎn)懶。轉(zhuǎn)的東西多些,自己寫東西的時(shí)候少了好多。曾經(jīng)豪言的100篇總結(jié),似乎也只完成了5或6篇。離目標(biāo)還有很遠(yuǎn)的距離。所以繼續(xù)。
這次是一個(gè)很小的知識(shí)點(diǎn),只是簡(jiǎn)單的改變對(duì)話框的OK或CANCEL按鈕。我們的法寶是SHDoneButton函數(shù)。
我先給幾個(gè)小示例:
已知想要改變的窗口句柄hWnd;
// 顯示OK按鈕
SHDoneButton(hWnd, SHDB_SHOW);
// 顯示CANCEL按鈕
SHDoneButton(hWnd, SHDB_SHOWCANCEL);
我們?cè)倬唧w看一下這個(gè)函數(shù)的使用。原來(lái)我認(rèn)為挺簡(jiǎn)單的,仔細(xì)看了一下SDK,竟然還有那么多的注意事項(xiàng),那我們來(lái)學(xué)習(xí)一下這個(gè)函數(shù)
SHDoneButton
功能:This function is provided for applications that need to dynamically show or hide the OK button based on the state of the application.(可以使應(yīng)用程序動(dòng)態(tài)的顯示或隱藏OK按鈕)
原型:
BOOL SHDoneButton(
HWND hwndRequester,
DWORD dwState
);
參數(shù):
hwndRequester :[in] Handle to the top-level window requesting the Done button. (指定窗口)
dwState :[in] Specifies the button state. (指定按鈕的狀態(tài))
按鈕的狀態(tài)有三個(gè)值,分別為:
SHDB_SHOW:添加屬性WS_EX_CAPTIONOKBTN到指定的窗口。當(dāng)指定窗口成為最前的窗口時(shí),OK按鈕將會(huì)顯現(xiàn)。注意指定窗口不能設(shè)置為樣式WS_CAPTION。
SHDB_HIDE:從指定窗口移出WS_EX_CAPTIONOKBTN屬性。下次當(dāng)指定窗口成為最前窗口時(shí),OK按鈕將不再顯示。
SHDB_SHOWCANCEL:將在窗口顯示[X]按鈕。當(dāng)[X]按鈕按下的時(shí)候,將會(huì)發(fā)送一個(gè)WM_COMMAND消息,指定IDCANCEL值。
返回值:
成功則返回TRUE,失敗則返回FALSE。
備注:
Typically, the Done button (the OK button that appears in the upper-right corner of the screen) is managed by the shell, and showing or hiding the OK button happens automatically. A top-level window that needs the Done button to appear should use the following window styles:
Must have WS_EX_CAPTIONOKBTN
Must not have WS_CAPTION
WS_CHILD
Note WS_CAPTION is defined as (WS_BORDER
WS_DLGFRAME). To make the OK button appear, you must ensure that your window does not have either of these styles.
Whenever the foreground window changes, the shell checks the style bits of the window to determine if the OK button should appear in the navigation bar.
To suppress the OK button, use the WS_NONAVDONEBUTTON style.
(通常情況下,確定按鈕是由shell控制的,自動(dòng)的顯示和隱藏OK按鈕。一個(gè)最頂層的窗口需要確定按鈕出現(xiàn)時(shí)需要使用下列窗口樣式:
必須具有WS_EX_CAPTIONOKBTN屬性
必須不能含有WS_CAPTION和WS_CHILD屬性樣式。
當(dāng)最前窗口改變時(shí),shell將檢查窗口的樣式來(lái)決定OK按鈕是否出現(xiàn)在導(dǎo)航按鈕中。)
對(duì)于這個(gè)備注,我沒(méi)有怎么注意過(guò)。所以為了驗(yàn)證我這里做了一下實(shí)驗(yàn)。發(fā)現(xiàn)WS_CAPTION這個(gè)屬性對(duì)OK按鈕的顯示沒(méi)有多大影響。只是顯示[X]按鈕沒(méi)有實(shí)驗(yàn)出來(lái)。
posted on 2009-07-21 18:13
Sandy 閱讀(1200)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
Windows Mobile