Q
幫助「?」按鈕
16
A
回答
30
這很簡單,只需將此代碼插入到Window類中即可。
此代碼使用interop刪除WS_MINIMIZEBOX和WS_MAXIMIZEBOX樣式並添加WS_EX_CONTEXTHELP擴展樣式(只有在刪除最小化和最大化按鈕時纔會顯示問號)。
編輯:在幫助按鈕上添加了單擊檢測,這是通過使用HwndSource.AddHook掛接到WndProc並使用wParam的SC_CONTEXTHELP偵聽WM_SYSCOMMAND消息來完成的。
當檢測到單擊時,此代碼將顯示一個消息框,將其更改爲事件,路由事件或命令(對於MVVM應用程序)作爲練習留給讀者。
private const uint WS_EX_CONTEXTHELP = 0x00000400;
private const uint WS_MINIMIZEBOX = 0x00020000;
private const uint WS_MAXIMIZEBOX = 0x00010000;
private const int GWL_STYLE = -16;
private const int GWL_EXSTYLE = -20;
private const int SWP_NOSIZE = 0x0001;
private const int SWP_NOMOVE = 0x0002;
private const int SWP_NOZORDER = 0x0004;
private const int SWP_FRAMECHANGED = 0x0020;
private const int WM_SYSCOMMAND = 0x0112;
private const int SC_CONTEXTHELP = 0xF180;
[DllImport("user32.dll")]
private static extern uint GetWindowLong(IntPtr hwnd, int index);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hwnd, int index, uint newStyle);
[DllImport("user32.dll")]
private static extern bool SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter, int x, int y, int width, int height, uint flags);
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
uint styles = GetWindowLong(hwnd, GWL_STYLE);
styles &= 0xFFFFFFFF^(WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
SetWindowLong(hwnd, GWL_STYLE, styles);
styles = GetWindowLong(hwnd, GWL_EXSTYLE);
styles |= WS_EX_CONTEXTHELP;
SetWindowLong(hwnd, GWL_EXSTYLE, styles);
SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
((HwndSource)PresentationSource.FromVisual(this)).AddHook(HelpHook);
}
private IntPtr HelpHook(IntPtr hwnd,
int msg,
IntPtr wParam,
IntPtr lParam,
ref bool handled)
{
if (msg == WM_SYSCOMMAND &&
((int)wParam & 0xFFF0) == SC_CONTEXTHELP)
{
MessageBox.Show("help");
handled = true;
}
return IntPtr.Zero;
}
0
WPF沒有幫助按鈕。但是不應該推動自己推出自己的產品。
+0
到標題欄?好像你需要改變Window chrome,這是記錄的,但不是微不足道的。 – micahtan 2009-06-17 23:27:38
0
如果您打算將按鈕添加到非客戶端區域,請參閱this article。
相關問題
- 1. Tkinter按鈕幫助
- 2. ASP.NET:幫助按鈕
- 3. HTML幫助 - 隱藏按鈕
- 4. ShowModalDialog的幫助按鈕
- 5. 按鈕幫助c#Visual Studio
- 6. iPhone後退按鈕幫助
- 7. 後退按鈕幫助
- 8. 幫助單選按鈕
- 9. setOnclickListener請按鈕幫助
- 10. pyGTK單選按鈕幫助
- 11. Android的幫助按鈕setOnclickListener
- 12. Vista Shellview幫助按鈕
- 13. 幫助與iPhone按鈕按下
- 14. 可重複使用的幫助按鈕和幫助彈出
- 15. Javascript jquery幫助w/for循環按鈕
- 16. 需要幫助驗證單選按鈕
- 17. 幫助! uitableviewcell按鈕更新文本域
- 18. 單選按鈕陣列 - 需要幫助
- 19. 幫助facebook和twitter分享按鈕
- 20. 需要幫助使排按鈕一致
- 21. 「對您有幫助嗎?」按鈕
- 22. 需要幫助對齊按鈕底部
- 23. jquery動畫按鈕問題的幫助?
- 24. 添加到收藏夾按鈕幫助
- 25. 按鈕點擊幫助(Greasemonkey的)
- 26. 需要幫助,點擊一下按鈕
- 27. 更改/移動的Zendesk幫助按鈕
- 28. 在按鈕事件上需要幫助
- 29. 需要幫助... Bootstrap按鈕/ matchMedia/removeClass
- 30. Javascript幫助,表格和單選按鈕
爲什麼標題欄?我看到的大多數應用都將它放在菜單欄中。 – 2009-06-17 23:48:39
事情是我們將主要在對話框窗口上使用它,它通常沒有菜單欄。點擊它將爲該窗口提供上下文幫助。就像在MS Word 2007中的字體對話框窗口中一樣。 – Carlo 2009-06-18 00:17:36