滑鼠移入按鈕區域 → 游標變手型、按鈕圖示切換為高亮版本、播放提示音效;滑鼠移出 → 還原。純程式碼實現,無需 Flash/Photoshop 輸出大型動畫檔。
one.bmp:正常狀態圖示two.bmp:滑鼠懸停狀態圖示 (色彩更鮮豔)crush.wav:短促音效純文字檔 app.rc:
crush WAV crush.wav
start BITMAP one.bmp
start1 BITMAP two.bmp
加入專案或編譯為 .res 連結。
TSpeedButton 名為 StartSpeedButtonCaption 空、Cursor = crHandPoint、Flat = true、Glyph = 無、ShowHint = trueprivate:
Graphics::TBitmap *bmpNormal, *bmpHover;
char *wavHandle;
bmpNormal = new Graphics::TBitmap();
bmpHover = new Graphics::TBitmap();
bmpNormal->Handle = LoadBitmap(HInstance, "one");
bmpHover->Handle = LoadBitmap(HInstance, "two");
HRSRC hRes = FindResource(HInstance, "crush", "WAV");
HGLOBAL hGlob = LoadResource(HInstance, hRes);
wavHandle = (char*)LockResource(hGlob);
// 初始顯示正常狀態
StartSpeedButton->Glyph->Assign(bmpNormal);
void __fastcall TForm1::StartSpeedButtonMouseEnter(TObject *Sender)
{
StartSpeedButton->Glyph->Assign(bmpHover);
if (wavHandle) sndPlaySound(wavHandle, SND_MEMORY | SND_ASYNC | SND_NODEFAULT);
}
void __fastcall TForm1::StartSpeedButtonMouseLeave(TObject *Sender)
{
StartSpeedButton->Glyph->Assign(bmpNormal);
}
完整可編譯專案結構,適合直接套用於需網頁風格互動按鈕的桌面應用。