Solved

LockWindowUpdate Question

Posted on 2004-08-16
5
510 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

628 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