[15] | 1 | Unit SystemIconUnit;
|
---|
| 2 |
|
---|
| 3 | Interface
|
---|
| 4 |
|
---|
| 5 | Uses
|
---|
| 6 | Classes, Forms, Graphics, OS2Def;
|
---|
| 7 |
|
---|
| 8 | {Declare new class}
|
---|
| 9 | Type
|
---|
| 10 | TSystemIconID =
|
---|
| 11 | (
|
---|
| 12 | siArrow, // Arrow pointer
|
---|
| 13 | siText, // Text I-beam pointer
|
---|
| 14 | siWait, // Hourglass pointer
|
---|
| 15 | siSize, // Size pointer
|
---|
| 16 | siMove, // Move pointer
|
---|
| 17 | siSizeNWSE, // Downward-sloping, double-headed arrow pointer
|
---|
| 18 | siSizeNESW, // Upward-sloping, double-headed arrow pointer
|
---|
| 19 | siSizeWE, // Horizontal, double-headed arrow pointer
|
---|
| 20 | siSizeNS, // Vertical, double-headed arrow pointer
|
---|
| 21 | siAppIcon, // Standard application icon pointer
|
---|
| 22 | siIconInformation, // Information icon pointer
|
---|
| 23 | siIconQuestion, // Question mark icon pointer
|
---|
| 24 | siIconError, // Exclamation mark icon pointer
|
---|
| 25 | siIconWarning, // Warning icon pointer
|
---|
| 26 | siIllegal, // Illegal operation icon pointer
|
---|
| 27 | siFile, // Single file icon pointer
|
---|
| 28 | siMultFile, // Multiple files icon pointer
|
---|
| 29 | siFolder, // Folder icon pointer
|
---|
| 30 | siProgram // Application program icon pointer
|
---|
| 31 | );
|
---|
| 32 |
|
---|
| 33 | TSystemIcon = Class(TControl)
|
---|
| 34 | Protected
|
---|
| 35 | FHandle: HPOINTER;
|
---|
| 36 | FID: TSystemIconID;
|
---|
| 37 | Procedure SetupComponent; Override;
|
---|
| 38 | Procedure Redraw( const rec: TRect ); Override;
|
---|
| 39 | Procedure SetID( NewID: TSystemIconID );
|
---|
| 40 | Public
|
---|
| 41 | Destructor Destroy; Override;
|
---|
| 42 | Published
|
---|
| 43 | property ID: TSystemIconID read FID write SetID;
|
---|
| 44 | End;
|
---|
| 45 |
|
---|
| 46 | {Define components to export}
|
---|
| 47 | {You may define a page of the component palette and a component bitmap file}
|
---|
| 48 | Exports
|
---|
| 49 | TSystemIcon,'User','';
|
---|
| 50 |
|
---|
| 51 | Implementation
|
---|
| 52 |
|
---|
| 53 | Uses
|
---|
| 54 | PmWin, PmBitmap, PmGpi;
|
---|
| 55 |
|
---|
| 56 | const
|
---|
| 57 | IDCode: array[ Low( TSystemIconID ) .. High( TSystemIconID ) ] of ULONG =
|
---|
| 58 | (
|
---|
| 59 | SPTR_ARROW,
|
---|
| 60 | SPTR_TEXT,
|
---|
| 61 | SPTR_WAIT,
|
---|
| 62 | SPTR_SIZE,
|
---|
| 63 | SPTR_MOVE,
|
---|
| 64 | SPTR_SIZENWSE,
|
---|
| 65 | SPTR_SIZENESW,
|
---|
| 66 | SPTR_SIZEWE,
|
---|
| 67 | SPTR_SIZENS,
|
---|
| 68 | SPTR_APPICON,
|
---|
| 69 | SPTR_ICONINFORMATION,
|
---|
| 70 | SPTR_ICONQUESTION,
|
---|
| 71 | SPTR_ICONERROR,
|
---|
| 72 | SPTR_ICONWARNING,
|
---|
| 73 | SPTR_ILLEGAL,
|
---|
| 74 | SPTR_FILE,
|
---|
| 75 | SPTR_MULTFILE,
|
---|
| 76 | SPTR_FOLDER,
|
---|
| 77 | SPTR_PROGRAM
|
---|
| 78 | );
|
---|
| 79 |
|
---|
| 80 | Procedure TSystemIcon.SetupComponent;
|
---|
| 81 | Begin
|
---|
| 82 | Inherited SetupComponent;
|
---|
| 83 | Width := 32;
|
---|
| 84 | Height := 32;
|
---|
| 85 | ID := siIconInformation;
|
---|
| 86 | Name := 'SystemIcon';
|
---|
| 87 | ParentColor := True;
|
---|
| 88 | Exclude( ComponentState, csAcceptsControls );
|
---|
| 89 | End;
|
---|
| 90 |
|
---|
| 91 | Destructor TSystemIcon.Destroy;
|
---|
| 92 | Begin
|
---|
| 93 | Inherited Destroy;
|
---|
| 94 | End;
|
---|
| 95 |
|
---|
| 96 | Procedure TSystemIcon.SetID( NewID: TSystemIconID );
|
---|
| 97 | var
|
---|
| 98 | Info: POINTERINFO;
|
---|
| 99 | BMInfo: BITMAPINFOHEADER;
|
---|
| 100 | Begin
|
---|
| 101 | if NewID = FID then
|
---|
| 102 | exit;
|
---|
| 103 |
|
---|
| 104 | FID := NewID;
|
---|
| 105 |
|
---|
| 106 | FHandle := WinQuerySysPointer( HWND_DESKTOP,
|
---|
| 107 | IDCode[ NewID ],
|
---|
| 108 | false // don't copy
|
---|
| 109 | );
|
---|
| 110 | WinQueryPointerInfo( FHandle,
|
---|
| 111 | Info );
|
---|
| 112 | if Info.hbmColor > 0 then
|
---|
| 113 | // color bitmap
|
---|
| 114 | GpiQueryBitmapParameters( Info.hbmColor,
|
---|
| 115 | BMInfo )
|
---|
| 116 | else
|
---|
| 117 | // b/w only
|
---|
| 118 | GpiQueryBitmapParameters( Info.hbmPointer,
|
---|
| 119 | BMInfo );
|
---|
| 120 | Width := BmInfo.cx;
|
---|
| 121 | Height := BmInfo.cy;
|
---|
| 122 | Refresh;
|
---|
| 123 | End;
|
---|
| 124 |
|
---|
| 125 | Procedure TSystemIcon.Redraw( const rec: TRect );
|
---|
| 126 | Begin
|
---|
| 127 | Canvas.ClipRect := rec;
|
---|
| 128 | // clear background rectangle
|
---|
| 129 | Canvas.FillRect( rec, Color );
|
---|
| 130 |
|
---|
| 131 | WinDrawPointer( Canvas.Handle, 0, 0, FHandle, DP_NORMAL );
|
---|
| 132 | End;
|
---|
| 133 |
|
---|
| 134 | Initialization
|
---|
| 135 | {Register classes}
|
---|
| 136 | RegisterClasses([TSystemIcon]);
|
---|
| 137 | End.
|
---|
| 138 |
|
---|