春暖花开
雪化了,花开了,春天来了
posts - 149,comments - 125,trackbacks - 0

对话框显示OKCANCEL的简便方法

最近很忙,有时也犯点懒。转的东西多些,自己写东西的时候少了好多。曾经豪言的100篇总结,似乎也只完成了56篇。离目标还有很远的距离。所以继续。

这次是一个很小的知识点,只是简单的改变对话框的OKCANCEL按钮。我们的法宝是SHDoneButton函数。

我先给几个小示例:

已知想要改变的窗口句柄hWnd;

// 显示OK按钮

  SHDoneButton(hWnd, SHDB_SHOW);

// 显示CANCEL按钮

  SHDoneButton(hWnd, SHDB_SHOWCANCEL);

我们再具体看一下这个函数的使用。原来我认为挺简单的,仔细看了一下SDK,竟然还有那么多的注意事项,那我们来学习一下这个函数

SHDoneButton
功能This function is provided for applications that need to dynamically show or hide the OK button based on the state of the application.(可以使应用程序动态的显示或隐藏OK按钮)

原型

BOOL SHDoneButton(

  HWND hwndRequester,

  DWORD dwState

);

参数:

hwndRequester [in] Handle to the top-level window requesting the Done button. (指定窗口)

dwState [in] Specifies the button state. (指定按钮的状态)

按钮的状态有三个值,分别为:

SHDB_SHOW:添加属性WS_EX_CAPTIONOKBTN到指定的窗口。当指定窗口成为最前的窗口时,OK按钮将会显现。注意指定窗口不能设置为样式WS_CAPTION

SHDB_HIDE:从指定窗口移出WS_EX_CAPTIONOKBTN属性。下次当指定窗口成为最前窗口时,OK按钮将不再显示。

SHDB_SHOWCANCEL:将在窗口显示[X]按钮。当[X]按钮按下的时候,将会发送一个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控制的,自动的显示和隐藏OK按钮。一个最顶层的窗口需要确定按钮出现时需要使用下列窗口样式:

必须具有WS_EX_CAPTIONOKBTN属性

必须不能含有WS_CAPTIONWS_CHILD属性样式。

当最前窗口改变时,shell将检查窗口的样式来决定OK按钮是否出现在导航按钮中。)

 

对于这个备注,我没有怎么注意过。所以为了验证我这里做了一下实验。发现WS_CAPTION这个属性对OK按钮的显示没有多大影响。只是显示[X]按钮没有实验出来。

posted on 2009-07-21 18:13 Sandy 阅读(1133) 评论(0)  编辑 收藏 引用 所属分类: Windows Mobile

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理