Solved

How to know LockWindowUpdate state for a specified control

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

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 25

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

10 Experts available now in Live!

Get 1:1 Help Now