MDI Form Background

Yazdığınız makaleleri ve üyelerimizin işine yarayacağını düşündüğünüz kodlarınızı gönderebilirsiniz. Bu foruma soru sormayın!
Cevapla
mavsar

MDI Form Background

Mesaj gönderen mavsar »

MDI Formlarınızı Resim veya sabit bir renkle boyayabilirsiniz.

Sabit Renkle Boyama :
Private kısmında tanımlamanız gereken

Kod: Tümünü seç

    FClientInstance,FPrevClientProc : TFarProc;
    BkBrush: HBRUSH;
    procedure WMNCPaint(var Msg: TWMNCPaint); message WM_NCPAINT;
    procedure ClientWndProc(VAR Message: TMessage);

Kod: Tümünü seç

procedure TFNomina.ClientWndProc(var Message: TMessage);
var
  DC: HDC;
  BrushOld: HBRUSH;
begin
  with Message do
  begin
    case Msg of
      WM_ERASEBKGND:
        begin
          DC := TWMEraseBkGnd(Message).DC;
          BrushOld := SelectObject(DC, BkBrush);
          FillRect(DC, ClientRect, BkBrush);
          SelectObject(DC, BrushOld);
          Result := 1;
        end;
      else
        Result := CallWindowProc(FPrevClientProc, ClientHandle, Msg, wParam, lParam);
    end;
  end;
end;
OnCreate Event'a yazılacak olan

Kod: Tümünü seç

  inherited;
  BkBrush := CreateSolidBrush(clWhite);
  FClientInstance := MakeObjectInstance(ClientWndProc);
  FPrevClientProc := Pointer(GetWindowLong(ClientHandle,GWL_WNDPROC));
  SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FClientInstance));
Resim Yerleştirme
Private Kısmındaki tanımlama

Kod: Tümünü seç

FClientInstance, FPrevClientProc: TFarProc;
procedure ClientWndProc(var Message: TMessage);
Implementation kısmının hemen altına yazılması gereken

Kod: Tümünü seç

procedure TForm1.ClientWndProc(var Message: TMessage);
var
  MyDC: hDC;
  Ro, Co: Word;
begin
  with Message do
    case Msg of
      WM_ERASEBKGND:
      begin
        MyDC := TWMEraseBkGnd(Message).DC;
        for Ro := 0 to ClientHeight DIV Image1.Picture.Height do
          for Co := 0 to ClientWIDTH DIV Image1.Picture.Width do
            BitBlt(MyDC, Co * Image1.Picture.Width, Ro * Image1.Picture.Height, Image1.Picture.Width,
                       Image1.Picture.Height, Image1.Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY);
        Result := 1;
      end
      else
        Result := CallWindowProc(FPrevClientProc, ClientHandle, Msg, wParam, lParam);
  end;
end;
Formun OnCreate Event'ına yazılacak olan

Kod: Tümünü seç

FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FClientInstance));
Jire
Üye
Mesajlar: 167
Kayıt: 07 Eki 2007 01:20

Re: MDI Form Background

Mesaj gönderen Jire »

Teşekkürler.
Cevapla