锁定鼠标我会
var ls:Trect;//ls为鼠标运动范围
begin
...
clipcursor(@ls);//clipcursor(nil)为解锁
end;

解决方案 »

  1.   

    在WIN2000下不能单纯地用ExitWindowEX,好像要先做一些其它的什么步骤吧!因为它是NT结构,和98不同。
      

  2.   

    unit WinReboot;(* TWinReboot component (freeware)
       by Barry Brannan, September 1997
       ([email protected])
       Usage:   1. Drop TWinReboot component on a form.
       2. Call WinReboot1.WinExit(flags)   Where flags must be one of the following:   EWX_LOGOFF     - Shuts down processes and logs user off
       EWX_REBOOT     - Shuts down the restarts the system
       EWX_SHUTDOWN   - Shuts down system   The following attributes may be combined (OR'd) with above flags   EWX_POWEROFF  - shuts down system and turns off the power.
       EWX_FORCE     - forces processes to terminate.
       Example:
               WinReboot1.WinExit(EWX_REBOOT or EWX_FORCE);
    *)interfaceuses
      Windows, Classes;type
      TWinReboot = class(TComponent)
      private
        function SetPrivilege(privilegeName: string; enable: boolean): boolean;
      public
        function WinExit(flags: integer): boolean;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('Samples', [TWinReboot]);
    end;function TWinReboot.SetPrivilege(privilegeName: string; enable: boolean): boolean;
    var
      tpPrev,
      tp         : TTokenPrivileges;
      token      : THandle;
      dwRetLen   : DWord;
    begin
      result := False;  OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, token);  tp.PrivilegeCount := 1;
      if LookupPrivilegeValue(nil, pchar(privilegeName), tp.Privileges[0].LUID) then
      begin
        if enable then
          tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
        else
          tp.Privileges[0].Attributes := 0;    dwRetLen := 0;
        result := AdjustTokenPrivileges(token, False, tp, SizeOf(tpPrev), tpPrev, dwRetLen);
      end;
      CloseHandle(token);
    end;
    function TWinReboot.WinExit(flags: integer): boolean;
    begin
      Result := True;
      SetPrivilege('SeShutdownPrivilege', true);
      if not ExitWindowsEx(flags, 0) then
          Result := False;
      SetPrivilege('SeShutdownPrivilege', False);
    end;end.
      

  3.   

    jdxjf,谢谢你的答复.我不知怎么给分的.你的程序中好象用到了什么控件,电源管理的吧.
      

  4.   

    你可以不用控件,直接使用过程,代码如下:
    function SetPrivilege(privilegeName: string; enable: boolean): boolean;
    var
      tpPrev,
      tp        : TTokenPrivileges;
      token      : THandle;
      dwRetLen  : DWord;
    begin
      result := False;  OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, token);  tp.PrivilegeCount := 1;
      if LookupPrivilegeValue(nil, pchar(privilegeName), tp.Privileges[0].LUID) then
      begin
        if enable then
          tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
        else
          tp.Privileges[0].Attributes := 0;    dwRetLen := 0;
        result := AdjustTokenPrivileges(token, False, tp, SizeOf(tpPrev), tpPrev, dwRetLen);
      end;
      CloseHandle(token);
    end;
    function WinExit(flags: integer): boolean;
    begin
      Result := True;
      SetPrivilege('SeShutdownPrivilege', true);
      if not ExitWindowsEx(flags, 0) then
          Result := False;
      SetPrivilege('SeShutdownPrivilege', False);
    end;