Created
August 18, 2010 23:41
-
-
Save miyamuko/536552 to your computer and use it in GitHub Desktop.
カーソル情報を取得する #xyzzy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (in-package :winapi) | |
| ;; http://msdn.microsoft.com/en-us/library/ms648381(VS.85).aspx | |
| ;; packing-align を調整しないと size-of CURSORINFO が 24 になる | |
| (let ((c:*c-structure-packing-align* 4)) | |
| (c:*define-c-struct CURSORINFO | |
| (DWORD size) | |
| (DWORD flags) | |
| (HANDLE handle) | |
| (POINT pos))) | |
| ;; http://msdn.microsoft.com/ja-jp/library/cc364612.aspx | |
| (c:*define-dll-entry | |
| BOOL | |
| GetCursorInfo ((CURSORINFO *)) | |
| "user32") | |
| ;; http://msdn.microsoft.com/ja-jp/library/cc410572.aspx | |
| (c:*define-dll-entry | |
| BOOL | |
| ScreenToClient (HWND (POINT *)) | |
| "user32") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (in-package :user) | |
| (defun get-cursor-info (&key client-hwnd) | |
| (let ((info (winapi:make-CURSORINFO))) | |
| (setf (winapi:CURSORINFO-size info) | |
| (c:c-struct-size-of CURSORINFO)) | |
| (when (zerop (GetCursorInfo info)) | |
| (error "GetCursorInfo が失敗しました")) | |
| (when client-hwnd | |
| (when (zerop (winapi:ScreenToClient client-hwnd (winapi:CURSORINFO-pos info))) | |
| (error "ScreenToClient が失敗しました"))) | |
| (values (winapi:CURSORINFO-flags info) | |
| (winapi:CURSORINFO-handle info) | |
| (winapi:POINT-x (winapi:CURSORINFO-pos info)) | |
| (winapi:POINT-y (winapi:CURSORINFO-pos info))))) | |
| (defun cursor-visible-p () | |
| (multiple-value-bind (flags handle x y) | |
| (get-cursor-info) | |
| (not (zerop flags)))) | |
| (defun cursor-in-xyzzy-p () | |
| (multiple-value-bind (flags handle x y) | |
| (get-cursor-info :client-hwnd (get-window-handle)) | |
| (every #'plusp (list x y)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment