與文章 7960 類似,但提供更詳細的步驟說明與資源檔建立流程。
crush WAV crush.wav
start BITMAP start.bmp // 灰階圖
start1 BITMAP start1.bmp // 彩色圖
直接加入 mysrc.rc 或用 brcc32 編譯為 .res 再用 #pragma resource "mysrc.res"。
| 屬性 | 值 |
|---|---|
| Caption | 空白 |
| Cursor | crHandPoint |
| Flat | true |
| Hint | 單擊以… |
| Glyph | None (設計時不指定) |
| ShowHint | true |
Graphics::TBitmap *start, *start1;
char *chWavHandle;
bool blStart = true;
start = new Graphics::TBitmap(); start1 = new Graphics::TBitmap();
start->Handle = LoadBitmap(HInstance, "start");
start1->Handle = LoadBitmap(HInstance, "start1");
HRSRC hRes = FindResource(HInstance, "crush", "WAV");
HGLOBAL hGlob = LoadResource(HInstance, hRes);
chWavHandle = (char*)LockResource(hGlob);
StartSpeedButton->Glyph->Assign(start1); // 初始灰階
delete chWavHandle; delete start1; delete start;
// SpeedButton OnMouseMove
if (blStart) {
StartSpeedButton->Glyph->Assign(start); // 彩色
SndPlaySound(chWavHandle, SND_MEMORY | SND_SYNC);
blStart = false;
}
// Form OnMouseMove (偵測移出)
if (!blStart) {
StartSpeedButton->Glyph->Assign(start1); // 灰階
blStart = true;
}
包含 #include <mmsystem.h>,BCB 4.0/Win98 測試通過。