Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

Image on MDI parent form

I wanted do display Logo on center of MDI parent form, but when I start app, image is not visible on form. How to solve that?
0
siki
Asked:
siki
1 Solution
 
intheCommented:
hi,
this is a quite well known problem ,try
drop a TImage( with logo added ) on your mdi forms parent form and try this method to overcome the problem:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Image1: TImage;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
   FClientInstance,
   FPrevClientProc : TFarProc;
  Procedure ClientWndProc(VAR Message: TMessage);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
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;

procedure TForm1.FormCreate(Sender: TObject);
begin
 FClientInstance := MakeObjectInstance(ClientWndProc);
 FPrevClientProc := Pointer(GetWindowLong(ClientHandle,GWL_WNDPROC));
 SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FClientInstance));
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
 SetWindowLong( ClientHandle, GWL_WNDPROC, longint(FPrevClientProc));
 FreeObjectInstance( FClientInstance);
end;

end.
0
 
shenqwCommented:
var
  Bitmap:TBitmap;

procedure TMainForm.FormCreate(Sender: TObject);
begin
  Bitmap:=TBitmap.Create;
  Bitmap.LoadFromFile('c:\Yield.bmp');
  Self.Brush.Bitmap:=Bitmap;
end;

procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if Assigned(Bitmap) then FreeAndNil(Bitmap);
end;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now