天天看点

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, , , , , , );
                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);
           

好处我就不多说了,就一个词:方便。

继续阅读