Тестовая схема с IC
Код:
Add(MainForm,11764172,315,119) { Point(PHandle) } Add(InlineCode,400025,315,182) { WorkPoints=#10:doMyCursor| DataPoints=#2:PH|5:MinPr|5:MaxPr| Code=#15:unit HiAsmUnit;|0:|9:interface|0:|29:uses Windows,Kol,Share,Debug;|0:|4:type|28: THiAsmClass = class(TDebug)|10: private|18: pc: PControl;|22: OldCursor: hicon;|23: fmin,fmax:Integer;|9: public|19: PH :THI_Event;|29: MinPr, MaxPr :THI_Event;|52: procedure doMyCursor(var dt: TData; idx: word);|63: function Create_Prc_Cursor(min, max, pos: integer): hicon;|68: function Int_Percent(umin, umax, upos, uabs: integer): integer;|5: end;|0:|14:implementation|0:|5:const|24: FONT_COLOR = clblack;|30: PROGRESSBAR_COLOR = clblack;|31: BACKGROUND_COLOR = clBtnFace;|0:|0:|33:procedure THiAsmClass.doMyCursor;|23:const chk: integer = 0;|15:var tmp: TData;|5:begin|35: fmin := ReadInteger(tmp,MinPr,0);|37: fmax := ReadInteger(tmp,MaxPr,100);|26: if not Assigned(pc) then|39: pc := PControl(ToIntegerEvent(PH));|17: if chk = 0 then|9: begin|29: OldCursor := pc.Cursor;|15: inc(chk);|12: end; |60: pc.Cursor := Create_Prc_Cursor(fmin, fmax, ToInteger(dt));|14: //pc.Update;|4:end;|0:|75:function THiAsmClass.Int_Percent(umin, umax, upos, uabs: integer): integer;|7: begin|16: result := 0;|23: if umax < umin then|11: exit;|23: if upos < umin then|11: exit;|23: if upos > umax then|9: begin|20: result := 100;|11: exit;|8: end;|43: if (umin = upos) and (umax = upos) then|9: begin|20: result := 100;|11: exit;|8: end;|60: result := round((upos - umin) / ((umax - umin) / uabs));|4:end;|0:|70:function THiAsmClass.Create_Prc_Cursor(min, max, pos: integer): hicon;|3:var|27: cwidth, cheight: integer;|15: ii: iconinfo;|24: bmc, bmm: KOL.PBitmap;|14: icon: hicon;|14: tw: integer;|13: tx: string;|16: pos_c: TPoint;|0:|36: function Create_Curspace: PBitmap;|7: begin|29: result := NewBitmap(0,0);|34: result.pixelformat := pf24bit;|27: result.width := cwidth;|29: result.height := cheight;|6: end;|0:|5:begin|42: cwidth := getsystemmetrics(sm_cxcursor);|43: cheight := getsystemmetrics(sm_cycursor);|25: bmc := create_curspace;|25: bmm := create_curspace;|0:|14: with bmc^ do|7: begin|43: Canvas.brush.color := BACKGROUND_COLOR;|59: Canvas.FillRect(MakeRect(0, 0, bmc.width, bmc.height));|44: Canvas.brush.color := PROGRESSBAR_COLOR;|0:|50: if Int_Percent(min, max, pos, 100) = 100 then |12: begin |28: GetCursorPos(pos_c);|28: Result := OldCursor;|45: // костыль -> дёрнуть для перерисовки|40: SetCursorPos(pos_c.x,pos_c.y+1);|13: Exit;|10: end;|9: |91: Canvas.fillrect(MakeRect(1 + Int_Percent(min, max, pos, bmc.width - 2), bmm.height - 7,|38: bmc.width - 1, bmc.height - 1));|44: Canvas.brush.color := PROGRESSBAR_COLOR;|73: Canvas.framerect(MakeRect(0, bmc.height - 8, bmc.width, bmc.height));|6: end;|55: tx := int2str(int_percent(min, max, pos, 100)) + '%';|14: with bmm^ do|7: begin|31: tw := Canvas.textwidth(tx);|48: Canvas.textout((cwidth - tw) div 2, 8, tx); |7: end; |14: with bmc^ do|7: begin|32: Canvas.font.FontHeight := 8;|31: Canvas.font.FontWidth := 8;|38: Canvas.font.FontStyle := [fsbold];|45: Canvas.font.color := FONT_COLOR; |45: Canvas.brush.color := BACKGROUND_COLOR; |47: Canvas.textout((cwidth - tw) div 2, 8, tx);|6: end;|0:|20: ii.fIcon := false;|28: ii.hbmColor := bmc.Handle;|27: ii.hbmMask := bmm.handle;|19: ii.xHotspot := 0;|19: ii.yHotspot := 0;|33: icon := createiconindirect(ii);|27: result := copyicon(icon);|20: destroyicon(icon);|11: bmc.free;|12: bmm.Free; |4:end;|0:|4:end.| link(PH,11764172:PHandle,[]) } Add(Button,6800273,161,182) { Left=50 Top=45 link(onClick,2389974:doTimer,[]) } Add(Timer,2389974,210,182) { Interval=50 Enable=1 AutoStop=100 Point(onStop) link(onTimer,6469897:doNext,[]) link(onStop,6469897:doReset,[]) } Add(CounterEx,6469897,259,182) { Point(doReset) link(onNext,400025:doMyCursor,[]) }