Question

Window painting

Asked by: todsawat

How will I know window (some one on desktop) is painting or now window isn't painted ??? Please explain and I want some source code. Sorry I'm beginner in english. Please tell me if tou don't understand my question.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2000-11-27 at 09:36:07ID11988898
Topic

Delphi Programming

Participating Experts
5
Points
200
Comments
30

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Paint
    In the java.applet.Applet class, there is a method call Paint, but, when will it be called ? During the the first time the applet shown or every time it redrawn ? thanks, Andrew
  2. paint
    how do you write when you want to open paint when you click at a commandbutton

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: requiemPosted on 2000-11-27 at 10:08:31ID: 5600139

In Delphi there a a OnPaint event for each of your forms.

However, if you're talking about window which does not belong to your own application then it's going to be harder coding.



/m

 

by: edeyPosted on 2000-11-27 at 10:16:34ID: 5600401

That would be very difficult.  The only way I can think of would be to subclass the window, catch these messages (maybe more):

WM_DISPLAYCHANGE
WM_ERASEBKGND
WM_ICONERASEBKGND
WM_NCPAINT
WM_PAINT
WM_PAINTICON
WM_PRINT
WM_PRINTCLIENT
WM_SETREDRAW

pass control back to the old handlers & assume that the time inbetween the window is painting.

Perhaps there is another method, depending on what, exactly, it is you need to do.  Perhaps you could explain a little more?

GL
Mike

 

by: LischkePosted on 2000-11-27 at 12:23:23ID: 5603963

Well, if I got you right, todsawat, then you want to get notified whenever a window in the whole starts and stops painting, right? Sorry to give you a negative answer but this is alsmost impossible with Delphi. You could hook each and every window using a global hook and you would get notified about a paint action, but this would not give you a hint when painting is finished. Additionally it could become extremely difficult to create and maintain the system wide hook and to manage the various paint events, depending on what you want with the notifications.

At least for Win9x there is another option. You can create a GDI hook which records all painting actions. But this hook must be in a 16bit dll. So you see it's going very difficult.

Ciao, mike

 

by: requiemPosted on 2000-11-27 at 16:29:02ID: 5609609

So this makes it impossible to create a new "window-manager-decoration-theme" for windows, right? That sucks.



/m

 

by: todsawatPosted on 2000-11-27 at 17:03:47ID: 5610222

It haven't command to wait WM_PAINT event or check TIME_OUT of WM_PAINT Message ?? Ex. Mutex, Semophore......... (I don't understand) :-D

 

by: requiemPosted on 2000-11-27 at 18:13:32ID: 5611549

I'm sorry to say it but your English is very confusing, I don't think you can get any real help before you have learnt some more English words and grammar. No offens.


/m

 

by: todsawatPosted on 2000-11-27 at 22:03:51ID: 5616762

I'm so sorry about my confusing in english. For the last question, I want to ask what's the command to tell me when WM_PAINT is finished. I don't sure my idea is work, It's sending message WM_PAINT  to windows again and wait for respond. If windows don't process my WM_PAINT message in time, I 'll sure that windows is processing WM_PAINT message which isn't mine. For example command , mutex or Semophore or WaitForSingleObject... I'm not sure.

Thanks a lot for your answer. I really hope that it isn't confuse like the old one.

 

by: LischkePosted on 2000-11-28 at 01:12:04ID: 5620061

I think I understood you most of the time :-) For the paint: when you send a WM_PAINT message using SendMessage the call is blocked until the target window has processed the message. This way you know exactly when the paint cycle you initiated is over. But of courses it is no indication about further paint cycles cause be other applications or internally.

Ciao, Mike

 

by: todsawatPosted on 2000-11-28 at 01:31:27ID: 5620383

Lischke : Thanks a lot for your answer. But I think I also have a little confuse. Would you mind sending some source about it ?

Regards, Todsawat..

 

by: todsawatPosted on 2000-11-28 at 01:36:05ID: 5620459

Lischke : Thanks a lot for your answer. But I think I also have a little confuse. Would you mind sending some source about it ?

Regards, Todsawat..

 

by: LischkePosted on 2000-11-28 at 01:36:27ID: 5620479

No problem. What would you like to see?

 

by: todsawatPosted on 2000-11-28 at 02:08:40ID: 5621219

Please show me the sample source code about your method. And please explain to me again.

Regards, Todsawat.
                       

 

by: todsawatPosted on 2000-11-28 at 02:13:21ID: 5621399

Please show me the sample source code about your method. And please explain to me again.

Regards, Todsawat.
                       

 

by: LischkePosted on 2000-11-28 at 02:19:17ID: 5621659

todsawat, please don't use the refresh button of your browser to refresh the page as this will resend all formular data. There is a link titled "Reload Question" at the top. Use this for refreshing.

Ciao, Mike

 

by: todsawatPosted on 2000-11-28 at 02:55:30ID: 5622801

Lischke, Please show me the sample source code about your method. And please explain to me again.

Regards, Todsawat.

 

by: LischkePosted on 2000-11-28 at 03:03:49ID: 5623101

Mmh, I'm still not sure we are talking along the same lines. There is really nothing to show about the painting. But for completeness be it so:


var
  Target: HWND;

begin
  ...
  // find the window you want to have repainted
  Target := ...;
  // send the paint message and wait until the window has finished it
  // perhaps invalidating the window is necessary sometimes (depending on what you want)
  SendMessage(Target, WM_PAINT, 0, 0);
end;

Ciao, Mike

 

by: timschatPosted on 2000-11-28 at 03:43:31ID: 5624207

Hi, repainting the window is done by the main thread in response to the WM_PAINT message. In the case of a form Delphi will fire the OnPaint event. However, the form may be completely covered with contained windows (the ones from MS Windows, most likely TWinCOntrol descendands;). In the case no repainting has to be done on the form itself because repainting will be done be the contained windows. Control over repainting these windows depends on published events and subtyping. However, if you just want to ensure the windows are not updating while you do something special you have to keep in mind that message processing is done by the main thread. So if youre in the main thread and the painting methods never call the code section youre thinking of youre safe. If thats not the problem feel free to ask back,

 

by: LischkePosted on 2000-11-28 at 03:46:46ID: 5624259

May I friendly lead your attention to an important issue? Here in Experts-Exchange it is common practice to lock questions
with an answer only if you are the first expert in the thread, or if all other comments are evidently wrong. Otherwise it is
usual to post a *comment* only. This way the questioner can later easily choose which expert helped most. Additionally,
using comments only is more polite because:
 
- the question can easily be deleted if necessary
- it cannot happen that an answer is accidentally accepted
- you show that you acknowledge the work already done
- you give other experts a chance to post a better answer
 
Please, be so kind and use the option "withdraw answer" to convert your answer to a normal comment.
 
Thank you for listening...   (-:

 

by: todsawatPosted on 2000-11-28 at 04:20:01ID: 5625099

I want to ask what's the command to tell me when WM_PAINT is finished. I don't sure my idea is work, It's sending message WM_PAINT  to windows again and wait for respond. If windows don't process my WM_PAINT message in time, I 'll sure that windows is processing WM_PAINT message which isn't mine. For example command , mutex or Semophore or WaitForSingleObject... I'm not sure.


 

by: todsawatPosted on 2000-11-28 at 04:20:16ID: 5625100

I want to ask what's the command to tell me when WM_PAINT is finished. I don't sure my idea is work, It's sending message WM_PAINT  to windows again and wait for respond. If windows don't process my WM_PAINT message in time, I 'll sure that windows is processing WM_PAINT message which isn't mine. For example command , mutex or Semophore or WaitForSingleObject... I'm not sure.


 

by: timschatPosted on 2000-11-28 at 04:37:44ID: 5625465

If you want to know when WM_PAINT processing has finished you can just override it:

type
  TMyForm = class(TForm)
  protected
    procedure WMPaint(var Msg:TWMPaint); message WM_PAINT;

[...]

procedure TMyForm.WMPaint(var Msg:TWMPaint);
begin
 inherited;
 // Place your code here
end;

 

by: LischkePosted on 2000-11-28 at 04:50:21ID: 5625859

timschat, please read the entire discussion and particularly the question. We do not talk about windows in our own application (for which a solution is trivial).

todsawat, I think you don't have understood yet how the painting works. When you send the WM_PAINT message (as shown in my example) then you *don't* need a notification about whether it is finished because whenever SendMessage returns the target window has finished its painting. There is however a special version (SendMessageTimout) which waits a specific amount of time and returns a state whether the message was correctly processed or not. E.g.:

  if not SendMessageTimeout(Target, WM_PAINT, 0, 0, SMTO_BLOCK, 500) then
  // message has not been processed

But you cannot generally assume that an unprocessed paint message means the target window is currently processing another paint message. Where did you get this funny idea from? It is rather so that your paint message is placed into the message queue of your target window, regardless whether it is currently painting or not, and when it has time it will process your paint message.

Ciao, Mike

 

by: timschatPosted on 2000-11-28 at 06:05:20ID: 5627459

Hi Lischke, if you would read more carefully you could notice that todsawat asked it:
"I want to ask what's the command to tell me when WM_PAINT is finished"
Using a timeout is no correct behaviour.
Message processing must always take place within the same thread to avoid side effects. Usually this is the applications main thread. This thread will either process the WM_PAINT messages or no one does. So placing the notification in the WM_PAINT handling is both logical and correct. Your conclusions from my writings are incorrect anyway.

 

by: LischkePosted on 2000-11-28 at 06:21:38ID: 5627785

> ...if you would read more carefully
:-) *you* tell *me* to read more carefully, funny, I made most of this thread here :-D

> "I want to ask what's the command to tell me when WM_PAINT is finished"
I'm trying a while already to show that there is no command or something like that. WM_PAINT is a message which can be sent and processed. That's it.

>Using a timeout is no correct behaviour.
Have basically understood what I'm talking about?

> Message processing must always take place within the same thread to avoid side effects. Usually this is the applications main thread. This thread will either process the WM_PAINT messages or no one does.
This depends on the creator of the window which gets the WM_PAINT message. There can well be something else than the main thread which paints a window. But...., we don't talk about this as it belongs to your own application. We talk about other applications like the ddesktop, explorer, IE etc.

>Your conclusions from my writings are incorrect anyway.
Oops, did I get you so wrong? I doubt it, but if you did not meant your own application what else?

Again, we do not talk about processing of or reacting to a WM_PAINT message but to send it a know when it is done.

Ciao, Mike

 

by: todsawatPosted on 2000-11-28 at 16:46:10ID: 5640027

Lischke, You're Right. But iwhat's the command to check timeout of RedrawWindow (Function) ?? :-D

 

by: LischkePosted on 2000-11-29 at 00:36:54ID: 5646688

Mmh, never heard about such a timeout. You should keep in mind that we are talking about time slices in milliseconds (usually). Today a program is no longer accepted if it takes a couple of seconds to update its display. Even all those 3D/fractal progs do maintain backbuffers to speed up display.

With RedrawWindow it is the same as sending WM_PAINT. Once it is returned you can be assured painting has been done. This is all guarantee you will get from Windows.

Ciao, Mike

 

by: requiemPosted on 2000-11-29 at 03:28:04ID: 5649229

Hmm, isn't the difference between PostMessage() and SendMessage() that one of them is async without return value, and the other one is sync with return value? Then would we not be able to use the sync one to post WM_PAINT and then our program would not continue (resume after the proc) until the painting where actually done?

Just a thought.



/m

 

by: LischkePosted on 2000-11-29 at 04:05:43ID: 5650027

This is true, requiem. By suggesting SendMessageTimeout(Target, WM_PAINT, 0, 0, SMTO_BLOCK, 500) or SendMessage(Target, WM_PAINT, 0, 0) I wanted to show exactly this fact.

Ciao, Mike

 

by: requiemPosted on 2000-11-29 at 04:13:34ID: 5650179

Oh, I didn't read all the jabber above, sorry. But would not SendMessage() be perfectly enough then? Or, where is the problem, todsawat?


/m

 

by: rpmccormi77Posted on 2005-09-16 at 00:35:50ID: 14896062

This solution did not work for me.  My programs embeds other programs to a TWindowContainer (I made myself) and then draws alpha-transparent PNG buttons over the embedded program (by embedding I mean using SetParent() and then SetWindowPos()).  The PNG buttons are drawn by TSkinLayer (I also made my self) which needs WS_EX_TRANSPARENT set to work right.

When the embedded program redraws itself, my TSkinLayer component is not recieving a WM_PAINT command as it should (all WS_EX_TRANSPARENT controls should recieve a WM_PAINT when any window it overlaps updates, but it doesn't...  know why?).  This causes my buttons to disapear.  I was hoping to intercept the embedded windows WM_PAINT message which is how I found this thread.

I've found I can keep my buttons from disapearing by redrawing them in a timer (.repaint or .invalidate).  Problem #1: When the embedded program re-draws you see the buttons blink (off for the time between the windows repaint and the 100ms timers next inturupt).  This is a bad work-around, but it's all I have for now.  Problem #2: PNG alpha-transparancy doesn't work because it repeatedly draws the PNG makeing the semi-transparent part less & less transparent each repaint.

I thought I could use this to fix problem #2:
    SendMessage(WindowContainer.EmbeddedWindowHandle, WM_PAINT, 0, 0);
    SkinLayer.Invalidate;
but the first button repaint does not dissapear when I run the first line (I assume it is not repainting itself at all), so problem #2 still exists.  Maybe I need to send it invalidate?  Maybe I could just clear my canvas before re-painting?  Do you know how to do either or both of those?

Any other suggestions?  I'd really like to only have to repaint my buttons whenever the embeded NAV program re-draws its map (and do it immediatly so the SkinLayer PNG doesn't blink off at all).  This should happen automatically acording to the documentation on WS_EX_TRANSPARENT, but it doesn't :(.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...