unit area; //{$DEFINE _DEBUG} interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, ImgList, Menus, myMessagePanel, StdCtrls, myLabel, AppEvnts, Buttons, ActnList, System.ImageList, System.Actions; type TApp_TOOLDskCaptArea = class(TForm) ActionList1: TActionList; Action_Move_Left: TAction; Action_Move_Right: TAction; Action_Move_Up: TAction; Action_Move_Down: TAction; Action_Zoom_Up: TAction; Action_Zoom_Down: TAction; Action_Capture_Execute: TAction; PopupMenu_Main: TPopupMenu; MenuItem_PDisp_Info: TMenuItem; MenuItem_PFile_Line1: TMenuItem; MenuItem_PFile_Close: TMenuItem; Image_Left: TImage; Image_Top: TImage; Image_Right: TImage; Image_Bottom: TImage; Image_LeftTop: TImage; Image_RightTop: TImage; Image_LeftBottom: TImage; Image_RightBottom: TImage; Image_Close: TImage; MyMessagePanel1: TMyMessagePanel; ApplicationEvents1: TApplicationEvents; ImageList1: TImageList; Timer1: TTimer; PaintBox1: TPaintBox; procedure Action_Move_LeftExecute (Sender: TObject); procedure Action_Zoom_UpExecute (Sender: TObject); procedure Action_Capture_ExecuteExecute(Sender: TObject); procedure FormCreate (Sender: TObject); procedure FormDestroy (Sender: TObject); procedure FormResize (Sender: TObject); procedure FormPaint (Sender: TObject); procedure FormKeyDown (Sender: TObject; var Key: Word; Shift: TShiftState); procedure FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); procedure MenuItem_PDisp_InfoClick (Sender: TObject); procedure MenuItem_PFile_CloseClick(Sender: TObject); procedure Image_CloseClick (Sender: TObject); procedure Image_MouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure MyMessagePanel1TextChange(Sender: TObject; Text: String); procedure Timer1Timer(Sender: TObject); procedure FormDblClick(Sender: TObject); procedure Image_MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private { Private 宣言 } FbmpLeft : TBitmap; FbmpTop : TBitmap; FbmpRight : TBitmap; FbmpBottom : TBitmap; FBitmapDraw : TBitmap; FhMessageHandle : HWND; FptMove : TPoint; FptMouseGesture : TPoint; //簡易マウスジェスチャー用 procedure FGetAreaRect; procedure WMMove(var Msg: TWMMove); message WM_MOVE; public { Public 宣言 } procedure Move(iX, iY: Integer); procedure Zoom(iLeft, iTop, iRight, iBottom: Integer); overload; procedure Zoom(iZoom: Integer); overload; property MessageHandle : HWND write FhMessageHandle; end; var App_TOOLDskCaptArea: TApp_TOOLDskCaptArea; implementation uses {$IFDEF _DEBUG} myDebug, {$ENDIF} System.Types, myControl, myGraphic, myNum, myParam, mySize, myWindow, area_ctrl; {$R *.dfm} procedure TApp_TOOLDskCaptArea.WMMove(var Msg: TWMMove); begin if (Application.Terminated) then begin Exit; end; FGetAreaRect; FptMove := Self.ClientOrigin; Msg.Result := 0; end; procedure TApp_TOOLDskCaptArea.FormCreate(Sender: TObject); begin {$IFDEF _DEBUG} myDebug.gpcMessageModeSet(True); {$ENDIF} gpcWindowStyleDel(Self.Handle, [WS_CAPTION]); ShowWindow(Application.Handle, SW_HIDE); gpcWindowStyleExAdd(Application.Handle, WS_EX_TOOLWINDOW); Self.DoubleBuffered := True; //チラツキを抑えるため Self.Constraints.MinWidth := (Width - ClientWidth) + Image_LeftTop.Width + Image_RightTop.Width +1; Self.Constraints.MinHeight := (Height - ClientHeight) + Image_LeftTop.Height + Image_RightTop.Height +1; // Self.Color := Self.TransparentColorValue; Self.ClientWidth := 320 + Image_LeftTop.Width + Image_RightTop.Width; Self.ClientHeight := 240 + Image_LeftTop.Height + Image_RightTop.Height; FptMove := Self.ClientOrigin; PaintBox1.Align := alClient; FbmpLeft := TBitmap.Create; FbmpTop := TBitmap.Create; FbmpRight := TBitmap.Create; FbmpBottom := TBitmap.Create; FBitmapDraw := TBitmap.Create; FbmpLeft.Width := Image_Left.Width; FbmpRight.Width := Image_Right.Width; FbmpTop.Height := Image_Top.Height; FbmpBottom.Height := Image_Bottom.Height; FbmpLeft.Canvas.Brush.Bitmap := Image_Left.Picture.Bitmap; FbmpTop.Canvas.Brush.Bitmap := Image_Top.Picture.Bitmap; FbmpRight.Canvas.Brush.Bitmap := Image_Right.Picture.Bitmap; FbmpBottom.Canvas.Brush.Bitmap := Image_Bottom.Picture.Bitmap; Image_LeftTop.Left := 0; Image_Lefttop.Top := 0; Image_RightTop.Left := Self.ClientWidth - Image_RightTop.Width; Image_RightTop.Top := 0; Image_Close.Left := Image_RightTop.Left; Image_Close.Top := Image_RightTop.Top; Image_RightBottom.Left := Image_RightTop.Left; Image_RightBottom.Top := Self.ClientHeight - Image_RightBottom.Height; Image_LeftBottom.Left := 0; Image_LeftBottom.Top := Image_RightBottom.Top; Image_LeftTop.Anchors := [akLeft, akTop]; Image_RightTop.Anchors := [akTop, akRight]; Image_RightBottom.Anchors := [akRight, akBottom]; Image_LeftBottom.Anchors := [akLeft, akBottom]; Image_Close.Anchors := [akTop, akRight]; Image_Left.Left := Image_LeftTop.Left; Image_Left.Top := Image_LeftTop.Height; Image_Left.Width := Image_LeftTop.Width; Image_Left.Height := Image_LeftBottom.Top - Image_Left.Height; Image_Left.Anchors := [akLeft, akTop, akBottom]; Image_Right.Left := Image_RightTop.Left; Image_Right.Top := Image_RightTop.Height; Image_Right.Width := Image_Right.Width; Image_Right.Height := Image_Left.Height; Image_Right.Anchors := [akRight, akTop, akBottom]; Image_Top.Left := Image_LeftTop.Width; Image_Top.Top := Image_LeftTop.Top; Image_Top.Width := Image_RightTop.Left - Image_Left.Left; Image_Top.Height := Image_LeftTop.Height; Image_Top.Anchors := [akLeft, akTop, akRight]; Image_Bottom.Left := Image_LeftBottom.Width; Image_Bottom.Top := Image_LeftBottom.Top; Image_Bottom.Width := Image_Top.Width; Image_Bottom.Height := Image_LeftBottom.Height; Image_Bottom.Anchors := [akLeft, akBottom, akRight]; Tag := 1; FormResize(nil); if (MenuItem_PDisp_Info.Checked) then begin MyMessagePanel1TextChange(nil, '/CREATE_CTRLPANEL'); end; end; procedure TApp_TOOLDskCaptArea.FormDestroy(Sender: TObject); var i : Integer; begin for i := 0 to Screen.FormCount-1 do begin if (Screen.Forms[i] is TApp_TOOLDskCaptAreaCtrl) then begin TApp_TOOLDskCaptAreaCtrl(Screen.Forms[i]).Close; end; end; FbmpLeft.Free; FbmpTop.Free; FbmpRight.Free; FbmpBottom.Free; FBitmapDraw.Free; end; procedure TApp_TOOLDskCaptArea.FGetAreaRect; var lrc_Rect : TRect; i : Integer; l_AreaCtrl : TApp_TOOLDskCaptAreaCtrl; begin lrc_Rect := Rect( Image_LeftTop.BoundsRect.Right, Image_LeftTop.BoundsRect.Bottom, Image_RightBottom.BoundsRect.Left, Image_RightBottom.BoundsRect.Top ); lrc_Rect := gfnrcRectMove(lrc_Rect, Self.ClientToScreen(Point(Image_LeftTop.Width, Image_LeftTop.Height))); Self.Hint := Format('(%d,%d) %dx%d', [lrc_Rect.Left, lrc_Rect.Top, gfniRectWidth(lrc_Rect), gfniRectHeight(lrc_Rect)]); myMessagePanel.gpcMessagePanelUnicast( Format('/AREA_WINDOW:%d,%d,%d,%d', [ lrc_Rect.Left, lrc_Rect.Top, lrc_Rect.Right, lrc_Rect.Bottom ]), FhMessageHandle ); for i := 0 to Screen.FormCount-1 do begin if (Screen.Forms[i] is TApp_TOOLDskCaptAreaCtrl) then begin l_AreaCtrl := TApp_TOOLDskCaptAreaCtrl(Screen.Forms[i]); l_AreaCtrl.Caption := Self.Hint; l_AreaCtrl.Paint_Zoom.Position := Point( l_AreaCtrl.Paint_Zoom.Position.X + Self.ClientOrigin.X - FptMove.X, l_AreaCtrl.Paint_Zoom.Position.Y + Self.ClientOrigin.Y - FptMove.Y ); end; end; end; procedure TApp_TOOLDskCaptArea.FormResize(Sender: TObject); begin if (Tag = 0) then begin Exit; end; //myDebug.gpcDebug('Resize'); FBitmapDraw.Width := Self.ClientWidth; FBitmapDraw.Height := Self.ClientHeight; FBitmapDraw.Canvas.Brush.Color := Self.TransparentColorValue; FBitmapDraw.Canvas.FillRect(Rect(0, 0, FBitmapDraw.Width, FBitmapDraw.Height)); { FBitmapDraw.Canvas.FillRect(Rect( FbmpLeft.Width, FbmpLeft.Height, FBitmapDraw.Width - FbmpRight.Width, //幅ではなくRECTなのでFBitmapDraw.Width - (FbmpLeft.Width + FbmpRight.Width)ではない FBitmapDraw.Height - FbmpBottom.Height )); } FbmpLeft.Height := Self.ClientHeight - FbmpTop.Height * 2; FbmpRight.Height := FbmpLeft.Height; FbmpTop.Width := Self.ClientWidth - FbmpLeft.Width * 2; FbmpBottom.Width := FbmpTop.Width; FbmpLeft.Canvas.FillRect (Rect(0, 0, FbmpLeft.Width, FbmpLeft.Height)); FbmpTop.Canvas.FillRect (Rect(0, 0, FbmpTop.Width, FbmpTop.Height)); FbmpRight.Canvas.FillRect (Rect(0, 0, FbmpRight.Width, FbmpRight.Height)); FbmpBottom.Canvas.FillRect(Rect(0, 0, FbmpBottom.Width, FbmpBottom.Height)); Image_Left.Picture.Bitmap := FbmpLeft; Image_Top.Picture.Bitmap := FbmpTop; Image_Right.Picture.Bitmap := FbmpRight; Image_Bottom.Picture.Bitmap := FbmpBottom; { BitBlt(FBitmapDraw.Canvas.Handle, 0, FbmpTop.Height, FbmpLeft.Width, FbmpLeft.Height, FbmpLeft.Canvas.Handle, 0, 0, SRCCOPY); BitBlt(FBitmapDraw.Canvas.Handle, FbmpLeft.Width, 0, FbmpTop.Width, FbmpTop.Height, FbmpTop.Canvas.Handle, 0, 0, SRCCOPY); BitBlt(FBitmapDraw.Canvas.Handle, Self.ClientWidth - FbmpRight.Width, FbmpTop.Height, FbmpRight.Width, FbmpRight.Height, FbmpRight.Canvas.Handle, 0, 0, SRCCOPY); BitBlt(FBitmapDraw.Canvas.Handle, FbmpLeft.Width, Self.ClientHeight - FbmpBottom.Height, FbmpBottom.Width, FbmpBottom.Height, FbmpBottom.Canvas.Handle, 0, 0, SRCCOPY); //何かのはずみ(画面の一番下にフォームを持っていった時)で四隅が透明に抜けてしまうことへの対症療法。 //Formを部分透過させようとするとおかしな挙動になってしまうようだ。 BitBlt(FBitmapDraw.Canvas.Handle, Image_LeftTop.Left, Image_LeftTop.Top, Image_LeftTop.Width, Image_LeftTop.Height, Image_LeftTop.Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY); BitBlt(FBitmapDraw.Canvas.Handle, Image_Close.Left, Image_Close.Top, Image_Close.Width, Image_Close.Height, Image_Close.Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY); BitBlt(FBitmapDraw.Canvas.Handle, Image_RightTop.Left, Image_RightTop.Top, Image_RightTop.Width, Image_RightTop.Height, Image_RightTop.Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY); BitBlt(FBitmapDraw.Canvas.Handle, Image_RightBottom.Left, Image_RightBottom.Top, Image_RightBottom.Width, Image_RightBottom.Height, Image_RightBottom.Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY); } FGetAreaRect; end; procedure TApp_TOOLDskCaptArea.FormPaint(Sender: TObject); begin Exit; // Self.Canvas.FillRect(Self.ClientRect); BitBlt( // Self.Canvas.Handle, PaintBox1.Canvas.Handle, 0, 0, Self.ClientWidth, Self.ClientHeight, FBitmapDraw.Canvas.Handle, 0, 0, SRCCOPY ); Image_LeftTop.Show; // Image_RightTop.Show; Image_Close.Show; Image_LeftBottom.Show; Image_RightBottom.Show; end; procedure TApp_TOOLDskCaptArea.MenuItem_PFile_CloseClick(Sender: TObject); begin Close; end; procedure TApp_TOOLDskCaptArea.Image_CloseClick(Sender: TObject); begin if (IsWindow(FhMessageHandle)) then begin myMessagePanel.gpcMessagePanelUnicast('/AREA_WINDOW_CANCEL', FhMessageHandle); Hide; App_TOOLDskCaptAreaCtrl.Hide; end else begin if (App_TOOLDskCaptAreaCtrl <> nil) then begin App_TOOLDskCaptAreaCtrl.Timer_Zoom.Enabled := False; end; Close; end; end; procedure TApp_TOOLDskCaptArea.Image_MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if (Button = mbLeft) then begin gpcDragMove(Self.Handle); end else if (Button = mbRight) then begin FptMouseGesture := gfnptMousePosGet; end; end; procedure TApp_TOOLDskCaptArea.Image_MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var ls_Compas : WideString; begin if (Button = mbRight) then begin //右クリックした場所のセルを取得 //マウスジェスチャー ls_Compas := gfnsCompasGet(FptMouseGesture, gfnptMousePosGet); if (ls_Compas = '') then begin //いわゆる右クリック PopupMenu_Main.Popup(X + ClientOrigin.X, Y + ClientOrigin.Y); end else if (ls_Compas = '右') then begin //DeskCapt本体を表示 end else if (ls_Compas = '左') then begin //キャプチャコントロールを表示 MenuItem_PDisp_InfoClick(nil); end else if (ls_Compas = '上') then begin //キャプチャ Action_Capture_ExecuteExecute(nil); end else if (ls_Compas = '下') then begin //閉じる Image_CloseClick(nil); end; end; end; procedure TApp_TOOLDskCaptArea.MyMessagePanel1TextChange(Sender: TObject; Text: String); var i, k : Integer; l_Message : TMyParam; l_OptionParam : TMyParamOption; ls_Opt, ls_Value : WideString; begin { if (Application.Terminated) then begin Exit; end; } //myDebug.gpcDebug(Text); l_Message := TMyParam.Create(Text); try for i := 0 to l_Message.Count-1 do begin l_OptionParam := l_Message.OptionParam[i]; if (l_OptionParam.IsOption) then begin ls_Opt := Trim(l_OptionParam.OptionText); ls_Value := Trim(l_OptionParam.ValueText); if (ls_Opt = 'AREA_WINDOW') then begin FhMessageHandle := HWND(gfniStrToInt(ls_Value)) end else if (ls_Opt = 'CLOSE') then begin //閉じる Close; end else if (ls_Opt = 'CREATE_CTRLPANEL') then begin for k := 0 to Screen.FormCount-1 do begin if (Screen.Forms[k] is TApp_TOOLDskCaptAreaCtrl) then begin App_TOOLDskCaptAreaCtrl.BringToFront; Exit; end; end; App_TOOLDskCaptAreaCtrl := TApp_TOOLDskCaptAreaCtrl.Create(Self); FormResize(nil); App_TOOLDskCaptAreaCtrl.SetBounds( Self.BoundsRect.Left, Self.BoundsRect.Bottom, App_TOOLDskCaptAreaCtrl.Width, App_TOOLDskCaptAreaCtrl.Height ); App_TOOLDskCaptAreaCtrl.Show; end else if (ls_Opt = 'SHOW') then begin Self.Show; App_TOOLDskCaptAreaCtrl.Show; end else if (ls_Opt = 'HIDE') then begin Self.Hide; App_TOOLDskCaptAreaCtrl.Hide; end else if (ls_Opt = 'DOCAPTURE') then begin //操作パネルを隠す // App_TOOLDskCaptAreaCtrl.Hide; end else if (ls_Opt = 'CAPTURE_DONE') then begin if (MenuItem_PDisp_Info.Checked) then begin // App_TOOLDskCaptAreaCtrl.Show; end; // end else if (ls_Opt = '') then begin end; end; end; finally l_Message.Free; end; end; procedure TApp_TOOLDskCaptArea.FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); begin if (WheelDelta < 0) then begin if (ssCtrl in Shift) then begin Action_Move_LeftExecute(Action_Move_Up); end else if (ssAlt in Shift) then begin Action_Move_LeftExecute(Action_Move_Left); end else begin Action_Zoom_UpExecute(Action_Zoom_Down); end; end else begin if (ssCtrl in Shift) then begin Action_Move_LeftExecute(Action_Move_Down); end else if (ssAlt in Shift) then begin Action_Move_LeftExecute(Action_Move_Right); end else begin Action_Zoom_UpExecute(Action_Zoom_Up); end; end; end; procedure TApp_TOOLDskCaptArea.MenuItem_PDisp_InfoClick(Sender: TObject); var i : Integer; begin for i := 0 to Screen.FormCount-1 do begin if (Screen.Forms[i] is TApp_TOOLDskCaptAreaCtrl) then begin App_TOOLDskCaptAreaCtrl.Visible := MenuItem_PDisp_Info.Checked; Exit; end; end; if (MenuItem_PDisp_Info.Checked) then begin MyMessagePanel1TextChange(nil, '/CREATE_CTRLPANEL'); end; end; procedure TApp_TOOLDskCaptArea.Move(iX, iY : Integer); //Ctrl併用なら拡大 //Alt 併用なら縮小 var li_Left, li_Top, li_Width, li_Height : Integer; begin li_Left := Left; li_Top := Top; li_Width := Width; li_Height := Height; if (gfnbKeyState(VK_CONTROL)) then begin //Ctrl併用なら拡大 if (iX < 0) then begin li_Left := li_Left + iX; li_Width := li_Width - iX; //iXはマイナスなのでマイナスのマイナスでプラスになり幅は広くなる end else if (iX > 0) then begin li_Width := li_Width + iX; end; if (iY < 0) then begin li_Top := li_Top + iY; li_Height := li_Height - iY; //iYはマイナスなのでマイナスのマイナスでプラスになり高さは高くなる end else if (iY > 0) then begin li_Height := li_Height + iY; end; end else if (gfnbKeyState(VK_MENU)) then begin //Alt 併用なら縮小 if (iX < 0) then begin li_Width := li_Width + iX; //iXはマイナスなのでマイナスをプラスで幅は狭くなる end else if (iX > 0) then begin li_Left := li_Left + iX; li_Width := li_Width - iX; end; if (iY < 0) then begin li_Height := li_Height + iY; //iYはマイナスなのでマイナスをプラスで高さは低くなる end else if (iY > 0) then begin li_Top := li_Top + iY; li_Height := li_Height - iY; end; end else begin li_Left := li_Left + iX; li_Top := li_Top + iY; end; SetBounds(li_Left, li_Top, li_Width, li_Height); end; procedure TApp_TOOLDskCaptArea.Zoom(iLeft, iTop, iRight, iBottom: Integer); begin SetBounds(Left + iLeft, Top + iTop, Width + iRight, Height + iBottom); end; procedure TApp_TOOLDskCaptArea.Zoom(iZoom : Integer); begin SetBounds(Left, Top, Width + iZoom, Height + iZoom); end; procedure TApp_TOOLDskCaptArea.Action_Move_LeftExecute(Sender: TObject); var li_X, li_Y, li_Value : Integer; begin if (gfnbKeyState(VK_SHIFT)) then begin li_Value := 10; end else begin li_Value := 1; end; if (Sender = Action_Move_Left) then begin li_X := -li_Value; li_Y := 0; end else if (Sender = Action_Move_Right) then begin li_X := li_Value; li_Y := 0; end else if (Sender = Action_Move_Up) then begin li_X := 0; li_Y := -li_Value; end else if (Sender = Action_Move_Down) then begin li_X := 0; li_Y := li_Value; end else begin li_X := 0; li_Y := 0; end; if (li_X <> 0) or (li_Y <> 0) then begin Move(li_X, li_Y); end; end; procedure TApp_TOOLDskCaptArea.Action_Zoom_UpExecute(Sender: TObject); var li_Value : Integer; begin if (gfnbKeyState(VK_SHIFT)) then begin li_Value := 10; end else begin li_Value := 1; end; if (Sender = Action_Zoom_Up) then begin Zoom(li_Value); end else if (Sender = Action_Zoom_Down) then begin Zoom(-li_Value); end; end; procedure TApp_TOOLDskCaptArea.Action_Capture_ExecuteExecute(Sender: TObject); begin myMessagePanel.gpcMessagePanelUnicast('/AREA_WINDOW_CAPTUREEXECUTE', FhMessageHandle); end; procedure TApp_TOOLDskCaptArea.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin case Key of VK_LEFT :begin Action_Move_LeftExecute(Action_Move_Left); end; VK_RIGHT :begin Action_Move_LeftExecute(Action_Move_Right); end; VK_UP :begin Action_Move_LeftExecute(Action_Move_Up); end; VK_DOWN :begin Action_Move_LeftExecute(Action_Move_Down); end; VK_PRIOR :begin Action_Zoom_UpExecute(Action_Zoom_Up); end; VK_NEXT :begin Action_Zoom_UpExecute(Action_Zoom_Down); end; end; end; procedure TApp_TOOLDskCaptArea.Timer1Timer(Sender: TObject); begin if not(IsWindow(FhMessageHandle)) then begin Close; end; end; procedure TApp_TOOLDskCaptArea.FormDblClick(Sender: TObject); begin FormPaint(nil); end; end.