Click here to Skip to main content
15,889,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wanted to get the current mouse cursor image in c++ or c because of the speed of execution. In my application I want to show the cursor in an applet. so I want to get the image as an buffered image. I found that we can get the image as bit map data. but can't figure out how it can do it because of lack of documentation. can you help me to find me a good tutorial to understand how I get the cursor image?
Posted
Updated 12-Jul-12 21:47pm
v2

GetCursor function of Win API
The return value is the handle to the current cursor. If there is no cursor, the return value is NULL.

Please see here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms648388%28v=vs.85%29.aspx[^]
 
Share this answer
 
Comments
lakshman udayakantha 13-Jul-12 14:53pm    
this function returns a handle to the cursor. but handle can do nothing other than passing to a function. what is the function that returns the cursor image as buffered image. should I write my own function to return the cursor? thanks all for your information.
Volynsky Alex 14-Jul-12 3:54am    
Ouch, that seems to be more complicated than I thought - see http://msdn.microsoft.com/msdnmag/issues/01/10/Cursor/default.aspx ("Win32 Resources: Using C++ to Pro-grammatically Retrieve a Global Cursor's Shape and ID") and http://delphi.cjcsoft.net/viewthread.php?tid=42851 , http://www.autoitscript.com/forum/topic/18981-capturing-the-mouse-cursor/ ,
http://www.luigibianchi.com/code/cursor_shape.htm :

HCURSOR GetCurrentCursorHandle()
{
POINT pt;
HWND hWnd;
DWORD dwThreadID, dwCurrentThreadID;
HCURSOR hCursor = NULL;

// Find out which window owns the cursor
GetCursorPos(&pt);
hWnd = WindowFromPoint(pt);

// Get the thread ID for the cursor owner.
dwThreadID = GetWindowThreadProcessId(hWnd, NULL);

// Get the thread ID for the current thread
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
if (dwCurrentThreadID != dwThreadID) {

// Attach to the thread that owns the cursor
if (AttachThreadInput(dwCurrentThreadID, dwThreadID, TRUE)) {

// Get the handle to the cursor
hCursor = GetCursor();

// Detach from the thread that owns the cursor
AttachThreadInput(dwCurrentThreadID, dwThreadID, FALSE);
}
} else
hCursor = GetCursor();

return hCursor;
}

If you do your work on C++/Qt it will help you:
C++ GUI Programming With Qt 4
http://books.google.ru/books?id=tSCR_4LH2KsC&pg=PA407&dq=C%2B%2B+cursor+bitmap&hl=ru&sa=X&ei=nB8BUOO7Lei90QXSz52sCw&ved=0CEMQ6AEwBDgU#v=onepage&q=C%2B%2B%20cursor%20bitmap&f=false

Good luck
lakshman udayakantha 17-Jul-12 7:31am    
thanks for your information Volynsky Alex..:)
Volynsky Alex 17-Jul-12 16:00pm    
You're welcome lakshman udayakantha :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900