Solved

LockWindowUpdate Question

Posted on 2004-08-16
5
499 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle global variables 4 69
Magic Software info 18 132
Slow Restore if incremental backups using RDiff.exe 4 21
firemonkey Android Listview Sort items 7 16
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 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