###実現したいこと
C#、Win32APIを使ってマウスカーソルの作成をしています。
以下の図のように、赤枠で囲い、中を透明化したいと考えています。
###ソースコード
private void Form1_Shown(object sender, EventArgs e) { const int COLOR_SIZE = 3; Point LeftTop = new Point(0, 0); Size IconSize = new Size(30, 30); IntPtr hdcRef = GetDC(IntPtr.Zero); IntPtr hdc = CreateCompatibleDC(hdcRef); IntPtr hAnd = CreateCompatibleBitmap(hdcRef, IconSize.Width, IconSize.Height); IntPtr hXor = CreateCompatibleBitmap(hdcRef, IconSize.Width, IconSize.Height); ReleaseDC(IntPtr.Zero, hdcRef); IntPtr colorBrush = CreateSolidBrush(ColorTranslator.ToWin32(Color.Red)); SelectObject(hdc, hXor); PatBlt(hdc, LeftTop.X, LeftTop.Y, IconSize.Width, IconSize.Height, WHITENESS); //SelectObject(hdc, colorBrush); //PatBlt(hdc, leftTop.X, leftTop.Y, IconSize.Width, IconSize.Height, PATCOPY); PatBlt(hdc, LeftTop.X + COLOR_SIZE, LeftTop.Y + COLOR_SIZE, IconSize.Width - (COLOR_SIZE * 2), IconSize.Height - (COLOR_SIZE * 2), BLACKNESS); DeleteDC(hdc); ICONINFO ii = new ICONINFO(); ii.fIcon = 0; ii.xHotspot = (uint)(LeftTop.X + IconSize.Width / 2); ii.yHotspot = (uint)(LeftTop.Y + IconSize.Height / 2); ii.hbmMask = hAnd; ii.hbmColor = hXor; IntPtr hCursor = CreateIconIndirect(ref ii); Cursor cursor = new Cursor(hCursor); this.Cursor = cursor; DeleteObject(hAnd); DeleteObject(hXor); }
###試したこと
WHITENESSが少しでも前面に来ている場合は、黒・赤ともに透明化されるようで、
完全に隠れているとほかの色が表示されるというところまではわかりました。
ご教示の程のよろしくお願い致します。
あなたの回答
tips
プレビュー