任务栏的位置 [英] Taskbar location

查看:135
本文介绍了任务栏的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检测那里的任务栏位置?我需要知道在右下角显示我的通知。谢谢



编辑:
谢谢汉斯帕桑特。我用这个来获得位置。我希望是好的。



  GetTaskbarLocation(TaskbarPosition.GetTaskbarPosition()); 

私人无效GetTaskbarLocation(矩形RC)
{
如果如果(rc.X == rc.Y)
{
(rc.Right< ; rc.Bottom)
taskbarLocation = TaskbarLocation.Left;
如果(rc.Right> rc.Bottom)
taskbarLocation = TaskbarLocation.Top;
}
如果(rc.X> rc.Y)
taskbarLocation = TaskbarLocation.Right;
如果(rc.X< rc.Y)
taskbarLocation = TaskbarLocation.Bottom;
}


解决方案

 公共静态矩形GetTaskbarPosition(){
VAR数据=新APPBARDATA();
data.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(数据);
IntPtr的RETVAL = SHAppBarMessage(ABM_GETTASKBARPOS,参考的数据);
如果(RETVAL == IntPtr.Zero)抛出新Win32Exception(请重新安装Windows);
返回新的Rectangle(data.rc.left,data.rc.top,
data.rc.right - data.rc.left,data.rc.bottom - data.rc.top);

}

//的P / Invoke咕:
私人const int的ABM_GETTASKBARPOS = 5;
[System.Runtime.InteropServices.DllImport(Shell32.dll中)]
私人静态外部的IntPtr SHAppBarMessage(INT味精,楼盘APPBARDATA数据);
私人结构APPBARDATA {
公众诠释CBSIZE;
公众的IntPtr的HWND;
公众诠释uCallbackMessage;
公众诠释uEdge;
公共RECT RC;
公众的IntPtr lParam的;
}
私人结构R​​ECT {
公众诠释左,上,右,下;
}


How can i detect where the taskbar is located? I need to know for displaying my notification in the right corner. Thanks

Edit: Thank you Hans Passant. I used that with this to get location. I hope is ok.

GetTaskbarLocation(TaskbarPosition.GetTaskbarPosition());

private void GetTaskbarLocation(Rectangle rc)
{
    if (rc.X == rc.Y)
    {
        if (rc.Right < rc.Bottom)
            taskbarLocation = TaskbarLocation.Left;
        if (rc.Right > rc.Bottom)
            taskbarLocation = TaskbarLocation.Top;
    }
    if (rc.X > rc.Y)
        taskbarLocation = TaskbarLocation.Right;
    if (rc.X < rc.Y)
        taskbarLocation = TaskbarLocation.Bottom;
}

解决方案

    public static Rectangle GetTaskbarPosition() {
        var data = new APPBARDATA();
        data.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(data);
        IntPtr retval = SHAppBarMessage(ABM_GETTASKBARPOS, ref data);
        if (retval == IntPtr.Zero) throw new Win32Exception("Please re-install Windows");
        return new Rectangle(data.rc.left, data.rc.top,
            data.rc.right - data.rc.left, data.rc.bottom - data.rc.top);

    }

    // P/Invoke goo:
    private const int ABM_GETTASKBARPOS = 5;
    [System.Runtime.InteropServices.DllImport("shell32.dll")]
    private static extern IntPtr SHAppBarMessage(int msg, ref APPBARDATA data);
    private struct APPBARDATA {
        public int cbSize;
        public IntPtr hWnd;
        public int uCallbackMessage;
        public int uEdge;
        public RECT rc;
        public IntPtr lParam;
    }
    private struct RECT {
        public int left, top, right, bottom;
    }

这篇关于任务栏的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆