Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

mouse cursor in windows

22 views
Skip to first unread message

ppp5000

unread,
Dec 21, 2009, 1:45:18 AM12/21/09
to
I have a copy of the cursor xxx.cur or xxx.ani in the block of
memory, and I want to create a window cursor from either of the cursor
files from memory.

I am using CreateIconFromResourceEx() currently to try to create the
mouse cursor, but it always failed.

Can anyone share the method please? Many thanks in advance.

ppp5000

unread,
Dec 21, 2009, 2:47:34 AM12/21/09
to
here is the code i used....

DWORD size;
safe_assign( size, stream.remain_size() ); // obtain the
cursor
file size

ByteArray p;
p.resize( stream.remain_size() ); // set up the size for
storing
the cursor
stream.get_raw( p ); // get the data from
cursor

PBYTE a = (PBYTE)p.ptr(); //for debug to check the
address
of p.ptr() // it is ok here

hcursor = (HCURSOR)CreateIconFromResourceEx( (PBYTE)p.ptr(),
size,
false, 0x00030000, 0, 0, LR_SHARED|LR_DEFAULTSIZE|LR_DEFAULTCOLOR);

As i always get invalid hcursor after this call...

Christian ASTOR

unread,
Dec 21, 2009, 12:21:25 PM12/21/09
to

You must use FindResource() (RT_GROUP_CURSOR then RT_CURSOR with
LookupIconIdFromDirectoryEx()) then LoadResource() - LockResource()
before CreateIconFromResourceEx()

ppp5000

unread,
Dec 21, 2009, 10:11:25 PM12/21/09
to

> You must use FindResource() (RT_GROUP_CURSOR then RT_CURSOR with
> LookupIconIdFromDirectoryEx())  then LoadResource() - LockResource()
> before CreateIconFromResourceEx()

Thank you Christian.

I understand that the normal method is to use FindResource().... but I
don't want to include any resource file in my exe, and I only want to
load the cursor from a memory address. I am looking for another way to
achieve loading the cursor without calling these kind of functions.

That's why I passed in the parameters as followed:

CreateIconFromResourceEx( (PBYTE)p.ptr(), size, false, 0x00030000, 0,

0, LR_SHARED );

(PBYTE)p.ptr() is the address storing the cursor file.
size is the size for the cursor data.

Richard Russell

unread,
Dec 22, 2009, 4:43:32 AM12/22/09
to
On Dec 22, 3:11 am, ppp5000 <ho.p...@gmail.com> wrote:
> CreateIconFromResourceEx( (PBYTE)p.ptr(), size, false, 0x00030000, 0,
> 0, LR_SHARED );
>
> (PBYTE)p.ptr()  is the address storing the cursor file.

The pointer you supply to CreateIconFromResourceEx isn't the address
of the *file* data, but the address of an individual icon/cursor image
*within* that file (an ICO or CUR file can hold multiple images,
typically with different sizes and color depths).

If the file only contains one image, or if you're only interested in
the first one, then you can find the correct pointer value by adding
the base address of the file to the value contained at offset 18
(decimal). Similarly you can set the size to the value contained at
offset 14:

size = *(DWORD *)(file_address+14) ;
ptr = file_address + *(DWORD *)(file_address+18) ;

Richard.
http://www.rtrussell.co.uk/
To reply by email change 'news' to my forename.

0 new messages