Solved

MDI window drawing

Posted on 1998-04-02
9
334 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
Technology Partners: 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 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