Solved

How to know LockWindowUpdate state for a specified control

Posted on 2014-10-02
5
413 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
  • 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 26

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 26

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IExtractImage Delphi 14 201
my delphi exe application have  problem with windows explorer ! 12 80
Delphi : could not find program, '...exe' 2 147
Create a path if not exists 7 69
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

16 Experts available now in Live!

Get 1:1 Help Now