Solved

How to know LockWindowUpdate state for a specified control

Posted on 2014-10-02
5
463 Views
Last Modified: 2014-10-08
Hello,
I'm using Windows.LockWindowUpdate in order to optimize control's drawing while moving and resizing.
Something like this:
LockWindowUpdate(MyPanel.Handle);
//some code here
//...
//...
LockWindowUpdate(0);

Open in new window


Sometimes I need to know if LockWindowUpdate is enabled or disabled for a specified control.
Something like "IsWindowUpdateLocked()".
How can this be done? (If it can be done..)
Thanks for your willingness.
0
Comment
Question by:ExDev001
[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
  • 2
  • 2
5 Comments
 
LVL 13

Expert Comment

by:akb
ID: 40356728
The only way I can think to do it is to define a Boolean flag to go with each control you want to know the status of and set it to true or false as you set lockwindowupdate on or off.
0
 
LVL 27

Expert Comment

by:Sinisa Vuk
ID: 40358053
According to this: http://msdn.microsoft.com/en-us/library/windows/desktop/dd145034%28v=vs.85%29.aspx
A locked window cannot be moved
Try to use Panel.DoubleBuffered:=True or Form.DoubleBuffered:=True.
0
 

Author Comment

by:ExDev001
ID: 40367702
Isn't there another way?
0
 
LVL 27

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 40369126
In description of LockWindowUpdate function stays:
Return value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero, indicating that an error occurred or another window was already locked.

... so your function IsWindowUpdateLocked should be:
function IsWindowUpdateLocked(hwd: THandle; bKeepLocked: Boolean): Boolean;
begin
  Result := (LockWindowUpdate(hwd) = 0); //try to lock and compare result
  if (not Result) and (not bKeepLocked) then LockWindowUpdate(0); //then unlock if you want
end;

Open in new window


LockWindowUpdate will return zero - so your or another window is alredy locked.
I suggest to use try ... finally ... end block:
LockWindowUpdate(hwd); //lock yours
try
   ....do something
finally
  LockWindowUpdate(0);  //always unlock
end;

Open in new window

0
 

Author Closing Comment

by:ExDev001
ID: 40370094
Hello, your informations helped me in writing IsWindowUpdateLocked function.

function IsWindowUpdateLocked() : boolean;
begin
  Result := not LockWindowUpdate(Application.Handle);
  if(not Result)
  then LockWindowUpdate(0);
end;

Consider that LockWindowUpdate fails if another window is update-locked.
Furthermore, LockWindowUpdate doesn't causes auto-update.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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