2012-06-26 42 views
2

我發現如何在我的Windows Mobile應用程序(通過設置ControlBox)禁用「確定」按鈕。Windows Mobile的「確定」按鈕

我遇到的問題是我可以通過按下這個「OK」按鈕關閉我的應用程序,但FormClosing,FormClosed事件沒有被解僱,而且最令人擔憂的是,表單的Dispose()方法沒有被調用無論是。這使得清理線程和其他資源等事情變得非常困難。

現在,我可以強制用戶使用我自己的「退出」按鈕,這些方法都會像我期望的那樣執行。

問題:爲什麼Windows Mobile應用程序中的「確定」按鈕在繞過我提到的方法的同時關閉應用程序?

+0

您是不是要找「確定」按鈕或「X」,IIRC當你點擊「X」按鈕您的應用程序不緊密,它只是隱藏的,所以當用戶再次運行它,它只是帶來了回到頂部。我認爲「確定」按鈕僅顯示在對話窗口中。 – Matt

+0

IIRC < - 按鈕實際上關閉了應用程序或應用程序的當前窗口。 –

+0

這是「確定」按鈕。我的應用程序是*不*模態。 –

回答

0

當您爲FormClosingFormClosed事件編寫代碼時,是否記得將實際形式連接起來以使用它們?

我有幾個Windows Mobile應用程序,我維護,他們調用我爲他們創建的方法。

我經常忘記設置控件以使用我爲他們編寫的代碼,所以這是我第一次想到的。

編輯:我不使用微軟的OK按鈕,而是使用具有EXIT菜單項的菜單。

Wm5 in GUI

我也/關閉軟輸入面板(SIP)和任務欄被P調用「coredll」文件中的Program.cs文件我的主要程序執行之前。

這可能是您的解決方案。如果是這樣,這應該是我使用的所有代碼。一定要測試一下,如果有什麼遺漏,請告訴我,我會更新它。

const string COREDLL = "coredll.dll"; 

[DllImport(COREDLL, EntryPoint = "FindWindowW", SetLastError = true)] 
public static extern IntPtr FindWindowCE(string lpClassName, string lpWindowName); 

[DllImport(COREDLL, SetLastError = true)] 
[return: MarshalAs(UnmanagedType.Bool)] 
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags); 

private static Form1 objForm = null; 
private static IntPtr _taskBar = IntPtr.Zero; 
private static IntPtr _sipButton = IntPtr.Zero; 

[MTAThread] 
static void Main() { 
    ShowWindowsMenu(false); 
    try { 
    objForm = new Form1(); 
    Application.Run(objForm); 
    } catch (Exception err) { 
    objForm.DisableTimer(); 
    if (!String.IsNullOrEmpty(err.Message)) { 
     ErrorWrapper("AcpWM5 Form (Program)", err); 
    } 
    } finally { 
    ShowWindowsMenu(true); // turns the menu back on 
    } 
} 

private static void ShowWindowsMenu(bool enable) { 
    try { 
    if (enable) { 
     if (_taskBar != IntPtr.Zero) { 
     SetWindowPos(_taskBar, IntPtr.Zero, 0, 0, 240, 26, (int)WindowPosition.SWP_SHOWWINDOW); // display the start bar 
     } 
    } else { 
     _taskBar = FindWindowCE("HHTaskBar", null); // Find the handle to the Start Bar 
     if (_taskBar != IntPtr.Zero) { // If the handle is found then hide the start bar 
     SetWindowPos(_taskBar, IntPtr.Zero, 0, 0, 0, 0, (int)WindowPosition.SWP_HIDEWINDOW); // Hide the start bar 
     } 
    } 
    } catch (Exception err) { 
    ErrorWrapper(enable ? "Show Start" : "Hide Start", err); 
    } 
    try { 
    if (enable) { 
     if (_sipButton != IntPtr.Zero) { // If the handle is found then hide the start bar 
     SetWindowPos(_sipButton, IntPtr.Zero, 0, 0, 240, 26, (int)WindowPosition.SWP_SHOWWINDOW); // display the start bar 
     } 
    } else { 
     _sipButton = FindWindowCE("MS_SIPBUTTON", "MS_SIPBUTTON"); 
     if (_sipButton != IntPtr.Zero) { // If the handle is found then hide the start bar 
     SetWindowPos(_sipButton, IntPtr.Zero, 0, 0, 0, 0, (int)WindowPosition.SWP_HIDEWINDOW); // Hide the start bar 
     } 
    } 
    } catch (Exception err) { 
    ErrorWrapper(enable ? "Show SIP" : "Hide SIP", err); 
    } 
} 
+0

是的,事件是迷上了。當我使用Close()關閉表單時,它們被正確執行。 –

+0

所以它是微軟的一點點確定按鈕,不會觸發Windows Mobile能夠傳遞的任何東西。我做了一些改變,可能會讓你「失魂落魄」。 – jp2code

+0

這不再是個問題,現在我隱藏了確定按鈕設置C​​ontrolBox = false。我的問題更多地涉及會導致這種行爲的事情。對我來說,這似乎是一個主要的用戶界面錯誤,允許用戶看似關閉程序而不實際關閉程序。上面馬特的評論似乎可能是一個很好的答案 - 好的只是隱藏窗口。從未使用過此平臺,並在同一地點看到確定按鈕,我希望有一個X按鈕 - 您可以看到我的困惑出現在哪裏。 –

相關問題