source: branches/delphi/LocalPlayer/PVSB.pas

Last change on this file was 6, checked in by chronos, 7 years ago
  • Modified: Formated all project source files using Delphi formatter as original indentation and other formatting was really bad.
File size: 3.3 KB
Line 
1{$INCLUDE switches}
2unit PVSB;
3
4interface
5
6uses
7 Windows, Messages, SysUtils;
8
9type
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
22implementation
23
24const
25 Count: integer = 0;
26
27procedure CreatePVSB;
28begin
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;
34end;
35
36procedure InitPVSB;
37begin
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)
51end;
52
53function ProcessPVSB;
54var
55 NewPos: integer;
56begin
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
94end;
95
96function ProcessMouseWheel;
97var
98 NewPos: integer;
99begin
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
118end;
119
120procedure ShowPVSB(var sb: TPVScrollbar; Visible: boolean);
121begin
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)
126end;
127
128procedure EndPVSB(var sb: TPVScrollbar);
129begin
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
141end;
142
143end.
Note: See TracBrowser for help on using the repository browser.