Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/VCLX/TMouse    [ Add a report in this area ]  
Report #:  9344   Status: Closed
Mouse.GetCursorPos fails when switching Windows desktops
Project:  Delphi Build #:  4.453
Version:    7.0 Submitted By:   Sasan Adami
Report Type:  Basic functionality failure Date Reported:  10/14/2004 1:55:42 PM
Severity:    Serious / Highly visible problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   214333
Resolution: Fixed (Resolution Comments) Resolved in Build: : 12.0.3076.13956
Duplicate of:  None
Voting and Rating
Overall Rating: (2 Total Ratings)
5.00 out of 5
Total Votes: 29
Description
When Mouse.GetCursorPos is called while Windows is switching the active desktop it fails and returns:

"System error.  Code: 6. The handle is invalid"

Switching the desktop can happen when the screensaver is activated or when the computer is being locked using Ctrl+Alt+Delete.
THintWindow.ActivateHint uses Mouse.GetCursorPos to determine the mouseposition, so this can lead to the problem described.

So far I've been able to reproduce the problem only on Windows XP.
Steps to Reproduce:
- use WinXP
- create a new Delphi project
- put a timer on the form
- in the OnTimer event write:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Mouse.CursorPos;
end;

- run the application and press Ctrl+Alt+Delete
- now press Esc to return to the normal desktop
=> exception EOSError is raised
Workarounds
None
Attachment
None
Comments

Bernd Heinemann at 3/19/2008 2:47:07 AM -
WORKAROUND:

Use a local copy of Control.pas and change TMouse.GetCursorPos to:


function TMouse.GetCursorPos: TPoint;
begin
{$WARN SYMBOL_PLATFORM OFF}

// --> ORIGINAL
//  Win32Check(Windows.GetCursorPos(Result));
// <--

  if not Windows.GetCursorPos(Result) then
  begin
    if GetLastError <> 0 then
      RaiseLastOSError;
  end;

{$WARN SYMBOL_PLATFORM ON}
end;

Tristan Grimaux at 5/12/2008 7:29:21 AM -
Workaround:

function isOpenInputDesktop: boolean;
begin
  //Check if Desktop is not LOCKED!!!!
  result := OpenInputDesktop(0, false,DESKTOP_READOBJECTS) > 0;
end;


function MouseCursorPos: TPoint;
begin
{$WARN SYMBOL_PLATFORM OFF}
if not isOpenInputDesktop then
  //Handle the result as you wish...
  //in fact, your app should test this
  //before even asking for this
  Result := Point(0,0)
else
  if not Windows.GetCursorPos(Result) then begin
    if GetLastError <> 0 then
      RaiseLastOSError;
  end;
{$WARN SYMBOL_PLATFORM ON}
end;

juan cruz at 5/30/2008 10:22:24 AM -
Hello:
  this is a good solution , but i have a problem...
  when i make the changes to the file 'controls.pas' i need to rebuild vclx70.bpl. is this correct? is possible rebuild this libriry?

  thanks for your time.

  Juan Cruz

PD: anyone now if exist a solution to this bug from borland?

Server Response from: ETNACODE01