⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fccalculator.pas

📁 一套及时通讯的原码
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  else if Key=vk_Escape then c:='e'
  else begin
    // Code := MapVirtualKey(Key, 2);
    // c:=char(Code);
    // 3/1/2002-PYW-Use new function to handle num pad keys in windows 98.
    c:=fcMessageCodeToChar(key);
    if (ssShift in Shift) or OpPressedWithShiftFlag then begin
       if c in ['=', '2', '5', '8', '-'] then
          OpPressedWithShiftFlag := False;
       case c of
       '=':c:='+';
       '2':c:='@';
       '5':c:='%';
       '8':c:='*';
       '-':c:='_';
       end;
    end;
  end;

  fb:= CharToButton(c,ssctrl in shift);
  if fb<>nil then begin
    fb.DrawKeyDown := False;
    fb.invalidate;
  end;

  inherited;
end;

procedure TfcCalculator.ResultKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var c:Char;
    fb:TfcCalcButton;
begin
  if {(OpPressedWithShiftFlag) or }(Key=16) then begin
    inherited;
    exit;
  end;

  if Key=vk_Return then c:='='
  else if Key=vk_Delete then c:='c'
  else if Key=vk_Back then c:='b'
  else if Key=vk_Escape then c:='e'
  else begin
  //  Code := MapVirtualKey(Key, 2);
  //  c:=char(Code);
    //3/1/2002-PYW-Use new function to handle num pad keys in windows 98.
    c:=fcMessageCodeToChar(key);
    if (ssShift in Shift) then begin
       OpPressedWithShiftFlag:= true;
       case c of
       '=':c:='+';
       '2':c:='@';
       '5':c:='%';
       '8':c:='*';
       '-':c:='_';
       else
         OpPressedWithShiftFlag := False;
       end;
    end;
  end;

  fb:= CharToButton(c,ssctrl in shift);
  if fb<>nil then begin
    fb.DrawKeyDown := True;
    fb.invalidate;
  end;

  DoCalc(CharToOp(c,(ssCtrl in Shift)));
  inherited;

  CalcEdit.SelStart := Length(CalcEdit.Text);
end;

function TfcCalculator.OpToChar(aOp:TfcCalcButtonType):Char;
begin
  Result := ' ';
    case aOP of
        btNone : Result := ' ';
        bt0 : Result := '0';
        bt1 : Result := '1';
        bt2 : Result := '2';
        bt3 : Result := '3';
        bt4 : Result := '4';
        bt5 : Result := '5';
        bt6 : Result := '6';
        bt7 : Result := '7';
        bt8 : Result := '8';
        bt9 : Result := '9';
        btDecimal : Result := DecimalSeparator;
        btPlusMinus : Result := '_';
        btMultiply: Result := '*';
        btDivide: Result := '/';
        btAdd: Result := '+';
        btSubtract: Result := '-';
        btEquals:Result :='=';
        btSqrt:Result := '@';
        btPercent:Result :='%';
        btInverse:Result := 'i';
        btBackspace:Result := 'b';
        btClear :Result := 'd';
        btClearAll: Result := 'e';
        btMRecall: Result := 'R';
        btMStore: Result := 'm';
        btMClear: Result := 'c';
        btMAdd: Result := 'a';
    end;
end;

procedure TfcCalculator.WMSize(var Message: TWMSize);
var NewBoundsRect: TRect;
  function sameRect(rect1, rect2: TRect): boolean;
  begin
     result:=
      (rect1.left = rect2.left) and
      (rect1.right = rect2.right) and
      (rect1.top = rect2.top) and
      (rect1.bottom = rect2.bottom);
  end;
begin
  inherited;
  NewboundsRect:= Rect(0, 0, BoundsRect.right-BoundsRect.left, BoundsRect.bottom-BoundsRect.top);
  if SameRect(OldBoundsRect, NewBoundsRect) then exit;
  OldboundsRect:= NewBoundsRect;

  InitBitmapsFlag:= True;
  if csLoading in COmponentState then exit;

  CalcButtons;
end;

procedure TfcCalculator.Paint;
const
  Alignments: array[TAlignment] of Longint = (DT_LEFT, DT_RIGHT, DT_CENTER);
var NewboundsRect: TRect;
    ARect: TRect;
    TopColor, BottomColor: TColor;
    i,j:integer;
    BtnShadow,BtnLight:TColor;
    procedure AdjustColors(Bevel: TPanelBevel);
    begin
      TopColor := clBtnHighlight;
      if Bevel = bvLowered then TopColor := clBtnShadow;
      BottomColor := clBtnShadow;
      if Bevel = bvLowered then BottomColor := clBtnHighlight;
    end;
begin
  if InitBitmapsFlag and ((not BackGroundBitmap.Bitmap.Empty) or (not BackGroundBitmap.Graphic.Empty)) then begin
     NewboundsRect:= Rect(0, 0, BoundsRect.right-BoundsRect.left, BoundsRect.bottom-BoundsRect.top);
     PaintBitmap.Width := NewBoundsRect.right;
     PaintBitmap.Height:= NewBoundsRect.Bottom;
     PaintBitmap.TransparentMode := tmFixed;
     PaintBitmap.TransparentColor := clNone;
     case BackgroundBitmapDrawStyle of
        cbdTile:
             begin
                with BackgroundBitmap do begin
                  i := 0;
                  while i < Self.Width do begin
                    j := 0;
                    while j < Self.Height do begin
                       PaintBitmap.Canvas.Draw(i,j,Graphic);
                      // r:=rect(i,j,i+Bitmap.width,j+Bitmap.height);
                      // PaintBitmap.canvas.CopyRect(r,backgroundbitmap.bitmap.canvas,r);
                       inc(j, Bitmap.Height);
                    end;
                    inc(i, Bitmap.Width);
                  end;
                end
             end;
        cbdTopLeft:
             begin
                with BackgroundBitmap do
                   PaintBitmap.Canvas.Draw(0, 0, Graphic);
             end;
        cbdCenter:
             begin
                with BackgroundBitmap do
                   PaintBitmap.Canvas.Draw((self.width-Width)div 2,
                               (self.Height-Height) div 2, Graphic);
             end;
        cbdStretch:
             begin
                with BackgroundBitmap do
                   PaintBitmap.Canvas.StretchDraw(Rect(0, 0, newBoundsRect.right, NewBoundsRect.bottom), Graphic);
             end;
   end;
   InitBitmapsFlag:= False;
  end;
  ARect := GetClientRect;
  if ((not BackGroundBitmap.Bitmap.Empty) or (not BackGroundBitmap.Graphic.Empty)) then
     Canvas.CopyRect(ARect,PaintBitmap.Canvas,Rect(0,0,Width,Height))
  else
  begin
    with Canvas do
    begin
      Brush.Color := PanelColor;
      FillRect(ARect);
    end;
  end;
  if cboHideBorder in Options then exit;
  if Border3D then begin
    BtnShadow:= changeColor(Color,False);
    BtnLight := changeColor(Color,True);
    Frame3D(Canvas, ARect, BtnLight, clBlack, 1);
    Frame3D(Canvas, ARect, clWhite, BtnShadow, 1);
  end
  else begin
    Frame3D(Canvas, ARect, clWhite, clBlack, 1);
  end;
end;

procedure TfcCalculator.CalcButtons;
var
  j: integer;
  i:TfcCalcButtonType;
  BtnWidth,BtnHeight :integer;
  clrbtnw,clrbtnh:integer;
  numbuttonsx,numbuttonsy:integer;
  row:integer;
  x,y:integer;

  aleft,statuspaneloffset,diff:integer;
  pad,simplecalcflag:integer;
  flag:boolean;
begin
  statuspaneloffset :=0;
  numbuttonsx:=6; // Number of Columns
  if cboHideMemory in Options then dec(numbuttonsx);

  //Number of Rows
  numbuttonsy:=5;
  if not (cboHideEditor in Options) then inc(numbuttonsy);

  //Add another row for space for summary status panel.
  if False and (cboShowStatus in Options) then begin
    inc(numbuttonsy);
    statuspaneloffset :=1;
  end;

  if cboSimpleCalc in Options then begin
     numbuttonsx:=4;
  end;

  if (cboSimpleCalc in Options) or (cboHideMemory in Options) then
     x:= Width-ButtonMargin*(numbuttonsx-1)-(5+5)
  else x:= Width-ButtonMargin*(numbuttonsx-1)-(5+5+5);
  y:= Height-ButtonMargin*(numbuttonsy-1)-10;
  btnWidth := x div numbuttonsx;
  btnHeight := y div numbuttonsy;

  if (not (cboHideMemory in Options)) and not (cboSimpleCalc in Options) then begin
    if (cboHideEditor in Options) then row := 1
    else row := 2;

    Btns[btMClear] := ButtonRecord(btMClear,5+row*(btnheight+ButtonMargin), 5, BtnWidth, btnHeight, 'MC',clRed,'Clears any number stored in memory.'+#13#10+#13#10+'Keyboard equivalent = CTRL + L');
    inc(row);
    Btns[btMRecall] := ButtonRecord(btMRecall,5+row*(btnheight+ButtonMargin), 5, btnwidth, btnHeight, 'MR',clRed,'Recalls the number stored in memory.');
    inc(row);
    Btns[btMStore] := ButtonRecord(btMStore,5+row*(btnheight+ButtonMargin), 5, btnwidth, btnHeight, 'MS',clRed,'Stores the displayed number in memory.');
    inc(row);
    Btns[btMAdd] := ButtonRecord(btMAdd,5+row*(btnheight+ButtonMargin), 5, btnwidth, btnHeight, 'M+',clRed,'Adds displayed number to number in memory.');
    clrbtnw := (width - 15 - btnwidth - ButtonMargin*3) div 3;
    pad := ((Width-5-BtnWidth)-4*(BtnWidth+ButtonMargin)) - (Width-5-clrbtnw-2*(clrbtnw+ButtonMargin));
  end
  else begin
    if csDesigning in ComponentState then begin
        if (cboHideEditor in Options) then row := 1
        else row := 2;
        Btns[btMClear] := ButtonRecord(btMClear,5+row*(btnheight+ButtonMargin), 5, BtnWidth, btnHeight, 'MC',clRed,'Clears any number stored in memory.'+#13#10+#13#10+'Keyboard equivalent = CTRL + L');
        inc(row);
        Btns[btMRecall] := ButtonRecord(btMRecall,5+row*(btnheight+ButtonMargin), 5, btnwidth, btnHeight, 'MR',clRed,'Recalls the number stored in memory.');
        inc(row);
        Btns[btMStore] := ButtonRecord(btMStore,5+row*(btnheight+ButtonMargin), 5, btnwidth, btnHeight, 'MS',clRed,'Stores the displayed number in memory.');
        inc(row);
        Btns[btMAdd] := ButtonRecord(btMAdd,5+row*(btnheight+ButtonMargin), 5, btnwidth, btnHeight, 'M+',clRed,'Adds displayed number to number in memory.');
    end;

    clrbtnw := (width - ButtonMargin*3) div 3;
    pad := 5;
  end;

  if cboHideEditor in Options then clrbtnh:=5
  else clrbtnh:=5+btnheight+ButtonMargin;

  if not (cboSimpleCalc in Options) then begin
    diff := abs((Width-5-clrbtnw-2*(clrbtnw+ButtonMargin))-5);
    if (cboHideMemory in Options) then
       Btns[btBackspace] := ButtonRecord(btBackSpace,clrbtnh,5, clrbtnw-diff, btnHeight, 'Back',clRed,'Deletes last digit of displayed number.')
    else Btns[btBackspace] := ButtonRecord(btBackSpace,clrbtnh,Width-5-clrbtnw-2*(clrbtnw+ButtonMargin), clrbtnw, btnHeight, 'Back',clRed,'Deletes last digit of displayed number.');
    Btns[btClear] := ButtonRecord(btClear,clrbtnh, Width-5-(clrbtnw+ButtonMargin)-clrbtnw, clrbtnw, btnHeight, 'CE', clRed,'Clears displayed number.');
    Btns[btClearAll] := ButtonRecord(btClearAll,clrbtnh, Width-5-clrbtnw, clrbtnw, btnHeight, 'C', clRed,'Clears the current calculation.');
  end
  else begin
    Btns[btBackspace] := ButtonRecord(btBackSpace,5+(numbuttonsy-1-statuspaneloffset)*(btnheight+ButtonMargin),Width-5-clrbtnw-(clrbtnw+ButtonMargin), clrbtnw, btnHeight, 'Back',clRed,'Deletes last digit of displayed number.');
//    Btns[btClearAll] := ButtonRecord(btClearAll,5+(numbuttonsy-1-statuspaneloffset)*(btnheight+ButtonMargin), Width-5-clrbtnw-2*(clrbtnw+ButtonMargin), clrbtnw, btnHeight, 'C', clRed,'Clears the current calculation.');
    diff := abs((Width-5-clrbtnw-2*(clrbtnw+ButtonMargin))-5);
    Btns[btClearAll] := ButtonRecord(btClearAll,5+(numbuttonsy-1-statuspaneloffset)*(btnheight+ButtonMargin), 5, clrbtnw-diff, btnHeight, 'C', clRed,'Clears the current calculation.');
    Btns[btEquals] := ButtonRecord(btEquals,5+(numbuttonsy-1-statuspaneloffset)*(btnheight+ButtonMargin), Width-5-clrbtnw, clrbtnw, btnHeight, '=',clRed,'Performs any operation on previous numbers.');
    if csDesigning in ComponentState then
       Btns[btClear] := ButtonRecord(btClear,clrbtnh, Width-5-(clrbtnw+ButtonMargin)-clrbtnw, clrbtnw, btnHeight, 'CE', clRed,'Clears displayed number.');
  end;

//  pad := ((Width-5-BtnWidth)-4*(BtnWidth+ButtonMargin)) - (Width-5-clrbtnw-2*(clrbtnw+ButtonMargin));
  if pad <= 0 then pad := 0;
  if cboHideEditor in Options then row := 1
  else row := 2;
  simplecalcflag := 0;
  if cboSimpleCalc in Options then begin
    simplecalcflag := 1;
    dec(row);
  end;

//  diff := abs((Width-5-clrbtnw-2*(clrbtnw+ButtonMargin))-5);
  if (cboHideMemory in Options) or (cboSimpleCalc in Options) then aLeft := 5
  else aLeft := -pad+ (Width-5-BtnWidth)-(4-simplecalcflag)*(BtnWidth+ButtonMargin);
  Btns[bt7] := ButtonRecord(bt7,5+row*(btnheight+ButtonMargin),aLeft  , BtnWidth, btnHeight, '7',clBlue,'Puts this number in display.');
  inc(row);
  Btns[bt4] := ButtonRecord(bt4,5+row*(btnheight+ButtonMargin),aLeft   , BtnWidth, btnHeight, '4',clBlue,'Puts this number in display.');
  inc(row);
  Btns[bt1] := ButtonRecord(bt1,5+row*(btnheight+ButtonMargin),aLeft   , BtnWidth, btnHeight, '1',clBlue,'Puts this number in display.');
  inc(row);
  Btns[bt0] := ButtonRecord(bt0,5+row*(btnheight+ButtonMargin),aLeft   , BtnWidth, btnHeight, '0',clBlue,'Puts this number in display.');
{
  Btns[bt7] := ButtonRecord(bt7,5+row*(btnheight+ButtonMargin),-pad+ (Width-5-BtnWidth)-(4-simplecalcflag)*(BtnWidth+ButtonMargin), BtnWidth, btnHeight, '7',clBlue,'Puts this number in display.');
  inc(row);
  Btns[bt4] := ButtonRecord(bt4,5+row*(btnheight+ButtonMargin),-pad+ (Width-5-BtnWidth)-(4-simplecalcflag)*(BtnWidth+ButtonMargin), BtnWidth, btnHeight, '4',clBlue,'Puts this number in display.');
  inc(row);
  Btns[bt1] := ButtonRecord(bt1,5+row*(btnheight+ButtonMargin),-pad+ (Width-5-BtnWidth)-(4-simplecalcflag)*(BtnWidth+ButtonMargin), BtnWidth, btnHeight, '1',clBlue,'Puts this number in display.');
  inc(row);
  Btns[bt0] := ButtonRecord(bt0,5+row*(btnheight+ButtonMargin),-pad+ (Width-5-BtnWidth)-(4-simplecalcflag)*(BtnWidth+ButtonMargin), BtnWidth, btnHeight, '0',clBlue,'Puts this number in display.');
}
  if cboHideEditor in Options then row := 1
  else row := 2;
  if cboSimpleCalc in Options then dec(row);
  if (cboHideMemory in Options) or (cboSimpleCalc in Options) then aLeft := 5+BtnWidth+ButtonMargin
  else aLeft := -pad+ (Width-5-BtnWidth)-(3-simplecalcflag)*(BtnWidth+ButtonMargin);
  Btns[bt8] := ButtonRecord(bt8,5+row*(btnheight+ButtonMargin),aLeft, BtnWidth, btnHeight, '8',clBlue,'Puts this number in display.');
  inc(row);
  Btns[bt5] := ButtonRecord(bt5,5+row*(btnheight+ButtonMargin),aLeft, BtnWidth, btnHeight, '5',clBlue,'Puts this number in display.');
  inc(row);
  Btns[bt2] := ButtonRecord(bt2,5+row*(btnheight+ButtonMargin),aLeft, BtnWidth, btnHeight, '2',clBlue,'Puts this number in display.');
  if cboSimpleCalc in Options then begin
    inc(row);
    Btns[btDecimal] := ButtonRecord(btDecimal,5+row*(btnheight+ButtonMargin),aLeft, BtnWidth, btnHeight, DecimalSeparator,clBlue,'Inserts a decimal point.');
  end
  else begin
    inc(row);
    Btns[btPlusMinus] := ButtonRecord(btPlusMinus,5+row*(btnheight+ButtonMargin),aLeft, BtnWidth, btnHeight, '+/-',clBlue,'Changes sign of displayed number.');
  end;

  if cboHideEditor in Options then row := 1
  else row := 2;
  if cboSimpleCalc in Options then dec(row);
  if (cboHideMemory in Options) or (cboSimpleCalc in Options) then aLeft := 5+2*(BtnWidth+ButtonMargin)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -