public static TaskbarPosition GetPosition() { IntPtr taskbarHandle = User32.FindWindow(Taskbar.ClassName, null); var data = new APPBARDATA(); data.cbSize = (uint)Marshal.SizeOf(typeof(APPBARDATA)); data.hWnd = taskbarHandle; IntPtr result = Shell32.SHAppBarMessage(ABM.GetTaskbarPos, ref data); if (result == IntPtr.Zero) throw new InvalidOperationException(); return (TaskbarPosition)data.uEdge; }
private static extern UInt32 SHAppBarMessage(UInt32 dwMessage, ref APPBARDATA data);
public void GetPosition(string strClassName, string strWindowName) { m_data = new APPBARDATA(); m_data.cbSize = (UInt32) Marshal.SizeOf(m_data.GetType()); IntPtr hWnd = FindWindow(strClassName, strWindowName); if (hWnd != IntPtr.Zero) { UInt32 uResult = SHAppBarMessage(ABM_GETTASKBARPOS, ref m_data); if (uResult != 1) { throw new Exception("Failed to communicate with the given AppBar"); } } else { throw new Exception("Failed to find an AppBar that matched the given criteria"); } }
public void GetSystemTaskBarPosition() { m_data = new APPBARDATA(); m_data.cbSize = APPBARDATA.SizeOf; IntPtr hWnd = FindWindow("Shell_TrayWnd", null); if (hWnd != IntPtr.Zero) { UInt32 uResult = SHAppBarMessage(ABM_GETTASKBARPOS, ref m_data); if (uResult != 1) { throw new Exception("Failed to communicate with the given AppBar"); } } else { throw new Exception("Failed to find an AppBar that matched the given criteria"); } }