私はMM_ANISTROPIC
を使用して画像/テキストなどを拡張しようとすると、私がやったことは以下であるのですSetWindowExtExのスケーリングが間違っているのはなぜですか?
Iを(構文は少し奇妙である場合の方法によって、それはとても擬似コードとして以下扱うデルファイ出身です)次のコードでは、PaintBoxの幅の70%、高さの30%の矩形を生成することが期待されますが、そうではありません。
SetMapMode(hdc,MM_ANISOTROPIC);
SetWindowExtEx(hdc,100,100,0);
SetViewportExtEx(hdc,70,30,0);
Rectangle(hdc, 0,0,PaintBox.width-1,PaintBox.Height-1);
SetWindowExtEx
は91を持っている代わりに、そのパラメータとして100(以下に示すように)、それは全く私には意味をなさないれ、動作するように、一方で私は、コードを変更、場合...
SetMapMode(hdc,MM_ANISOTROPIC);
SetWindowExtEx(hdc,91,91,0);
SetViewportExtEx(hdc,70,30,0);
Rectangle(hdc, 0,0,PaintBox.width-1,PaintBox.Height-1);
私の正気のテストケースは、以下の擬似コード
SetMapMode(hdc,MM_TEXT);
DrawLine(hdc,Round(PaintBox.width*0.7),0,Round(PaintBox.width*0.7),PaintBox.Height-1);
DrawLine(hdc,0,Round(PaintBox.height*0.3),PaintBox.width-1,Round(PaintBox.height*0.3));
を追加することでした私は、これが私の元のRectangleの下/下端を上書きすると期待しているだろうが、それは私がない限りませんその91,91 SetWindowExtExを使用します。
誰でもこれを複製できますか?
さらに編集してください:私は擬似コードを与えてから非デルファイのユーザーにもっとアクセスしやすいようにしましたが、私のコメント作成者の一人は、それがデルファイのクールークであるという私の主張が本当かどうか。
プロジェクト全体が矩形ペイントボックスとVCLフォームから構成は、それが中心にので、すべてその周りにスペースが滴下し、そののOnPaintイベントがthis image:その結果、下のコードに設定した:
procedure TForm11.PaintBox2Paint(Sender: TObject);
var
hdc:THandle;
res:TPoint;
procedure SetupMapMode;
begin
SetMapMode(hdc,MM_ANISOTROPIC);
SetWindowExtEx(hdc,100,100,0);
SetViewportExtEx(hdc,70,30,0);
// These lines are required when we're painting to a TPaintBox but can't be used
// if we're paiting to a TPanel and they were NOT in my original question but only
// got added as part of the answer
// SetViewportOrgEx(hdc,PaintBox2.Left,PaintBox2.Top,@ZeroPoint);
// SetWindowOrgEx(hdc,0,0,@ZeroPoint);
end;
begin
//draw a rectangle to frame the Paintbox Surface
PaintBox2.Canvas.Pen.Style:=psSolid;
PaintBox2.Canvas.Pen.width:=2;
PaintBox2.Canvas.Pen.Color:=clGreen;
PaintBox2.Canvas.Brush.Style:=bsClear;
PaintBox2.Canvas.Rectangle(0,0,PaintBox2.Width-1,PaintBox2.Height-1);
PaintBox2.Canvas.Brush.Style:=bsSolid;
//initialize convenience variable
hdc:=PaintBox2.Canvas.Handle;
SetTextAlign(hdc,TA_LEFT);
//as doing things to the PaintBox2.Canvas via Delphi's interface tends to reset
//everything, I'm ensuring the map mode gets set **immediately** before
//each drawing call
SetupMapMode;
/// Draw Text at the bottom of the PaintBox2.Canvas (though as it's mapped it
/// SHOULD be 1/3 of the way down and much smaller instead)
TextOut(hdc,200,PaintBox2.Height-PaintBox2.Canvas.TextHeight('Ap'),'Hello, World!',13);
PaintBox2.Canvas.Pen.Color:=clblue;
PaintBox2.Canvas.Brush.Style:=bsClear;
//ensure it's set before doing the rectangle
SetupMapMode;
// Redraw the same rectangle as before but in the mapped mode
Rectangle(hdc, 0,0,PaintBox2.Width-1,PaintBox2.Height-1);
PaintBox2.Canvas.Brush.Style:=bsSolid;
//reset the map mode to normal
SetMapMode(hdc,MM_Text);
//draw text at the "same" position as before but unmapped...
TextOut(hdc,200,PaintBox2.Height-PaintBox2.Canvas.TextHeight('Ap'),'Goodbye, World!',15);
//Draw lines exactly at 70% of the way across and 30% of the way down
//if this works as expected they should overwrite the right and bottom
//borders of the rectangle drawn in the mapped mode
PaintBox2.Canvas.Pen.Color:=RGB(0,255,255);
PaintBox2.Canvas.MoveTo(Round(PaintBox2.Width*0.7),0);
PaintBox2.Canvas.LineTo(Round(PaintBox2.Width*0.7),PaintBox2.Height);
PaintBox2.Canvas.MoveTo(0,Round(PaintBox2.Height*0.3));
PaintBox2.Canvas.LineTo(PaintBox2.Width,Round(PaintBox2.Height*0.3));
end;
'PaintBox.Width-1、PaintBox.Height-1'の代わりに' Paintbox.Width、PaintBox.Height'が必要です。 「長方形」には、図面の下または右の座標は含まれません。 –
あなたのアプリケーションはDPI対応ではないかもしれません。参照してください[リンク](https://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx) –
Drat、私はあなたが何かになるかもしれないと思ったが、私もこれまでアプリケーションの互換性プロパティを設定して640x480モードで実行するようになりましたが、違いはありませんでした。誰でもこれを複製できますか?元の質問にテストケースを追加しました。 –