Solved

MM_LOMETRIC

Posted on 2002-03-29
8
925 Views
Last Modified: 2008-02-01
Hi all, I have procedure like this

procedure TForm1.Paint;
var
   // ...
begin
 inherited;

  // Some work with canvas

end;

Now I want to set canvas units to mm with

x:=SetMapMode(Canvas.handle, MM_LOMETRIC);

so, when I put this line in TForm1.Paint procedure, application stucked. Where should I do this, and how ?

Cheers,
Zeko
0
Comment
Question by:zeko
  • 5
  • 3
8 Comments
 
LVL 3

Expert Comment

by:SteveWaite
ID: 6906380
have a go with these examples..
procedure TForm1.FormPaint(Sender: TObject);
var
  OldVPOrigin, OldOrigin: TPoint
begin
  with PaintBox1.Canvas do
  begin
    SetMapMode(Handle, MM_LOMETRIC);

  //  SetViewPortOrgEx(Handle, 0, 0, @OldVPOrigin);
  //  SetWindowOrgEx(Handle, 0, 0, @OldOrigin);
  //  SetViewPortExtEx(Handle, FinalWidth, FinalHeight, @OldViewPortExtent);
  //  SetWindowExtEx(Handle, BackBuf.Width, BackBuf.Height, @OldWindowExtent);

    SetWindowExtEx(Handle, BackBuf.Width, BackBuf.Height, nil);
    SetViewPortExtEx(Handle, FinalWidth, FinalHeight, nil);

    CopyMode := cmSrcCopy;
    BitBlt(Handle, 0, 0, BackBuf.Width, BackBuf.Height, ABitmap.Canvas.Handle, 0, 0, SRCCOPY);

    //  SetViewPortOrgEx(Handle, OldVPOrigin.X, OldVPOrigin.Y, nil);
    //  SetWindowOrgEx(Handle, OldOrigin.X, OldOrigin.Y, nil);
    //  SetViewPortExtEx(Handle, OldViewPortExtent.X, OldViewPortExtent.Y, nil);
    //  SetWindowExtEx(Handle, OldWindowExtent.X, OldWindowExtent.Y, nil);
    //  Brush.Style := bsSolid;
    //  Font.Color := clYellow;
    //  TextOut(20, 20, 'hello');
  end;
end;

Regards,
Steve
0
 

Author Comment

by:zeko
ID: 6906804
I am working with form canvas not (PaintBox) and my Paint function declaration is like this:

TForm1 = class(TForm)
   procedure FormCreate(Sender: TObject);
   procedure FormDestroy(Sender: TObject);
   procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
   procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
   procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure Button1Click(Sender: TObject);
 private
   // ...
 public
   procedure Paint; override;

Sorry but I don't think that u answered this question.
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 6907919
Then just do it this way:


TForm1 = class(TForm)
  procedure FormPaint(Sender: TObject);

procedure TForm1.FormPaint(Sender: TObject);
var
  PrevMapMode: Integer;
begin
 with Canvas do // that means Form1.Canvas
 begin
   PrevMapMode := SetMapMode(Handle, MM_LOMETRIC);


Now each logical unit is mapped to 0.1 millimeter. Positive x is to the right; positive y is up.

If the function succeeds, the return value identifies the
previous mapping mode.


Steve
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 6907929
Same thing if you want to override Paint.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 3

Accepted Solution

by:
SteveWaite earned 30 total points
ID: 6907961
as in:
procedure TForm1.Paint;
var
  // ...
begin
 inherited;

  with Canvas do // that means Form1.Canvas
  begin
    SetMapMode(Handle, MM_LOMETRIC);

 // Some work with canvas

end;
0
 

Author Comment

by:zeko
ID: 6908671
Well, it's not working in override Paint, I tested it again. I've got window with canvas background same as my desktop background.
0
 

Author Comment

by:zeko
ID: 6908673
Ops, I think that I found mistake, I used DoubleBuffered := true;  in my Form.OnCreate event.

Thanks SteveWaite, here is your earned points. You made a effort to help me.
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 6908846
Thanks!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now