Solved

LockWindowUpdate Question

Posted on 2004-08-16
5
497 Views
Last Modified: 2010-04-05
Is there a way of finding out if a LockWindowUpdate is on or not?
and maybe to get the handle of the item locked too.

a bit like

beginwork
if intransaction then
  commitwork

sort of thing but with LockWindowUpdate instead.

Reason.....
I have a grid drawing Graphics that i use a lock on in the populate event,
but i have a frame that whilst loading i want to also lock.
but the grid load event is doing the Lock...(0)
and the frame then flickers still whilst it continues loading.
so in the grid i want to say:
if not locked then
  Lock...(grid.handle)
..
..
..
if was not locked then
  Lock...(0)

Thanks in advance
Kristian

0
Comment
Question by:Kristian
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:gwalkeriq
ID: 11817197
Well, this may be a little ugly, but if you read the LockWindowUpdate API closely, you will should see this in the Remarks section:

If an application with a locked window (or any locked child windows) calls the GetDC, GetDCEx, or BeginPaint function, the called function returns a device context with a visible region that is empty. This will occur until the application unlocks the window by calling LockWindowUpdate, specifying a value of NULL for hWndLock.

i.e., call GetDC on the other region that you may have locked, and if the device context has no visible region, that means it is locked. Have to admit I have not tried this myself.
0
 
LVL 4

Expert Comment

by:Colin_Dawson
ID: 11825528
Maybe the better approach would be to make sure that you always match LockWindowUpdate calls using a Try..Finally block.
I know this is not a way to test, but it's the way that I use it.
0
 
LVL 1

Author Comment

by:Kristian
ID: 11828194
Colin:
its not the finally thats the problem, its when you want to do a lock inside another lock.

gwalkeriq:
i havnt had a chance to check this yet (another job came up), but im hoping today, or tomorrow to get back to this and check if it works etc.
Cheers for the idea though, it looks promising.

Kristian
0
 
LVL 6

Accepted Solution

by:
gwalkeriq earned 50 total points
ID: 11830720
Of course, I'll add that what I do in this situation is create a CountedLock function that keeps a counter inside for the lock depth. Then I can use CountedLock whereever I would otherwise have use LockWindowUpdate.

e.g.,

function CountedLock(handle: HWND): boolean;
  const Depth: integer = 0;
begin
  if handle = 0 then begin
    if (Depth > 0) then begin
      dec(Depth);
      if (Depth = 0) then begin
        LockWindowUpdate(0);
      end;
    end;
  end else begin
    if (Depth = 0) then begin
      if LockWindowUpdate(handle) then Depth := 1;
    end else begin
      inc(Depth);
    end;
  end;
  result := Depth > 0;
end;

Note: I've use Depth (as an assignable typed constant) to track the value of. This is a compiler setting which is off by default in recent versions. Either change the setting or change var to a regular integer declared outside of the procedure.

Also, I just typed this in (no testing), so I might have an error in the code, but certainly you get the idea.
0
 
LVL 1

Author Comment

by:Kristian
ID: 11972470
Im sorry to say ive not had a chance to test this,
ive done some minor changes and have got around most of the flickering by better managment of process.
im also off on holiday for 4 weeks as of tommorrow so i thought i would close this thread now rather than leaving it until i get back.
anyway thankyou for your help. the code looks good, but like i said i havnt had a chance to test it.
K
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
How to convert wav to mp3 in delphi 9 169
indy Tmemory stream non latin charcter issue 2 98
Delphi IDE crash without error message ... 7 75
Dev Express grid collapse 2 39
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

914 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

19 Experts available now in Live!

Get 1:1 Help Now