Solved

MDI window drawing

Posted on 1998-04-02
9
332 Views
Last Modified: 2010-04-06
How do I draw an image onto the main MDI parent window in an application? If I put controls ( editboxes, labels, TImages ) etc onto the main form, only buttons, editboxes etc appear. Items like labels and images are nowhere to be seen! I've tried messing in the OnPaint event etc., but can't get it to work. ANy ideas??
0
Comment
Question by:andrewjb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1361241
I think controls that don't have handles, that is, they are not child of TWinControl are not displayed.
In D3 use TStaticText(which has handle) instead of TLabel(which doesn't have handle).
0
 
LVL 12

Author Comment

by:andrewjb
ID: 1361242
Yes, that would work, but the controls are also visible 'through' any child MDI windows you've got. I basically am trying to provide a backdrop image to go on the MDI parent form, which is visible if you've not got any MDI child forms in the way.

0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1361243
Good Luck.
0
Independent Software Vendors: 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!

 
LVL 12

Author Comment

by:andrewjb
ID: 1361244
Don't give up, ronit! Your first idea helped a lot. Any more suggestions ???
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1361245
Regarding the TImage problem perheps this will help a bit:
http://www.sherlocksoftware.com/watson/page26.html
0
 
LVL 4

Expert Comment

by:StevenB
ID: 1361246
Andrew,

  There is DEFINITELY a question hidden somewhere in the Delphi PAQ that that was the same as your question. If I remember correctly it was answered very well. If there was a search engine at EE we could find this previous example easily, however it's going to be quite a search by hand. Bear with me and I'll have a look for it for you.

  Steven.
0
 
LVL 1

Accepted Solution

by:
cmain earned 200 total points
ID: 1361247
Here is an extract of sample code that will draw in image onto the MDI main form.

Declare FPrevClientProc : TFarProc; in the form.

In Form Create.
FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));


Then

procedure TMainForm.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;
                       
                         else Result := CallWindowProc(FPrevClientProc, ClientHandle, Msg, wParam, lParam);
                     end;
    else
      Result := CallWindowProc(FPrevClientProc, ClientHandle, Msg, wParam, lParam);
    end;
end;
0
 
LVL 1

Expert Comment

by:cmain
ID: 1361248
Hi There,
I was wondering if my example helped you or not.
I realised that there was a small error in the code.
Just remove the line:
else Result := CallWindowProc....

Everything else should be find.
TLabels and other such controls will not draw correctly unless you use this method. The TLabel control does not have a window handle. It therefore does not have a window. If you use the paint event to draw the background you will draw over the controls. By using the WM_ERASEBKGND message you do not interfere with the normal painting of these controls.

Let me know what you think of my answer.
I will be happy to assist furthur if there are any outstanding problems.
Thanks
Regards
-craig.
0
 
LVL 12

Author Comment

by:andrewjb
ID: 1361249
cMain:

You also missed out a rather important SetWindowLong(...) after the Get.

The website quoted at Sherlock is basically the same as what you've said, except it talks about dealing with icon drawing too, and I don't quite understand this at the moment. D'you know what it is talking about?

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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