We help IT Professionals succeed at work.

screen

kevinward66
kevinward66 asked
on
Medium Priority
226 Views
Last Modified: 2010-04-06
how can i flip the screen vertically, horizontally and return it back to normal?
Comment
Watch Question

Commented:
unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
 ExtCtrls, jpeg;

type
 TForm1 = class(TForm)
   Image1: TImage;
    Image2: TImage;
   procedure FormShow(Sender: TObject);
   procedure FormCreate(Sender: TObject);
   procedure Image1Click(Sender: TObject);
 private
   { Private declarations }
 public
   can:Tcanvas;
   { Public declarations }
 end;

var
 Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormShow(Sender: TObject);
var
       y:integer;
begin
       y:=0;
       for y:=0 to can.ClipRect.bottom do
       begin
               image1.Canvas.CopyRect(rect(0,y-1,can.ClipRect.Right,y),can,rect(0,can.ClipRect.bottom-y+1,can.ClipRect.Right,can.ClipRect.bottom-y));
       end;
       with(image1)do
       for y:=0 to Canvas.ClipRect.Right do
       begin
               image2.Canvas.CopyRect(rect(Can.ClipRect.Right-y-1,0,Can.ClipRect.Right-y,Can.ClipRect.bottom),image1.picture.Bitmap.Canvas,rect(y,0,y+1,Can.ClipRect.bottom));
       end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
       borderstyle:=bsnone;
       formstyle:=fsstayontop;
       image1.Align:=alclient;
       image2.Align:=alclient;
       left:=0;
       top:=0;
       height:=screen.height;
       width:=screen.width;
       can:=Tcanvas.create;
       can.handle:=getdc(0);
end;

procedure TForm1.Image2Click(Sender: TObject);
begin
       close;
end;

end.

Author

Commented:
this is EXCELLENT, but PLEASE let me explain more, i am sorry, i should have given you more detail at the start of the question

this is what i would ideally like, if its possible!


button 1 = flip screen horizontally
button 2 = flip screen vertically
button 3 = return screen to normal

ONCE AGAIN I AM SORRY, FOR NOT GIVING MORE DETAIL AT THE START!!! :-(

Commented:
you can not use button after you flip the screen but only to click on a mouse.

Author

Commented:
ok, well can you provide the code that flips the screen BOTH horizontally & vertically

as the current code only flips it one way

Commented:
you can not use button after you flip the screen but only to click on a mouse.

Commented:
verticaly and hor
look at the start button there it is it should be in upper right corner

Commented:
i meant my code already flips the screen vertically and horizontally

Commented:
if it works give me the points

Commented:
hello kevinward66 , , your question and explanation are not clear to me, you ask to flip the screen in your question and then you say
button 1 = flip screen horizontally
button 2 = flip screen vertically
button 3 = return screen to normal

but you don't say what buttons you are refering to. .  you can flip an Image of the screen but it is Only an Image, it is NOT a working Desktop screen where you can click the flipped program's buttons and have them work, however you could use the onClick event to do all the flips and then close the app. Here is some code for that

unit Flip1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormClick(Sender: TObject);
  private
    { Private declarations }
    FlipNum: Byte;
    Rect1: TRect;
    ScreenBmp: TBitmap;
    procedure WMEraseBkgnd (var Msg : TMessage); message WM_ERASEBKGND;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  FlipNum := 0;
  Top := 0;
  Left := 0;
  Width := Screen.Width;
  Height := Screen.Height;
  BorderStyle := bsNone;
  Rect1 := Rect(0,0,Width,Height);
  ScreenBmp := TBitmap.Create;
  ScreenBmp.Width := Width;
  ScreenBmp.Height := Height;
end;

procedure TForm1.FormClick(Sender: TObject);
begin
{each click of the screen increases FlipNum
and flips the screen and then Closes the app}
case FlipNum of
0: begin
{I use BitBlt because it is faster but you can use CopyRect}
   BitBlt(ScreenBmp.Canvas.Handle, 0, 0, Width, Height,
      Form1.Canvas.Handle, 0, 0, SRCCOPY);
   Canvas.CopyRect(rect(0,Height,Width,0),ScreenBmp.Canvas,rect1);
   Inc(FlipNum);
   end;
1: begin
   Canvas.CopyRect(rect(Width,0,0,Height),ScreenBmp.Canvas,rect1);
   Inc(FlipNum);
   end;
2: begin
   Canvas.CopyRect(rect1,ScreenBmp.Canvas,rect1);
   Inc(FlipNum);;
   end;
3: Close;
else Close;
end;

end;

procedure TForm1.WMEraseBkGnd;
begin
{this prevents this app from erasing the screen}
  Msg.Result := 0;
end;

end.

 - - - - - - - - - - - - - - - - - - - - - - - -

if you want to use buttons, I can also do that with a timer, let me know.

Commented:
Oh, I forgot to add this

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FreeAndNil(ScreenBmp);
end;

Author

Commented:
i will try this and get back to you, thanks for your help

Author

Commented:
this code is EXCELLENT, but instead of clicking on the screen each time to get the screen to move to the different positions, can you put each screen movement into a button click procedure.

thanks, SORRY to mess u around!!! :-(

Commented:
what are you asking for ? you say -
can you put each screen movement into a button click procedure?

maybe you're real inexperienced at this, it seems the procedures are very simple (only ONE line of code) for the CopyRect to flip the image. . . .  is this what you are asking for

procedure TForm1.Button1Click(Sender: TObject);
begin
Canvas.CopyRect(rect(Width,0,0,Height), ScreenBmp.Canvas, rect1);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Canvas.CopyRect(rect(0,Height,Width,0), ScreenBmp.Canvas, rect1);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
{back to normal look}
Canvas.CopyRect(rect1,ScreenBmp.Canvas,rect1);
end;


 Of course you will have to capture the ScreenBmp Image before you can use it.

maybe if you could give some explanation as to the use or purpose of these screen flips I could help you,

Commented:
Listening...

Explore More ContentExplore courses, solutions, and other research materials related to this topic.