Solved

How to know LockWindowUpdate state for a specified control

Posted on 2014-10-02
5
473 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 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