一年前的另一个答案<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> IconSizeX: integer;<br> IconSizeY: integer;<br> AndMask : TBitmap;<br> XorMask : TBitmap;<br> IconInfo : TIconInfo;<br> Icon : TIcon;<br>begin<br> {Get the icon size}<br> IconSizeX := GetSystemMetrics(SM_CXICON);<br> IconSizeY := GetSystemMetrics(SM_CYICON);<br><br> {Create the "and" mask}<br> AndMask := TBitmap.Create;<br> AndMask.Monochrome := true;<br> AndMask.Width := IconSizeX;<br> AndMask.Height := IconSizeY;<br><br> {Draw on the "and" mask}<br> AndMask.Canvas.Brush.Color := clWhite;<br> AndMask.Canvas.FillRect(rect(0, 0, IconSizeX, IconSizeY));<br> AndMask.Canvas.Brush.Color := clblack;<br> AndMask.Canvas.ELLIPSE(4, 4, IconSizeX-4, IconSizeY-4);<br><br> {Draw as a test}<br> Form1.Canvas.Draw(IconSizeX*2, IconSizeY, AndMask);<br><br> {Create the "xor" mask}<br> XorMask := TBitmap.Create;<br> XorMask.Width := IconSizeX;<br> XorMask.Height := IconSizeY;<br><br> {Draw on the "xor" mask}<br> XorMask.Canvas.Brush.Color := clblack;<br> XorMask.Canvas.FillRect(rect(0, 0, IconSizeX, IconSizeY));<br> XorMask.Canvas.Pen.Color := clRed;<br> XorMask.Canvas.Brush.Color := clRed;<br> XorMask.Canvas.ELLIPSE(4, 4, IconSizeX-4, IconSizeY-4);<br><br> {Draw as a test}<br> Form1.Canvas.Draw(IconSizeX*4, IconSizeY, XOrMask);<br><br> {Create a icon}<br> Icon := TIcon.Create;<br> IconInfo.fIcon := true;<br> IconInfo.xHotspot := 0;<br> IconInfo.yHotspot := 0;<br> IconInfo.hbmMask := AndMask.Handle;<br> IconInfo.hbmColor := XOrMask.Handle;<br> Icon.Handle := CreateIconIndirect(IconInfo);<br><br> {Destroy the temporary bitmaps}<br> AndMask.Free;<br> XorMask.Free;<br><br> {Draw as a test}<br> Form1.Canvas.Draw(IconSizeX*6, IconSizeY, Icon);<br><br> {Assign the application icon}<br> Application.Icon := Icon;<br><br> {Force a repaint}<br> InvalidateRect(Application.Handle, nil, true);<br><br> {Free the icon}<br> Icon.Free;<br>