1 | {$INCLUDE switches}
|
---|
2 | unit PVSB;
|
---|
3 |
|
---|
4 | interface
|
---|
5 |
|
---|
6 | uses
|
---|
7 | Windows, Messages, SysUtils;
|
---|
8 |
|
---|
9 | type
|
---|
10 | TPVScrollbar = record
|
---|
11 | h: integer;
|
---|
12 | si: TScrollInfo end;
|
---|
13 |
|
---|
14 | procedure CreatePVSB(var sb: TPVScrollbar; Handle, y0, x1, y1: integer);
|
---|
15 | procedure InitPVSB(var sb: TPVScrollbar; max, Page: integer);
|
---|
16 | function ProcessPVSB(var sb: TPVScrollbar; const m: TMessage): boolean;
|
---|
17 | function ProcessMouseWheel(var sb: TPVScrollbar; const m: TMessage)
|
---|
18 | : boolean;
|
---|
19 | procedure ShowPVSB(var sb: TPVScrollbar; Visible: boolean);
|
---|
20 | procedure EndPVSB(var sb: TPVScrollbar);
|
---|
21 |
|
---|
22 | implementation
|
---|
23 |
|
---|
24 | const
|
---|
25 | Count: integer = 0;
|
---|
26 |
|
---|
27 | procedure CreatePVSB;
|
---|
28 | begin
|
---|
29 | inc(Count);
|
---|
30 | sb.h := CreateWindowEx(0, 'SCROLLBAR', pchar('PVSB' + IntToStr(Count)),
|
---|
31 | SBS_VERT or WS_CHILD or SBS_RIGHTALIGN, x1 - 100, y0, 100, y1 - y0,
|
---|
32 | Handle, 0, 0, nil);
|
---|
33 | sb.si.cbSize := 28;
|
---|
34 | end;
|
---|
35 |
|
---|
36 | procedure InitPVSB;
|
---|
37 | begin
|
---|
38 | with sb.si do
|
---|
39 | begin
|
---|
40 | nMin := 0;
|
---|
41 | nMax := max;
|
---|
42 | npos := 0;
|
---|
43 | nPage := Page;
|
---|
44 | FMask := SIF_PAGE or SIF_POS or SIF_RANGE;
|
---|
45 | end;
|
---|
46 | SetScrollInfo(sb.h, SB_CTL, sb.si, true);
|
---|
47 | if max < Page then
|
---|
48 | ShowWindow(sb.h, SW_HIDE)
|
---|
49 | else
|
---|
50 | ShowWindow(sb.h, SW_SHOW)
|
---|
51 | end;
|
---|
52 |
|
---|
53 | function ProcessPVSB;
|
---|
54 | var
|
---|
55 | NewPos: integer;
|
---|
56 | begin
|
---|
57 | with sb.si do
|
---|
58 | if nMax < integer(nPage) then
|
---|
59 | result := false
|
---|
60 | else
|
---|
61 | begin
|
---|
62 | if m.wParamLo in [SB_THUMBPOSITION, SB_THUMBTRACK] then
|
---|
63 | begin
|
---|
64 | result := m.wParamHi <> npos;
|
---|
65 | npos := m.wParamHi;
|
---|
66 | end
|
---|
67 | else
|
---|
68 | begin
|
---|
69 | case m.wParamLo of
|
---|
70 | SB_LINEUP:
|
---|
71 | NewPos := npos - 1;
|
---|
72 | SB_LINEDOWN:
|
---|
73 | NewPos := npos + 1;
|
---|
74 | SB_PAGEUP:
|
---|
75 | NewPos := npos - integer(nPage);
|
---|
76 | SB_PAGEDOWN:
|
---|
77 | NewPos := npos + integer(nPage);
|
---|
78 | else
|
---|
79 | NewPos := npos
|
---|
80 | end;
|
---|
81 | if NewPos < 0 then
|
---|
82 | NewPos := 0;
|
---|
83 | if NewPos > nMax - integer(nPage) + 1 then
|
---|
84 | NewPos := nMax - integer(nPage) + 1;
|
---|
85 | result := NewPos <> npos;
|
---|
86 | if (NewPos <> npos) or (m.wParamLo = SB_ENDSCROLL) then
|
---|
87 | begin
|
---|
88 | npos := NewPos;
|
---|
89 | FMask := SIF_POS;
|
---|
90 | SetScrollInfo(sb.h, SB_CTL, sb.si, true);
|
---|
91 | end;
|
---|
92 | end
|
---|
93 | end
|
---|
94 | end;
|
---|
95 |
|
---|
96 | function ProcessMouseWheel;
|
---|
97 | var
|
---|
98 | NewPos: integer;
|
---|
99 | begin
|
---|
100 | with sb.si do
|
---|
101 | if nMax < integer(nPage) then
|
---|
102 | result := false
|
---|
103 | else
|
---|
104 | begin
|
---|
105 | NewPos := npos - m.wParam div (1 shl 16 * 40);
|
---|
106 | if NewPos < 0 then
|
---|
107 | NewPos := 0;
|
---|
108 | if NewPos > nMax - integer(nPage) + 1 then
|
---|
109 | NewPos := nMax - integer(nPage) + 1;
|
---|
110 | result := NewPos <> npos;
|
---|
111 | if NewPos <> npos then
|
---|
112 | begin
|
---|
113 | npos := NewPos;
|
---|
114 | FMask := SIF_POS;
|
---|
115 | SetScrollInfo(sb.h, SB_CTL, sb.si, true);
|
---|
116 | end
|
---|
117 | end
|
---|
118 | end;
|
---|
119 |
|
---|
120 | procedure ShowPVSB(var sb: TPVScrollbar; Visible: boolean);
|
---|
121 | begin
|
---|
122 | if not Visible or (sb.si.nMax < integer(sb.si.nPage)) then
|
---|
123 | ShowWindow(sb.h, SW_HIDE)
|
---|
124 | else
|
---|
125 | ShowWindow(sb.h, SW_SHOW)
|
---|
126 | end;
|
---|
127 |
|
---|
128 | procedure EndPVSB(var sb: TPVScrollbar);
|
---|
129 | begin
|
---|
130 | with sb.si do
|
---|
131 | begin
|
---|
132 | if nMax < integer(nPage) then
|
---|
133 | npos := 0 // hidden
|
---|
134 | else
|
---|
135 | begin
|
---|
136 | sb.si.npos := nMax - integer(nPage) + 1;
|
---|
137 | sb.si.FMask := SIF_POS;
|
---|
138 | SetScrollInfo(sb.h, SB_CTL, sb.si, true);
|
---|
139 | end
|
---|
140 | end
|
---|
141 | end;
|
---|
142 |
|
---|
143 | end.
|
---|