Seite 1 von 1

(WinAPI) Frage zu ClipCursor_()

Verfasst: 07.10.2004 11:29
von nco2k
hi folks,

ich habe eine frage, warum ist die einschränkung die ich mit ClipCursor_() gesetzt habe, nach einem taskswitch (alt+tab) immernoch vorhanden und durch z.b. die windows taste nicht mehr?!

Code: Alles auswählen

#Title = "Test"
#Error = "Error"

#WinWidth = 640
#WinHeight = 480

Procedure ClientX(WindowID.l)
  ClientRect.RECT
  GetWindowRect_(WindowID, @ClientRect)
  ClientPoint.POINT
  ClientToScreen_(WindowID, @ClientPoint)
  Result = WindowX() + (ClientPoint\X - ClientRect\left)
  ProcedureReturn Result.l
EndProcedure

Procedure ClientY(WindowID.l)
  ClientRect.RECT
  GetWindowRect_(WindowID, @ClientRect)
  ClientPoint.POINT
  ClientToScreen_(WindowID, @ClientPoint)
  Result = WindowY() + (ClientPoint\Y - ClientRect\top)
  ProcedureReturn Result.l
EndProcedure

If OpenWindow(0, 0, 0, #WinWidth, #WinHeight, #PB_Window_ScreenCentered, #Title)
  AddKeyboardShortcut(0, #PB_Shortcut_Escape, 0)
EndIf

Repeat
  
  If GetForegroundWindow_() = WindowID()
    MouseRect.RECT
    MouseRect\left = ClientX(WindowID())
    MouseRect\top = ClientY(WindowID())
    MouseRect\right = ClientX(WindowID()) + WindowWidth()
    MouseRect\bottom = ClientY(WindowID()) + WindowHeight()
    ClipCursor_(MouseRect.RECT)
  EndIf
  
  EventID.l = WaitWindowEvent()
  Select EventID
    Case #PB_Event_Menu
      Select MenuID()
        Case #PB_Shortcut_Escape
          End
      EndSelect
    Case #PB_Event_CloseWindow
      End
  EndSelect
  
ForEver

End
vielen dank, für eure hilfe.

c ya,
nco2k

Verfasst: 07.10.2004 12:50
von AndyMars
Wenn Du in der API Hilfe nachliest, steht dort:

Remarks
The cursor is a shared resource. If an application confines the cursor, it must release the cursor by using ClipCursor before relinquishing control to another application.


Das heisst, Windows will, dass Du den Cursor wieder frei gibst, wenn Dein Programm den Fokus verliert... (eigentlich steht da sogar "Du musst" ;)) Wahrscheinlich gibt es Situationen, in denen Windows die Aufgabe der Begrenzung erzwingt (windows taste - aber z. B. auch, wenn Du alt+tab drückst und dann das neu fokusierte Fenster verschiebst). Jetzt kommte es drauf an, was Du willst. Ich gebe Dir mal ein Code Beispiel - hoffe es hilft Dir weiter (musst Du in Deinem Code einsetzen):

Code: Alles auswählen

  If GetForegroundWindow_() = WindowID()
    MouseRect.RECT
    MouseRect\left = ClientX(WindowID())
    MouseRect\top = ClientY(WindowID())
    MouseRect\right = ClientX(WindowID()) + WindowWidth()
    MouseRect\bottom = ClientY(WindowID()) + WindowHeight()
    ClipCursor_(MouseRect.RECT)
  Else
    ;1. Wenn die Begrenzung aufgegeben werden soll:
    ClipCursor_(#Null)
    ;2. Wenn man die Begrenzung nicht aufgeben will - nur so eine Idee
    ;SetForegroundWindow_(WindowID())
  EndIf
Verwende nur entweder 1. oder nur 2. ... (alles klar?)

Verfasst: 07.10.2004 14:02
von nco2k
@AndyMars
Vielen Dank, für die ausführliche Hilfe! Das hab ich wohl irgendwie übersehen.

c ya,
nco2k