Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

LockWindowUpdate Question

Posted on 2004-08-16
5
Medium Priority
?
522 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 200 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

722 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