Solved

LockWindowUpdate Question

Posted on 2004-08-16
5
494 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

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 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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

763 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

6 Experts available now in Live!

Get 1:1 Help Now