![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
Получить дескриптор текущего курсораDelphi , ОС и Железо , Мышка и КурсорПолучить дескриптор текущего курсора
Оформил: DeeCo { The GetCursor() API is limited in that it does not, by default, return a handle to the current cursor when that cursor is owned by another thread. This article demonstrates a way to retrieve the current cursor regardless of what thread owns it. For example, when you wish to include the image of the cursor in a screen capture. } { Die GetCursor() API gibt das Handle auf den aktuellen Mauszeiger zurьck. Wenn Der Mauszeiger aber zu einem anderen Thread gehцrt, funktioniert die GetCursor() nicht ohne weiteres. Dieses Beispiel zeigt, wie man das Handle zum aktuellen Mauszeiger systemweit ermitteln kann, egal zu welchem Thread der Mauszeiger gehцrt. Der Code ist z.B nьtzlich, wenn man in einem "Screen Shot" den Mauszeiger zeigen mцchte. } function GetCursorHandle: HCURSOR; var hWindow: HWND; pt: TPoint; pIconInfo: TIconInfo; dwThreadID, dwCurrentThreadID: DWORD; begin // Find out which window owns the cursor // Das zum Mauszeiger zugehцrige Fenster finden GetCursorPos(pt); hWindow := WindowFromPoint(pt); // Get the thread ID for the cursor owner. // Thread ID des Fensters ermitteln dwThreadID := GetWindowThreadProcessId(hWindow, nil); // Get the thread ID for the current thread // Thread ID fьr den aktuellen Thread ermitteln dwCurrentThreadID := GetCurrentThreadId; // If the cursor owner is not us then we must attach to // the other thread in so that we can use GetCursor() to // return the correct hCursor // Wenn der Mauszeiger zu einem anderen Thread gehцrt, mьssen wir // an den anderen Thread anhдngen. if (dwCurrentThreadID <> dwThreadID) then begin if AttachThreadInput(dwCurrentThreadID, dwThreadID, True) then begin // Das Handle des Mauszeigers ermitteln // Get the handle to the cursor Result := GetCursor; AttachThreadInput(dwCurrentThreadID, dwThreadID, False); end; end else begin Result := GetCursor; end; end; procedure TForm1.Button1Click(Sender: TObject); var CurPosX, CurPoxY: Integer; MyCursor: TIcon; pIconInfo: TIconInfo; begin MyCursor := TIcon.Create; try MyCursor.Handle := GetCursorHandle; // Retrieves information about the specified cursor. // Informationen ьber den Mauszeiger auslesen GetIconInfo(MyCursor.Handle, pIconInfo); CurPosX := pIconInfo.xHotspot; CurPoxY := pIconInfo.yHotspot; // Draw the Cursor on the form // Den Mauszeiger auf die Form zeichnen Canvas.Draw(CurPoxY, CurPoxY, MyCursor); finally MyCursor.ReleaseHandle; MyCursor.Free; end; end; // Another Solution: // Andere Mцglichkeit: procedure TForm1.Timer1Timer(Sender: TObject); var CI: TCursorInfo; begin CI.cbSize := SizeOf(CI); GetCursorInfo(CI); Image1.Picture.Icon.Handle := CI.hCursor; end; Привет! Я переведу текст на русский язык. Это фрагмент кода на Delphi, демонстрирующий, как получить текущий.handle курсора, не зависящий от того, какой поток владеет им. Код использует функции Функция Еще одна реализация предоставляется в процедуре события Вот разбивка кода:
Обратите внимание, что этот код является специфичным для Delphi и может не работать в других языках программирования или средах. Рассказывается о методе получения дескриптора текущего курсора, включая способ attachments к другому потоку, если курсор принадлежит ему, для обеспечения корректной работы при получении информации об активном курсоре. Комментарии и вопросыПолучайте свежие новости и обновления по Object Pascal, Delphi и Lazarus прямо в свой смартфон. Подпишитесь на наш Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта. :: Главная :: Мышка и Курсор ::
|
||||
©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007 |