Solved

MDI window drawing

Posted on 1998-04-02
9
331 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…

838 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