Solved

How to know LockWindowUpdate state for a specified control

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 62
Base1 Encode/Decode 3 77
Dev express lookupcombo 3 30
Tidtcpserver listening on multiports? 1 28
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 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