views:

192

answers:

1

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...

+1  A: 

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.

Qberticus
This was very helpful, thanks. I found different results though regarding the paint event. If I added it in the paint handler the application would seem to get stuck in a loop when displaying as if the call was triggering another paint, which caused another call, etc.Just adding the call in the forms load event worked like a charm on both platmforms.
ZippyBurger