简体   繁体   中英

Changing [X] to OK on form in Windows CE .NET 4.2 in .NET application

I have a .NET application that is being targeted to run on Windows Mobile 5 and Windows CE .NET 4.2 and there are some minor differences between how forms display that I'm trying to converge.

On the WM device a form will display with an "ok" button in the top right while on CE the same form will show an "X". Is there anyway on CE to have it display the "OK"? I've seen "OK" show up on message boxes so it seems like I should be able to...

The easiest way is probably to set the forms window style ControlBox = False and MinimizeBox = False and then call SHDoneButton in the form's Paint event handler and when it's activated or shown. You really are only supposed to need to do it before the form becomes the foreground window but I found that you have to also call it in the Paint event handler. So SHDoneButton(this.handle, SHDB_SHOW) where SHDB_SHOW = 0x0001 you'll need:

[DllImport("aygshell.dll")]
public static extern bool SHDoneButton(IntPtr hWnd, UInt32 dwState);

somewhere as well.

Per the linked documentation:

Typically, the Done button 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 WS_EX_CAPTIONOKBTN window style.

To make the OK button appear, ensure that your window does not have either the WS_CAPTION or WS_CHILD 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 taskbar. The OK button takes precedence over a menu bar added to the taskbar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM