Solved

MDI window drawing

Posted on 1998-04-02
9
329 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
  • 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
 
LVL 12

Author Comment

by:andrewjb
ID: 1361244
Don't give up, ronit! Your first idea helped a lot. Any more suggestions ???
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now