Windows 95 引入視窗區域,按鈕可在執行期設定任意形狀。設計時仍為矩形,執行時套用區域。
CreateEllipticRgn (圓/橢圓)、CreatePolygonRgn (多邊形)、CreateRectRgn、CreateRoundRectRgn,複雜形狀可用 CombineRgn 組合。SetWindowRgn 指派給按鈕控制代碼。void __fastcall TForm1::FormCreate(TObject *Sender)
{
// 圓形按鈕 (設計為正方形)
HRGN hRgnR = CreateEllipticRgn(0, 0, RButton->Width, RButton->Height);
SetWindowRgn(RButton->Handle, hRgnR, TRUE);
// 三角形按鈕
TrPoint[0].x = TButton->Width / 2; TrPoint[0].y = 0;
TrPoint[1].x = 0; TrPoint[1].y = TButton->Height;
TrPoint[2].x = TButton->Width; TrPoint[2].y = TButton->Height;
HRGN hRgnT = CreatePolygonRgn(TrPoint, 3, ALTERNATE);
SetWindowRgn(TButton->Handle, hRgnT, TRUE);
}
private:
POINT TrPoint[3];
TBitBtn/TSpeedButton 貼圖美化。