Solved

MDI window drawing

Posted on 1998-04-02
9
326 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
Comment Utility
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
Comment Utility
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
Comment Utility
Good Luck.
0
 
LVL 12

Author Comment

by:andrewjb
Comment Utility
Don't give up, ronit! Your first idea helped a lot. Any more suggestions ???
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 5

Expert Comment

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

Expert Comment

by:StevenB
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

17 Experts available now in Live!

Get 1:1 Help Now