3
我發現,System.Windows.SystemParameters
類中有一個靜態屬性,用於聲明用戶爲其Windows整體選擇的顏色。檢索窗口10的顏色任務欄
但是用戶有第二種可能性讓他啓用或禁用,無論任務欄/窗口欄是否應使用相同的顏色。
我無法在SystemParameters類中找到該鍵的關鍵字。
我發現,System.Windows.SystemParameters
類中有一個靜態屬性,用於聲明用戶爲其Windows整體選擇的顏色。檢索窗口10的顏色任務欄
但是用戶有第二種可能性讓他啓用或禁用,無論任務欄/窗口欄是否應使用相同的顏色。
我無法在SystemParameters類中找到該鍵的關鍵字。
我相信這是找到顏色的註冊表值,它可能是裏面:
HKEY_CURRENT_USER\Control Panel\Colors
但是我的系統上我有任務欄禁用,顏色值似乎並沒有出現在顏色這個關鍵。
一個解決將是答案結合以下兩個問題:
您需要以下進口:
[DllImport("shell32.dll")]
private static extern IntPtr SHAppBarMessage(int msg, ref APPBARDATA data);
[DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
private static extern int BitBlt(IntPtr hDC, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop);
的以下結構:
而下面的常數:
private const int ABM_GETTASKBARPOS = 5;
然後就可以調用以下兩種方法:
public static Rectangle GetTaskbarPosition()
{
APPBARDATA data = new APPBARDATA();
data.cbSize = 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);
}
public static Color GetColourAt(Point location)
{
using (Bitmap screenPixel = new Bitmap(1, 1, PixelFormat.Format32bppArgb))
using (Graphics gdest = Graphics.FromImage(screenPixel))
{
using (Graphics gsrc = Graphics.FromHwnd(IntPtr.Zero))
{
IntPtr hSrcDC = gsrc.GetHdc();
IntPtr hDC = gdest.GetHdc();
int retval = BitBlt(hDC, 0, 0, 1, 1, hSrcDC, location.X, location.Y, (int)CopyPixelOperation.SourceCopy);
gdest.ReleaseHdc();
gsrc.ReleaseHdc();
}
return screenPixel.GetPixel(0, 0);
}
}
像這樣:
Color taskBarColour = GetColourAt(GetTaskbarPosition().Location);
是我的回答有幫助嗎?如果是這樣,您可以對它進行升級和接受,以便其他人可以更輕鬆地瞭解信息是否有用。 – TheLethalCoder