使用 Delphi 內建「圖像編輯器」(工具選單)建立 face.res 資源檔,包含 5 個 .cur 檔:
faceleft.cur — 雙眼向左faceright.cur — 雙眼向右plainface.cur — 雙眼向前(預設)leftshrink.cur — 閉左眼(左鍵按下)rightshrink.cur — 閉右眼(右鍵按下){$R face.res} // 編譯指令嵌入資源
procedure TForm1.FormCreate(Sender: TObject);
begin
// 系統游標索引 1~5 對應自訂游標
Screen.Cursors[1] := LoadCursor(HInstance, 'faceleft');
Screen.Cursors[2] := LoadCursor(HInstance, 'faceright');
Screen.Cursors[3] := LoadCursor(HInstance, 'plainface');
Screen.Cursors[4] := LoadCursor(HInstance, 'leftshrink');
Screen.Cursors[5] := LoadCursor(HInstance, 'rightshrink');
Screen.Cursor := crPlainFace; // 常數 crPlainFace = 3
end;
procedure TForm1.FormClick(Sender: TObject);
begin
Screen.Cursor := crFaceLeft; // 點擊瞬間向左看
Screen.Cursor := crPlainFace; // 立即恢復
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Key = VK_LBUTTON then
begin
Screen.Cursor := crLeftShrink; // 按住左鍵閉左眼
Screen.Cursor := crPlainFace; // 釋放恢復
end;
if Key = VK_RBUTTON then
begin
Screen.Cursor := crRightShrink; // 按住右鍵閉右眼
Screen.Cursor := crPlainFace;
end;
end;
const crFaceLeft = 1; crFaceRight = 2; crPlainFace = 3; crLeftShrink = 4; crRightShrink = 5;FormKeyDown 捕獲滑鼠按鍵需設定表單 KeyPreview = True編譯執行後即可看到生動幽默的圓臉游標,展示 Delphi 輕鬆客製化系統級 UI 元素的能力。