unit sub_api; //{$DEFINE _DEBUG} interface uses my_settingfile, Windows, Messages, SysUtils, Variants, Graphics, Controls, Forms, Dialogs, ExtCtrls, Grids, ComCtrls, StdCtrls, Classes, my_apivalue; type TApp_BugsEyeAPITest = class(TForm) Panel_Top: TPanel; ComboBox_APIList: TComboBox; ListBox_Declaration: TListBox; ComboBox_TargetWindow: TComboBox; Shape_Border: TShape; StringGrid_Result: TStringGrid; Splitter1: TSplitter; Memo_Hint: TMemo; procedure FormCreate (Sender: TObject); procedure FormClose (Sender: TObject; var Action: TCloseAction); procedure FormDestroy(Sender: TObject); procedure FormResize (Sender: TObject); procedure ComboBox_APIListSelect (Sender: TObject); procedure ComboBox_APIListDropDown (Sender: TObject); procedure ListBox_DeclarationClick (Sender: TObject); procedure ListBox_DeclarationDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); procedure StringGrid_ResultSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); procedure StringGrid_ResultDrawCell (Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); procedure ComboBox_APIListDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); procedure ComboBox_TargetWindowDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); private { Private 宣言 } //メッセージレシーバー FhRichEditModule: THandle; FhMsgReceiver: HWND; FTestItems: TStrings; FAPIValue: T_MyAPIValue; procedure FValueDraw; //設定ファイル procedure FSetConfig; procedure FLoadIni; procedure WMCommand(var Msg: TWMCommand); message WM_COMMAND; procedure FSetHighDPIControlHeight; public { Public 宣言 } procedure DoAPIInfo(hWindow: HWND; ptPos: TPoint); procedure SetTextSize(AFont: TFont); property TestItems: TStrings read FTestItems; end; var App_BugsEyeAPITest: TApp_BugsEyeAPITest; implementation uses {$IFDEF _DEBUG} myDebug, {$ENDIF} CommCtrl, RichEdit, highDPIUnit, general, main, common; {$R *.dfm} const F_ciROW_TITLE = 0; F_ciCOL_TITLE = 0; F_ciCOL_VALUE = 1; F_ciCOL_HINT = 2; procedure TApp_BugsEyeAPITest.WMCommand(var Msg: TWMCommand); begin case (Msg.NotifyCode) of EN_CHANGE :begin //myDebug.gpcDebugAdd('EN_CHANGE'); end; end; inherited; end; procedure TApp_BugsEyeAPITest.FSetHighDPIControlHeight; //高DPI対応 begin gpcItemHeightSet(ComboBox_APIList); ComboBox_APIList.Items.Add('');//ダミー ComboBox_APIList.Items.Delete(ComboBox_APIList.Items.Count -1); //ComboBoxはItemHeightに値をセットした後にアイテムを追加しないと表示されるまで高さが変わらない。 //アイテムを追加してしまった後にItemHeightをセットしたのではうまくいかない。 gpcItemHeightSet(ComboBox_TargetWindow); ComboBox_TargetWindow.Items.Add('');//ダミー ComboBox_TargetWindow.Items.Delete(ComboBox_TargetWindow.Items.Count -1); gpcDefaultRowHeightSet(StringGrid_Result); gpcItemHeightSet(ListBox_Declaration); ListBox_Declaration.Height := ListBox_Declaration.ItemHeight + 2; ComboBox_APIList.Width := ComboBox_APIList.Parent.ClientWidth - (ComboBox_APIList.Left * 2); ListBox_Declaration.Width := ComboBox_APIList.Width; ListBox_Declaration.Top := ComboBox_APIList.BoundsRect.Bottom + G_ciCONTROL_MARGIN; ComboBox_TargetWindow.Top := ListBox_Declaration.BoundsRect.Bottom + G_ciCONTROL_MARGIN; Panel_Top.Height := ComboBox_TargetWindow.BoundsRect.Bottom + G_ciCONTROL_MARGIN; end; procedure TApp_BugsEyeAPITest.FormCreate(Sender: TObject); { type TAPI_Execute = function(pNowDeclaration: PWideChar; pAPIName: PWideChar; hHandle: HWND; APoint: TPoint): Integer; stdcall; TGet_MsgReceiver = procedure(hHandle: HWND); stdcall; const lcs_MODULENAME = 'Riched20.dll'; var ls_Path : WideString; lh_Module : HMODULE; l_Get_MsgReceiver : TGet_MsgReceiver; } begin (* //メッセージレシーバー作成 FhRichEditModule := LoadLibrary(lcs_MODULENAME); if (FhRichEditModule <> 0) then begin //レシーバー作成成功。 //エディットボックス FhMsgReceiver := CreateWindowW( RICHEDIT_CLASSW, //クラス名 nil, //ウィンドウテキスト WS_CHILD, //ウィンドウスタイル 0, //Left 0, //Top 0, //幅 0, //高さ Self.Handle, //親ウィンドウ $2001, //コントロールID 0, //インスタンス nil ); //最大入力文字数 SendMessageW(FhMsgReceiver, EM_EXLIMITTEXT, 0, LPARAM(-1)); //イベントマスクセット SendMessageW(FhMsgReceiver, EM_SETEVENTMASK, 0, LPARAM( ENM_CHANGE //EN_CHANGE 通知を送ります。 )); end; ls_Path := gfnsFilePathGet(gfnsExeNameGet); lh_Module := LoadLibraryW(PWideChar(ls_Path + 'message_trackbar.dll')); if (lh_Module <> 0) then begin try // Get_MsgReceiver の関数ポインタを取得 @l_Get_MsgReceiver := GetProcAddress(lh_Module, 'Get_MsgReceiver'); if (@l_Get_MsgReceiver <> nil) then begin l_Get_MsgReceiver(FhMsgReceiver); end; finally FreeLibrary(lh_Module); end; end; *) //高DPI対応 FSetHighDPIControlHeight; // StringGrid_Result.ColWidths[F_ciCOL_HINT] := 0; StringGrid_Result.Align := alClient; StringGrid_Result.Cells[F_ciCOL_TITLE, F_ciROW_TITLE] := '引数'; StringGrid_Result.Cells[F_ciCOL_VALUE, F_ciROW_TITLE] := '値'; StringGrid_Result.Cells[F_ciCOL_HINT, F_ciROW_TITLE] := '説明'; FAPIValue := T_MyAPIValue.Create; FTestItems := FAPIValue.Items; ComboBox_APIList.Items.Assign(FAPIValue.Items); FLoadIni; StringGrid_Result.ColWidths[F_ciCOL_VALUE] := (StringGrid_Result.GridWidth - StringGrid_Result.ColWidths[F_ciCOL_TITLE]) div 2; end; procedure TApp_BugsEyeAPITest.FormClose(Sender: TObject; var Action: TCloseAction); begin G_APITestCallWindow.Action_Test_APITest.Checked := False; end; procedure TApp_BugsEyeAPITest.FormDestroy(Sender: TObject); begin DestroyWindow(FhMsgReceiver); FhMsgReceiver := 0; if (FhRichEditModule <> 0) then begin FreeLibrary(FhRichEditModule); end; // FApiTestAllList.Free; FAPIValue.Free; end; procedure TApp_BugsEyeAPITest.FormResize(Sender: TObject); var li_Width : Integer; begin li_Width := StringGrid_Result.ClientWidth - StringGrid_Result.ColWidths[F_ciCOL_TITLE] - StringGrid_Result.ColWidths[F_ciCOL_VALUE]; if (goFixedVertLine in StringGrid_Result.Options) then begin li_Width := li_Width - (StringGrid_Result.GridLineWidth * 3); end; StringGrid_Result.ColWidths[F_ciCOL_HINT] := li_Width; end; procedure TApp_BugsEyeAPITest.ListBox_DeclarationClick(Sender: TObject); //var // lb_Dummy : Boolean; begin //APIの説明を表示。 // StringGrid_ResultSelectCell(nil, F_ciCOL_HINT, F_ciROW_TITLE, lb_Dummy); // Memo_Hint.Text := StringGrid_Result.Cells[F_ciCOL_HINT, F_ciROW_TITLE]; Memo_Hint.Text := FAPIValue.Description; end; procedure TApp_BugsEyeAPITest.ListBox_DeclarationDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var lrc_Rect : TRect; begin with ListBox_Declaration do begin Canvas.Font.Assign(Font); lrc_Rect := Rect; Inc(lrc_Rect.Left, G_ciTEXT_MARGIN); if (Self.ActiveControl = ListBox_Declaration) // and (GetActiveWindow = Self.Handle) then begin Canvas.Font.Color := clHighlightText; Canvas.Brush.Color := clHighlight; end else begin Canvas.Font.Color := clWindowText; Canvas.Brush.Color := clWindow; end; Canvas.FillRect(Rect); DrawText(Canvas.Handle, PChar(Items[Index]), -1, lrc_Rect, DT_NOPREFIX or DT_SINGLELINE or DT_VCENTER); end; end; procedure TApp_BugsEyeAPITest.ComboBox_APIListSelect(Sender: TObject); begin DoAPIInfo(0, Point(0, 0)); FormResize(nil); end; procedure TApp_BugsEyeAPITest.ComboBox_APIListDropDown(Sender: TObject); begin Self.ActiveControl := ComboBox_APIList; ListBox_Declaration.Refresh; end; procedure TApp_BugsEyeAPITest.ComboBox_APIListDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var lrc_Rect : TRect; l_Execute : T_Execute; begin with ComboBox_APIList do begin Canvas.Font.Assign(Font); lrc_Rect := Rect; Inc(lrc_Rect.Left, G_ciTEXT_MARGIN); if (odSelected in State) and (Self.ActiveControl = ComboBox_APIList) // and (GetForegroundWindow = Self.Handle) //myDebug.gpcDebug(Self.ActiveControl.Name); // if (Self.ActiveControl = ComboBox_APIList) // and (GetActiveWindow = Self.Handle) then begin Canvas.Font.Color := clHighlightText; Canvas.Brush.Color := clHighlight; end else begin Canvas.Font.Color := clWindowText; Canvas.Brush.Color := clWindow; // Canvas.Font.Color := clBtnText; // Canvas.Brush.Color := clBtnFace; end; Canvas.FillRect(Rect); if (Items.Objects[Index] <> nil) then begin l_Execute := T_Execute(Items.Objects[Index]); DrawText(Canvas.Handle, PChar(l_Execute.Name), -1, lrc_Rect, DT_NOPREFIX or DT_SINGLELINE or DT_VCENTER); end; end; end; procedure TApp_BugsEyeAPITest.StringGrid_ResultDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); const lci_PARAM = DT_NOPREFIX or DT_SINGLELINE or DT_VCENTER; var lrc_Rect : TRect; begin with StringGrid_Result do begin Canvas.Font.Assign(StringGrid_Result.Font); lrc_Rect := Rect; Inc(lrc_Rect.Left, G_ciTEXT_MARGIN); if (ARow = 0) then begin //タイトル Canvas.Font.Color := clBtnText; Canvas.Brush.Color := clBtnFace; Canvas.FillRect(Rect); if (Canvas.TextWidth(Cells[ACol, ARow]) > ColWidths[ACol]) then begin //タイトル文字列がセル幅より大きければ左寄せ DrawText(Canvas.Handle, PChar(Cells[ACol, ARow]), -1, lrc_Rect, DT_NOPREFIX or DT_SINGLELINE or DT_VCENTER); end else begin //タイトルはセンタリング DrawText(Canvas.Handle, PChar(Cells[ACol, ARow]), -1, lrc_Rect, DT_NOPREFIX or DT_SINGLELINE or DT_VCENTER or DT_CENTER); end; end else begin if (gdSelected in State) and (Self.ActiveControl = StringGrid_Result) then begin Canvas.Font.Color := clHighlightText; Canvas.Brush.Color := clHighlight; end else begin Canvas.Font.Color := Font.Color; //clWindowText; Canvas.Brush.Color := Color; //clWindow; end; Canvas.FillRect(Rect); DrawTextW(Canvas.Handle, PWideChar(gfnsAnsiToWideEx(Cells[ACol, ARow])), -1, lrc_Rect, lci_PARAM); // DrawTextW(Canvas.Handle, PWideChar(WideString(Cells[ACol, ARow])), -1, lrc_Rect, lci_PARAM); end; end; end; procedure TApp_BugsEyeAPITest.StringGrid_ResultSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); begin // Memo_Hint.Text := StringGrid_Result.Cells[F_ciCOL_HINT, ARow]; end; //設定ファイル ----------------------------------------------------------------- //設定読み込み。設定保存はいらない。 procedure TApp_BugsEyeAPITest.FLoadIni; begin //Shift+Ctrl起動で設定を読み込まない。 if (gfnbKeyStateAnd([VK_SHIFT, VK_CONTROL])) then begin Exit; end; FSetConfig; end; procedure TApp_BugsEyeAPITest.FSetConfig; begin if (gfniRectWidth (G_APITestInfo.rcRect) = 0) or (gfniRectHeight(G_APITestInfo.rcRect) = 0) then begin end else begin gpcSetMonitorBounds(Self, G_APITestInfo.rcRect); Memo_Hint.Height := G_APITestInfo.iHintHeight; end; if (G_APITestDiffList = nil) then begin G_APITestDiffList := TStringList.Create; end; gpcDifferenceListGet(Self.ComboBox_APIList.Items, FAPIValue.Items, G_APITestDiffList); ComboBox_APIList.ItemIndex := G_APITestInfo.iIndex; end; //------------------------------------------------------------------------------ procedure TApp_BugsEyeAPITest.FValueDraw; procedure _ClearData; //固定セル以外をクリア var i, k: Integer; begin with StringGrid_Result do begin for i := 1 to RowCount-1 do begin for k := 0 to ColCount-1 do begin Cells[k, i] := ''; end; end; end; end; procedure _ClearValue; //固定セル以外の列をクリア var i: Integer; begin with StringGrid_Result do begin for i := 1 to RowCount-1 do begin Cells[F_ciCOL_VALUE, i] := ''; end; end; end; var i: Integer; li_Row: Integer; // li_Len : Integer; li_Width : Integer; begin if (FAPIValue.IsNowAPI(ListBox_Declaration.Items[0])) then begin //直前のテストと同じ //テストの値のみを初期化 _ClearValue; //EnumWindows等で直前のテストと違う数の値があるので StringGrid_Result.RowCount := FAPIValue.Count +1; end else begin //直前のテストとは違うので表示データ全てを初期化 _ClearData; StringGrid_Result.RowCount := FAPIValue.Count +1; //表題を含めるので+1 //表題の欄外にテストする関数のヒントをセット // StringGrid_Result.Cells[F_ciCOL_HINT, F_ciROW_TITLE] := FAPIValue.Description; //関数の宣言文をセット ListBox_Declaration.Items[0] := FAPIValue.Declaration; //引数欄の幅を割り出すための変数 li_Width := 0; for i := 0 to FAPIValue.ParamCount -1 do begin li_Row := i +1; StringGrid_Result.Cells[F_ciCOL_TITLE, li_Row] := FAPIValue.Params[i]; StringGrid_Result.Cells[F_ciCOL_HINT, li_Row] := FAPIValue.Hints[i]; li_Width := gfniMax([li_Width, gfniCanvasTextWidthGet(StringGrid_Result.Font, FAPIValue.Params[i])]); end; //引数欄の幅をセットする StringGrid_Result.ColWidths[F_ciCOL_TITLE] := li_Width + (G_ciTEXT_MARGIN * 2); StringGrid_Result.Row := F_ciROW_TITLE +1; //タイトルは固定セルなのでその次にセットする。 ListBox_DeclarationClick(nil); //Hint表示 FormResize(nil); end; for i := 0 to FAPIValue.ValueCount -1 do begin li_Row := i +1; StringGrid_Result.Cells[F_ciCOL_VALUE, li_Row] := gfnsWideToAnsiEx(FAPIValue.Values[i]); end; end; //------------------------------------------------------------------------------ procedure TApp_BugsEyeAPITest.SetTextSize(AFont: TFont); begin // StringGrid_Result.Font.Assign(AFont); // StringGrid_Result.DefaultRowHeight := gfniCanvasTextHeightGet(StringGrid_Result.Font, 'A') + (G_ciTEXT_MARGIN * 2); Memo_Hint.Font.Assign(AFont); end; procedure TApp_BugsEyeAPITest.DoAPIInfo(hWindow: HWND; ptPos: TPoint); const lci_CAPTUREWINDOW = 0; lci_PARENTWINDOW = 1; lci_TOPLEVELWINDOW = 2; lci_DESKTOPWINDOW = 3; lci_INVALIDWINDOW = 4; var li_Row : Integer; lh_Target : HWND; begin case ComboBox_TargetWindow.ItemIndex of lci_PARENTWINDOW : lh_Target := gfnhParentWindowGet(hWindow); //親ウィンドウ lci_TOPLEVELWINDOW : lh_Target := gfnhToplevelWindowGet(hWindow); //トップレベルウィンドウ lci_DESKTOPWINDOW : lh_Target := GetDesktopWindow; //デスクトップウィンドウ lci_INVALIDWINDOW : lh_Target := 0; //無効なウィンドウ else lh_Target := hWindow; //ターゲットウィンドウ end; { if (ComboBox_APIList.Text = '') then begin F(lh_Target); end else } if (FAPIValue.Execute(ComboBox_APIList.Text, lh_Target, ptPos) <> -1) then begin FValueDraw; end else begin ListBox_Declaration.Items[0] := ''; StringGrid_Result.RowCount := 2; //1にしてしまうとColSizingができなくなる。 li_Row := F_ciROW_TITLE + 1; StringGrid_Result.Cells[F_ciCOL_TITLE, li_Row] := ''; StringGrid_Result.Cells[F_ciCOL_VALUE, li_Row] := ''; StringGrid_Result.Cells[F_ciCOL_HINT, li_Row] := ''; Memo_Hint.Text := ''; end; end; procedure TApp_BugsEyeAPITest.ComboBox_TargetWindowDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var lrc_Rect : TRect; begin with ComboBox_TargetWindow do begin Canvas.Font.Assign(Font); lrc_Rect := Rect; Inc(lrc_Rect.Left, G_ciTEXT_MARGIN); if (odSelected in State) and (Self.ActiveControl = ComboBox_TargetWindow) then begin Canvas.Font.Color := clHighlightText; Canvas.Brush.Color := clHighlight; end else begin Canvas.Font.Color := clWindowText; Canvas.Brush.Color := clWindow; // Canvas.Font.Color := clBtnText; // Canvas.Brush.Color := clBtnFace; end; Canvas.FillRect(Rect); DrawText(Canvas.Handle, PChar(Items[Index]), -1, lrc_Rect, DT_NOPREFIX or DT_SINGLELINE or DT_VCENTER); end; end; end.