Programlama yapalım ve Öğrenelim. - Delphi Eğitim160
  Ana Sayfa
  .NET Eğitim Notları
  Visual C# .NET Örnek Kodları
  VisualBasic.NET Örnek Kodları
  J# Örnekleri
  ASP.NET Örnek Kodları
  Delphi Eğitim
  => Delphi Eğitim1
  => Delphi Eğitim2
  => Delphi Eğitim3
  => Delphi Eğitim4
  => Delphi Eğitim5
  => Delphi Eğitim6
  => Delphi Eğitim7
  => Delphi Eğitim8
  => Delphi Eğitim9
  => Delphi Eğitim10
  => Delphi Eğitim11
  => Delphi Eğitim13
  => Delphi Eğitim14
  => Delphi Eğitim15
  => Delphi Eğitim16
  => Delphi Eğitim17
  => Delphi Eğitim18
  => Delphi Eğitim19
  => Delphi Eğitim20
  => Delphi Eğitim21
  => Delphi Eğitim22
  => Delphi Eğitim23
  => Delphi Eğitim24
  => Delphi Eğitim25
  => Delphi Eğitim26
  => Delphi Eğitim27
  => Delphi Eğitim28
  => Delphi Eğitim29
  => Delphi Eğitim30
  => Delphi Eğtim31
  => Delphi Eğitim32
  => Delphi Eğitim33
  => Delphi Eğitim34
  => Delphi Eğitim35
  => Delphi Eğitim36
  => Delphi Eğitim37
  => Delphi Eğitim38
  => Delphi Eğitim39
  => Delphi Eğitim40
  => Delphi Eğitim41
  => Delphi Eğitim42
  => Delphi Eğitim43
  => Delphi Eğitim44
  => Delphi Eğitim45
  => Delphi Eğitim46
  => Delphi Eğitim47
  => Delphi Eğitim48
  => Delphi Eğitim49
  => Delphi Eğitim50
  => Delphi Eğitim51
  => Delphi Eğitim52
  => Delphi Eğitim53
  => Delphi Eğitim54
  => Delphi Eğitim55
  => Delphi Eğitim56
  => Delphi Eğitim57
  => Delphi Eğitim58
  => Delphi Eğitim59
  => Delphi Eğitim60
  => Delphi Eğitim61
  => Delphi Eğitim62
  => Delphi Eğitim63
  => Delphi Eğitim64
  => Delphi Eğitim65
  => Delphi Eğitim66
  => Delphi Eğitim67
  => Delphi Eğitim68
  => Delphi Eğitim69
  => Delphi Eğitim70
  => Delphi Eğitim71
  => Delphi Eğitim72
  => Delphi Eğitim73
  => Delphi Eğitim74
  => Delphi Eğitim75
  => Delphi Eğitim76
  => Delphi Eğitim77
  => Delphi Eğitim78
  => Delphi Eğitim79
  => Delphi Eğitim80
  => Delphi Eğitim81
  => Delphi Eğitim82
  => Delphi Eğitim83
  => Delphi Eğitim84
  => Delphi Eğitim85
  => Delphi Eğitim86
  => Delphi Eğitim87
  => Delphi Eğitim88
  => Delphi Eğitim89
  => Delphi Eğitim90
  => Delphi Eğitim91
  => Delphi Eğitim92
  => Delphi Eğitim93
  => Delphi Eğitim94
  => Delphi Eğitim95
  => Delphi Eğitim96
  => Delphi Eğitim97
  => Delphi Eğitim98
  => Delphi Eğitim99
  => Delphi Eğitim100
  => Delphi Eğitim101
  => Delphi Eğitim102
  => Delphi Eğitim103
  => Delphi Eğitim104
  => Delphi Eğitim105
  => Delphi Eğitim106
  => Delphi Eğitim107
  => Delphi Eğitim108
  => Delphi Eğitim109
  => Delphi Eğitim110
  => Delphi Eğitim111
  => Delphi Eğitim112
  => Delphi Eğitim113
  => Delphi Eğitim114
  => Delphi Eğitim115
  => Delphi Eğitim116
  => Delphi Eğitim117
  => Delphi Eğitim118
  => Delphi Eğitim119
  => Delphi Eğitim120
  => Delphi Eğitim121
  => Delphi Eğitim122
  => Delphi Eğitim123
  => Delphi Eğitim124
  => Delphi Eğitim125
  => Delphi Eğitim126
  => Delphi Eğitim127
  => Delphi Eğitim128
  => Delphi Eğitim129
  => Delphi Eğitim130
  => Delphi Eğitim131
  => Delphi Eğitim132
  => Delphi Eğitim133
  => Delphi Eğitim134
  => Delphi Eğitim135
  => Delphi Eğitim136
  => Delphi Eğitim137
  => Delphi Eğitim138
  => Delphi Eğitim139
  => Delphi Eğitim140
  => Delphi Eğitim141
  => Delphi Eğitim142
  => Delphi Eğitim143
  => Delphi Eğitim144
  => Delphi Eğitim145
  => Delphi Eğitim146
  => Delphi eğitim147
  => Delphi Eğitim148
  => Delphi Eğitim149
  => Delphi Eğitim150
  => Delphi Eğitim151
  => Delphi Eğitim152
  => Delphi Eğitim153
  => Delphi Eğitim154
  => Delphi Eğitim155
  => Delphi Eğitim156
  => Delphi Eğitim157
  => Delphi Eğitim158
  => Delphi Eğitim159
  => Delphi Eğitim160
  => Delphi Eğitim161
  => Delphi Eğitim162
  => Delphi Eğitim164
  => Delphi Eğitim165
  => Delphi Eğitim166
  => Delphi Eğitim167
  => Delphi Eğitim168
  => Delphi Eğitim169
  => Delphi Eğitim170
  => Delphi Eğitim171
  => Delphi Eğitim172
  => Delphi Eğitim173
  => Delphi Eğitim174
  => Delphi Eğitim175
  => Delphi Eğitim176
  => Delphi Eğitim177
  => Delphi Eğitim178
  => Delphi Eğitim179
  => Delphi Eğitim180
  => Delphi Eğitim181
  => Delphi Eğitim182
  => Delphi Eğitim183
  => Delphi Eğitim184
  => Delphi Eğitim185
  => Delphi Eğitim186
  => Delphi Eğitim187
  => Delphi Eğitim188
  => Delphi Eğitim189
  => Delphi Eğitim190
  => Delphi Eğitim191
  => Delphi Eğitim192
  => Delphi Eğitim193
  => Delphi Eğitim194
  => Delphi Eğitim195
  => Delphi Eğitim196
  => Delphi Eğitim197
  => Delphi Eğitim198
  => Delphi Eğitim199
  => Delphi Eğitim200
  => Delphi Eğitim201
  => Delphi Eğitim202
  => Delphi Eğitim203
  => Delphi Eğitim204
  => Delphi Eğitim205
  => Delphi Eğitim206
  => Delphi Eğitim207
  => Delphi Eğitim208
  => Delphi Eğitim209
  => Delphi Eğitim210
  => Delphi Eğitim211
  => Delphi Eğitim212
  => Delphi Eğitim213
  => Delphi Eğitim214
  => Delphi Eğitim215
  => Delphi Eğitim216
  => Delphi Eğitim217
  => Delphi Eğitim218
  => Delphi Eğitim219
  => Delphi Eğitim220
  => Delphi Eğitim221
  => Delphi Eğitim222
  => Delphi Eğitim223
  => Delphi Eğitim224
  => Delphi Eğitim225
  => Delphi Eğitim226
  => Delphi Eğitim227
  => Delphi Eğitim228
  => Delphi Eğitim229
  => Delphi Eğitim230
  => Delphi Eğitim231
  => Delphi Eğitim232
  => Delphi Eğitim233
  => Delphi Eğitim234
  => Delphi Eğitim235
  => Delphi Eğitim236
  => Delphi Eğitim237
  => Delphi Eğitim238
  => Delphi Eğitim239
  => Delphi Eğitim240
  => Delphi Eğitim241
  => Delphi Eğitim242
  İletişim

neoturk: ...Make a desktop screenshot ?...

{---------------------1---------------------}

function GetScreenShot: TBitmap;

var

  Desktop: HDC;

begin

  Result  := TBitmap.Create;

  Desktop := GetDC(0);

  try

    try

      Result.PixelFormat := pf32bit;

      Result.Width := Screen.Width;

      Result.Height := Screen.Height;

      BitBlt(Result.Canvas.Handle, 0, 0, Result.Width, Result.Height, Desktop, 0, 0, SRCCOPY);

      Result.Modified := True;

    finally

      ReleaseDC(0, Desktop);

    end;

  except

    Result.Free;

    Result := nil;

  end;

end;

 

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  Image1.Picture.Bitmap := GetScreenShot;

end;

 

 

{---------------------2---------------------}

procedure TForm1.Button1Click(Sender: TObject);

var DCDesk: HDC; // hDC of Desktop

  bmp: TBitmap;

begin

  {Create a bitmap}

  bmp := TBitmap.Create;

 

  {Set a bitmap sizes}

  bmp.Height := Screen.Height;

  bmp.Width := Screen.Width;

 

  {Get a desktop DC handle - handle of a display device context}

  DCDesk := GetWindowDC(GetDesktopWindow);

 

  {Copy to any canvas, here canvas of an image}

  BitBlt(bmp.Canvas.Handle, 0, 0, Screen.Width, Screen.Height,

         DCDesk, 0, 0, SRCCOPY);

 

  {Save the bitmap}

  bmp.SaveToFile('ScreenShot.bmp');

 

  {Release desktop DC handle}

  ReleaseDC(GetDesktopWindow, DCDesk);

 

  {Release a bitmap}

  bmp.Free;

end;

 

{---------------------3---------------------}

{

  If you will try to capture the screen to bitmap using BitBlt function

  and have a layered (transparent)  window visible,

  you will get only a picture of the screen without this window.

  To fix it we have to use the new raster-operation code for BitBlt

  function CAPTUREBLT that introduced in Windows 2000 for including

  any windows that are layered on top of your window in the resulting image.

}

 

procedure CaptureScreen(AFileName: string);

const

  CAPTUREBLT = $40000000;

var

  hdcScreen: HDC;

  hdcCompatible: HDC;

  bmp: TBitmap;

  hbmScreen: HBITMAP;

begin

  // Create a normal DC and a memory DC for the entire screen. The

  // normal DC provides a "snapshot" of the screen contents. The

  // memory DC keeps a copy of this "snapshot" in the associated

  // bitmap.

 

  hdcScreen := CreateDC('DISPLAY', nil, nil, nil);

  hdcCompatible := CreateCompatibleDC(hdcScreen);

  // Create a compatible bitmap for hdcScreen.

 

  hbmScreen := CreateCompatibleBitmap(hdcScreen,

    GetDeviceCaps(hdcScreen, HORZRES),

    GetDeviceCaps(hdcScreen, VERTRES));

 

  // Select the bitmaps into the compatible DC.

  SelectObject(hdcCompatible, hbmScreen);

  bmp := TBitmap.Create;

  bmp.Handle := hbmScreen;

  BitBlt(hdcCompatible,

    0, 0,

    bmp.Width, bmp.Height,

    hdcScreen,

    0, 0,

    SRCCOPY or CAPTUREBLT);

 

  bmp.SaveToFile(AFileName);

  bmp.Free;

  DeleteDC(hdcScreen);

  DeleteDC(hdcCompatible);

end;

 

Delphi - .....................................

 

neoturk: ...Hide the caption bar ?...

procedure TForm1.HideTitlebar;

var

  Style: Longint;

begin

  if BorderStyle = bsNone then Exit;

  Style := GetWindowLong(Handle, GWL_STYLE);

  if (Style and WS_CAPTION) = WS_CAPTION then

  begin

    case BorderStyle of

      bsSingle,

      bsSizeable: SetWindowLong(Handle, GWL_STYLE, Style and

          (not (WS_CAPTION)) or WS_BORDER);

      bsDialog: SetWindowLong(Handle, GWL_STYLE, Style and

          (not (WS_CAPTION)) or DS_MODALFRAME or WS_DLGFRAME);

    end;

    Height := Height - GetSystemMetrics(SM_CYCAPTION);

    Refresh;

  end;

end;

 

procedure TForm1.ShowTitlebar;

var

  Style: Longint;

begin

  if BorderStyle = bsNone then Exit;

  Style := GetWindowLong(Handle, GWL_STYLE);

  if (Style and WS_CAPTION) <> WS_CAPTION then

  begin

    case BorderStyle of

      bsSingle,

      bsSizeable: SetWindowLong(Handle, GWL_STYLE, Style or WS_CAPTION or

          WS_BORDER);

      bsDialog: SetWindowLong(Handle, GWL_STYLE,

          Style or WS_CAPTION or DS_MODALFRAME or WS_DLGFRAME);

    end;

    Height := Height + GetSystemMetrics(SM_CYCAPTION);

    Refresh;

  end;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  HideTitlebar;

end;

 

procedure TForm1.Button2Click(Sender: TObject);

begin

  ShowTitlebar;

end;

 

Delphi - .....................................

 

neoturk: ...Hide the caption bar ?...

procedure TForm1.HideTitlebar;

var

  Style: Longint;

begin

  if BorderStyle = bsNone then Exit;

  Style := GetWindowLong(Handle, GWL_STYLE);

  if (Style and WS_CAPTION) = WS_CAPTION then

  begin

    case BorderStyle of

      bsSingle,

      bsSizeable: SetWindowLong(Handle, GWL_STYLE, Style and

          (not (WS_CAPTION)) or WS_BORDER);

      bsDialog: SetWindowLong(Handle, GWL_STYLE, Style and

          (not (WS_CAPTION)) or DS_MODALFRAME or WS_DLGFRAME);

    end;

    Height := Height - GetSystemMetrics(SM_CYCAPTION);

    Refresh;

  end;

end;

 

procedure TForm1.ShowTitlebar;

var

  Style: Longint;

begin

  if BorderStyle = bsNone then Exit;

  Style := GetWindowLong(Handle, GWL_STYLE);

  if (Style and WS_CAPTION) <> WS_CAPTION then

  begin

    case BorderStyle of

      bsSingle,

      bsSizeable: SetWindowLong(Handle, GWL_STYLE, Style or WS_CAPTION or

          WS_BORDER);

      bsDialog: SetWindowLong(Handle, GWL_STYLE,

          Style or WS_CAPTION or DS_MODALFRAME or WS_DLGFRAME);

    end;

    Height := Height + GetSystemMetrics(SM_CYCAPTION);

    Refresh;

  end;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  HideTitlebar;

end;

 

procedure TForm1.Button2Click(Sender: TObject);

begin

  ShowTitlebar;

end;

 

Delphi - .....................................

 

neoturk: ...Trap the main forms wm_move message ?...

type

  TForm1 = class(TForm)

  private

    procedure WMMove(var Msg: TWMMove); message WM_MOVE;

    { Private-Deklarationen}

  public

    { Public-Deklarationen}

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.DFM}

 

procedure TForm1.WMMove(var Msg: TWMMove);

begin

  inherited;

  ShowMessage('Form has moved!');

end;

 

end.

 

Delphi - .....................................

 

neoturk: ...Trap the main forms wm_move message ?...

type

  TForm1 = class(TForm)

  private

    procedure WMMove(var Msg: TWMMove); message WM_MOVE;

    { Private-Deklarationen}

  public

    { Public-Deklarationen}

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.DFM}

 

procedure TForm1.WMMove(var Msg: TWMMove);

begin

  inherited;

  ShowMessage('Form has moved!');

end;

 

end.

 

Delphi - .....................................

 

neoturk: ...Make a form's caption scrolling ?...

var

  a: string;

 

procedure TForm1.FormCreate(Sender: TObject);

begin

  a := 'Look at here !...';

end;

 

procedure TForm1.Timer1Timer(Sender: TObject);

var

  i: Integer;

begin

  Application.Title := a;

  Form1.Caption     := a;

  for i := 1 to (Length(a) - 1) do

    a[i] := Application.Title[i + 1];

  a[Length(a)] := Application.Title[1];

end;

 

Delphi - .....................................

 

neoturk: ...Make a form's caption scrolling ?...

var

  a: string;

 

procedure TForm1.FormCreate(Sender: TObject);

begin

  a := 'Look at here !...';

end;

 

procedure TForm1.Timer1Timer(Sender: TObject);

var

  i: Integer;

begin

  Application.Title := a;

  Form1.Caption     := a;

  for i := 1 to (Length(a) - 1) do

    a[i] := Application.Title[i + 1];

  a[Length(a)] := Application.Title[1];

end;

 

Delphi - .....................................

 

neoturk: ...Capture the screen ?...

uses

  Graphics;

 

// Capture the entire screen

// Screenshot des gesamten Bildschirms

procedure ScreenShot(Bild: TBitMap);

var

  c: TCanvas;

  r: TRect;

begin

  c := TCanvas.Create;

  c.Handle := GetWindowDC(GetDesktopWindow);

  try

    r := Rect(0, 0, Screen.Width, Screen.Height);

    Bild.Width := Screen.Width;

    Bild.Height := Screen.Height;

    Bild.Canvas.CopyRect(r, c, r);

  finally

    ReleaseDC(0, c.Handle);

    c.Free;

  end;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  Form1.Visible := False;

  Sleep(750); // some delay, ein wenig Zeit geben

  ScreenShot(Image1.Picture.BitMap);

  Form1.Visible := True;

end;

 

 

// Only active window

// Screenshot des aktiven Fensters

procedure ScreenShotActiveWindow(Bild: TBitMap);

var

  c: TCanvas;

  r, t: TRect;

  h: THandle;

begin

  c := TCanvas.Create;

  c.Handle := GetWindowDC(GetDesktopWindow);

  h := GetForeGroundWindow;

  if h <> 0 then

    GetWindowRect(h, t);

  try

    r := Rect(0, 0, t.Right - t.Left, t.Bottom - t.Top);

    Bild.Width  := t.Right - t.Left;

    Bild.Height := t.Bottom - t.Top;

    Bild.Canvas.CopyRect(r, c, t);

  finally

    ReleaseDC(0, c.Handle);

    c.Free;

  end;

end;

 

procedure TForm1.Button2Click(Sender: TObject);

begin

  Form1.Visible := False;

  Sleep(750); //some delay,ein wenig Zeit geben

  ScreenShotActiveWindow(Image1.Picture.BitMap);

  Form1.Visible := True;

end;

 

{**********************************************}

// Another print screen function by Xavier P:

// Capture the entire screen

procedure ScreenShot(x: Integer;

  y: Integer; //(x, y) = Left-top coordinate

  Width: Integer;

  Height: Integer; //(Width-Height) = Bottom-Right coordinate

  bm: TBitMap); //Destination

var

  dc: HDC;

  lpPal: PLOGPALETTE;

begin

  {test width and height}

  if ((Width = 0) or

    (Height = 0)) then

    Exit;

  bm.Width  := Width;

  bm.Height := Height;

  {get the screen dc}

  dc := GetDc(0);

  if (dc = 0) then

    Exit;

  {do we have a palette device?}

  if (GetDeviceCaps(dc, RASTERCAPS) and

    RC_PALETTE = RC_PALETTE) then

  begin

    {allocate memory for a logical palette}

    GetMem(lpPal,

      SizeOf(TLOGPALETTE) +

    (255 * SizeOf(TPALETTEENTRY)));

    {zero it out to be neat}

    FillChar(lpPal^,

      SizeOf(TLOGPALETTE) +

    (255 * SizeOf(TPALETTEENTRY)),

      #0);

    {fill in the palette version}

    lpPal^.palVersion := $300;

    {grab the system palette entries}

    lpPal^.palNumEntries :=

      GetSystemPaletteEntries(dc,

      0,

      256,

      lpPal^.palPalEntry);

    if (lpPal^.PalNumEntries <> 0) then

      {create the palette}

      bm.Palette := CreatePalette(lpPal^);

    FreeMem(lpPal, SizeOf(TLOGPALETTE) +

    (255 * SizeOf(TPALETTEENTRY)));

  end;

  {copy from the screen to the bitmap}

  BitBlt(bm.Canvas.Handle,

    0,

    0,

    Width,

    Height,

    Dc,

    x,

    y,

    SRCCOPY);

  {release the screen dc}

  ReleaseDc(0, dc);

end;

 

 

// Example:

procedure TForm1.Button1Click(Sender: TObject);

begin

 ScreenShot(0,0,Screen.Width, Screen.Height, Image1.Picture.Bitmap);

end;

 

 

{**********************************************}

// Capture a window

procedure ScreenShot(hWindow: HWND; bm: TBitmap);

var

  Left, Top, Width, Height: Word;

  R: TRect;

  dc: HDC;

  lpPal: PLOGPALETTE;

begin

  {Check if valid window handle}

  if not IsWindow(hWindow) then Exit;

  {Retrieves the rectangular coordinates of the specified window}

  GetWindowRect(hWindow, R);

  Left := R.Left;

  Top := R.Top;

  Width := R.Right - R.Left;

  Height := R.Bottom - R.Top;

  bm.Width  := Width;

  bm.Height := Height;

  {get the screen dc}

  dc := GetDc(0);

  if (dc = 0) then

  begin

    Exit;

  end;

  {do we have a palette device?}

  if (GetDeviceCaps(dc, RASTERCAPS) and

    RC_PALETTE = RC_PALETTE) then

  begin

    {allocate memory for a logical palette}

    GetMem(lpPal,

      SizeOf(TLOGPALETTE) +

    (255 * SizeOf(TPALETTEENTRY)));

    {zero it out to be neat}

    FillChar(lpPal^,

      SizeOf(TLOGPALETTE) +

    (255 * SizeOf(TPALETTEENTRY)),

      #0);

    {fill in the palette version}

    lpPal^.palVersion := $300;

    {grab the system palette entries}

    lpPal^.palNumEntries :=

      GetSystemPaletteEntries(dc,

      0,

      256,

      lpPal^.palPalEntry);

    if (lpPal^.PalNumEntries <> 0) then

    begin

      {create the palette}

      bm.Palette := CreatePalette(lpPal^);

    end;

    FreeMem(lpPal, SizeOf(TLOGPALETTE) +

    (255 * SizeOf(TPALETTEENTRY)));

  end;

  {copy from the screen to the bitmap}

  BitBlt(bm.Canvas.Handle,

    0,

    0,

    Width,

    Height,

    Dc,

    Left,

    Top,

    SRCCOPY);

  {release the screen dc}

  ReleaseDc(0, dc);

end;

// Example: Capture the foreground window:

procedure TForm1.Button1Click(Sender: TObject);

begin

  ScreenShot(GetForeGroundWindow, Image1.Picture.Bitmap);

end;

 

 

{**********************************************}

// by Daniel Wischnewski

Sometimes you want to take a screen shot,

however often Windows has trouble with big data amounts and becomes very slow.

The simple solution is to make many small screen shots and paste the result together.

It's not light speed, however often faster than taking the whole screen at once.

const

  cTileSize = 50;

function TForm1.GetSCREENSHOT: TBitmap;

var

  Locked: Boolean;

  X, Y, XS, YS: Integer;

  Canvas: TCanvas;

  R: TRect;

begin

  Result := TBitmap.Create;

  Result.Width := Screen.Width;

  Result.Height := Screen.Height;

  Canvas := TCanvas.Create;

  Canvas.Handle := GetDC(0);

  Locked := Canvas.TryLock;

  try

    XS := Pred(Screen.Width div cTileSize);

    if Screen.Width mod cTileSize > 0 then

      Inc(XS);

    YS := Pred(Screen.Height div cTileSize);

    if Screen.Height mod cTileSize > 0 then

      Inc(YS);

    for X := 0 to XS do

      for Y := 0 to YS do

      begin

        R := Rect(

          X * cTileSize, Y * cTileSize, Succ(X) * cTileSize,

          Succ(Y) * cTileSize);

        Result.Canvas.CopyRect(R, Canvas, R);

      end;

  finally

    if Locked then

      Canvas.Unlock;

    ReleaseDC(0, Canvas.Handle);

    Canvas.Free;

  end;

end;

 

Delphi - .....................................

 

neoturk: ...Capture the screen ?...

uses

  Graphics;

 

// Capture the entire screen

// Screenshot des gesamten Bildschirms

procedure ScreenShot(Bild: TBitMap);

var

  c: TCanvas;

  r: TRect;

begin

  c := TCanvas.Create;

  c.Handle := GetWindowDC(GetDesktopWindow);

  try

    r := Rect(0, 0, Screen.Width, Screen.Height);

    Bild.Width := Screen.Width;

    Bild.Height := Screen.Height;

    Bild.Canvas.CopyRect(r, c, r);

  finally

    ReleaseDC(0, c.Handle);

    c.Free;

  end;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  Form1.Visible := False;

  Sleep(750); // some delay, ein wenig Zeit geben

  ScreenShot(Image1.Picture.BitMap);

  Form1.Visible := True;

end;

 

 

// Only active window

// Screenshot des aktiven Fensters

procedure ScreenShotActiveWindow(Bild: TBitMap);

var

  c: TCanvas;

  r, t: TRect;

  h: THandle;

begin

  c := TCanvas.Create;

  c.Handle := GetWindowDC(GetDesktopWindow);

  h := GetForeGroundWindow;

  if h <> 0 then

    GetWindowRect(h, t);

  try

    r := Rect(0, 0, t.Right - t.Left, t.Bottom - t.Top);

    Bild.Width  := t.Right - t.Left;

    Bild.Height := t.Bottom - t.Top;

    Bild.Canvas.CopyRect(r, c, t);

  finally

    ReleaseDC(0, c.Handle);

    c.Free;

  end;

end;

 

procedure TForm1.Button2Click(Sender: TObject);

begin

  Form1.Visible := False;

  Sleep(750); //some delay,ein wenig Zeit geben

  ScreenShotActiveWindow(Image1.Picture.BitMap);

  Form1.Visible := True;

end;

 

{**********************************************}

// Another print screen function by Xavier P:

// Capture the entire screen

procedure ScreenShot(x: Integer;

  y: Integer; //(x, y) = Left-top coordinate

  Width: Integer;

  Height: Integer; //(Width-Height) = Bottom-Right coordinate

  bm: TBitMap); //Destination

var

  dc: HDC;

  lpPal: PLOGPALETTE;

begin

  {test width and height}

  if ((Width = 0) or

    (Height = 0)) then

    Exit;

  bm.Width  := Width;

  bm.Height := Height;

  {get the screen dc}

  dc := GetDc(0);

  if (dc = 0) then

    Exit;

  {do we have a palette device?}

  if (GetDeviceCaps(dc, RASTERCAPS) and

    RC_PALETTE = RC_PALETTE) then

  begin

    {allocate memory for a logical palette}

    GetMem(lpPal,

      SizeOf(TLOGPALETTE) +

    (255 * SizeOf(TPALETTEENTRY)));

    {zero it out to be neat}

    FillChar(lpPal^,

      SizeOf(TLOGPALETTE) +

    (255 * SizeOf(TPALETTEENTRY)),

      #0);

    {fill in the palette version}

    lpPal^.palVersion := $300;

    {grab the system palette entries}

    lpPal^.palNumEntries :=

      GetSystemPaletteEntries(dc,

      0,

      256,

      lpPal^.palPalEntry);

    if (lpPal^.PalNumEntries <> 0) then

      {create the palette}

      bm.Palette := CreatePalette(lpPal^);

    FreeMem(lpPal, SizeOf(TLOGPALETTE) +

    (255 * SizeOf(TPALETTEENTRY)));

  end;

  {copy from the screen to the bitmap}

  BitBlt(bm.Canvas.Handle,

    0,

    0,

    Width,

    Height,

    Dc,

    x,

    y,

    SRCCOPY);

  {release the screen dc}

  ReleaseDc(0, dc);

end;

 

 

// Example:

procedure TForm1.Button1Click(Sender: TObject);

begin

 ScreenShot(0,0,Screen.Width, Screen.Height, Image1.Picture.Bitmap);

end;

 

 

{**********************************************}

// Capture a window

procedure ScreenShot(hWindow: HWND; bm: TBitmap);

var

  Left, Top, Width, Height: Word;

  R: TRect;

  dc: HDC;

  lpPal: PLOGPALETTE;

begin

  {Check if valid window handle}

  if not IsWindow(hWindow) then Exit;

  {Retrieves the rectangular coordinates of the specified window}

  GetWindowRect(hWindow, R);

  Left := R.Left;

  Top := R.Top;

  Width := R.Right - R.Left;

  Height := R.Bottom - R.Top;

  bm.Width  := Width;

  bm.Height := Height;

  {get the screen dc}

  dc := GetDc(0);

  if (dc = 0) then

  begin

    Exit;

  end;

  {do we have a palette device?}

  if (GetDeviceCaps(dc, RASTERCAPS) and

    RC_PALETTE = RC_PALETTE) then

  begin

    {allocate memory for a logical palette}

    GetMem(lpPal,

      SizeOf(TLOGPALETTE) +

    (255 * SizeOf(TPALETTEENTRY)));

    {zero it out to be neat}

    FillChar(lpPal^,

      SizeOf(TLOGPALETTE) +

    (255 * SizeOf(TPALETTEENTRY)),

      #0);

    {fill in the palette version}

    lpPal^.palVersion := $300;

    {grab the system palette entries}

    lpPal^.palNumEntries :=

      GetSystemPaletteEntries(dc,

      0,

      256,

      lpPal^.palPalEntry);

    if (lpPal^.PalNumEntries <> 0) then

    begin

      {create the palette}

      bm.Palette := CreatePalette(lpPal^);

    end;

    FreeMem(lpPal, SizeOf(TLOGPALETTE) +

    (255 * SizeOf(TPALETTEENTRY)));

  end;

  {copy from the screen to the bitmap}

  BitBlt(bm.Canvas.Handle,

    0,

    0,

    Width,

    Height,

    Dc,

    Left,

    Top,

    SRCCOPY);

  {release the screen dc}

  ReleaseDc(0, dc);

end;

// Example: Capture the foreground window:

procedure TForm1.Button1Click(Sender: TObject);

begin

  ScreenShot(GetForeGroundWindow, Image1.Picture.Bitmap);

end;

 

 

{**********************************************}

// by Daniel Wischnewski

Sometimes you want to take a screen shot,

however often Windows has trouble with big data amounts and becomes very slow.

The simple solution is to make many small screen shots and paste the result together.

It's not light speed, however often faster than taking the whole screen at once.

const

  cTileSize = 50;

function TForm1.GetSCREENSHOT: TBitmap;

var

  Locked: Boolean;

  X, Y, XS, YS: Integer;

  Canvas: TCanvas;

  R: TRect;

begin

  Result := TBitmap.Create;

  Result.Width := Screen.Width;

  Result.Height := Screen.Height;

  Canvas := TCanvas.Create;

  Canvas.Handle := GetDC(0);

  Locked := Canvas.TryLock;

  try

    XS := Pred(Screen.Width div cTileSize);

    if Screen.Width mod cTileSize > 0 then

      Inc(XS);

    YS := Pred(Screen.Height div cTileSize);

    if Screen.Height mod cTileSize > 0 then

      Inc(YS);

    for X := 0 to XS do

      for Y := 0 to YS do

      begin

        R := Rect(

          X * cTileSize, Y * cTileSize, Succ(X) * cTileSize,

          Succ(Y) * cTileSize);

        Result.Canvas.CopyRect(R, Canvas, R);

      end;

  finally

    if Locked then

      Canvas.Unlock;

    ReleaseDC(0, Canvas.Handle);

    Canvas.Free;

  end;

end;

 

Delphi - .....................................

 

neoturk: ...Move components at runtime ?...

{

  This example shows how to move components at runtime, dragging it.

  You are able to see the components move as you drag them.

  Attach the Control event handlers (ControlMouseDown,...)

  to all components you want to move.

 

  Dieses Beispiel zeigt, wie man Komponenten zur Laufzeit

  verschieben kann. Während dem Verschieben werden die

  Komponenten voll angezeigt.

  An alle Komponenten, welche verschoben werden sollen,

  die Eregnisse ControlMouseDown,ControlMouseMove und

  ControlMouseUp zuweisen.

}

 

 

type

  TForm1 = class(TForm)

    Image1: TImage;

    procedure ControlMouseDown(Sender: TObject; Button: TMouseButton;

      Shift: TShiftState; X, Y: Integer);

    procedure ControlMouseMove(Sender: TObject; Shift: TShiftState; X,

      Y: Integer);

    procedure ControlMouseUp(Sender: TObject; Button: TMouseButton;

      Shift: TShiftState; X, Y: Integer);

  private

    { Private declarations }

    FDownX,

    FDownY: Integer;

    FDragging: Boolean;

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.DFM}

 

type

  TMoveCracker = class(TControl);

 

procedure TForm1.ControlMouseDown(Sender: TObject; Button: TMouseButton;

  Shift: TShiftState; X, Y: Integer);

begin

  FDownX := X;

  FDownY := Y;

  FDragging := True;

  TMoveCracker(Sender).MouseCapture := True;

end;

 

procedure TForm1.ControlMouseMove(Sender: TObject; Shift: TShiftState; X,

  Y: Integer);

begin

  if FDragging then

    with Sender as TControl do

    begin

      Left := X - FDownX + Left;

      Top  := Y - FDownY + Top;

    end;

end;

 

procedure TForm1.ControlMouseUp(Sender: TObject; Button: TMouseButton;

  Shift: TShiftState; X, Y: Integer);

begin

  if FDragging then

  begin

    FDragging := False;

    TMoveCracker(Sender).MouseCapture := False;

  end;

end;

Bu web sitesi ücretsiz olarak Bedava-Sitem.com ile oluşturulmuştur. Siz de kendi web sitenizi kurmak ister misiniz?
Ücretsiz kaydol