win32api之修改revit狀態欄提示

在使用revit進行二次開發的時候,我們經常需要做一個提示,方便用戶操作。

api中提供了選擇對象的時候可以設置提示信息,這樣很不方便,下面我們使用win封裝revit的狀態欄提示,讓大家可以很方便的設置你想提示的內容。

public class StatusBar
{
    private static IntPtr m_statusBar = IntPtr.Zero;

    /// <summary>
    /// Initializes the <see cref="StatusBar"/> class.
    /// </summary>
    /// <author>YangSen</author>
    static StatusBar()
    {
        IntPtr mainWindowHandle = Process.GetCurrentProcess().MainWindowHandle;
        if (mainWindowHandle != IntPtr.Zero)
        {
            m_statusBar = Methods.FindWindowEx(mainWindowHandle, IntPtr.Zero, "msctls_statusbar32", "");
        }
    }
    /// <summary>
    /// 設置提示內容.
    /// </summary>
    /// <param name="prompts">The prompts.</param>
    /// <author>YangSen</author>
    public static void SetPrompts(string prompts)
    {
        try
        {
            if (m_statusBar != IntPtr.Zero)
            {
                Methods.SetWindowPos(m_statusBar, 0, 0, 0, 0, 0, 0x37);
                Methods.SetWindowText(m_statusBar, prompts);
            }
        }
        catch (Exception ex)
        {
        }
    }
}
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetWindowPos(IntPtr hwnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int SetWindowText(IntPtr hWnd, string lpString);

好處我就不多說了,就一個詞:方便。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章