Resource file to accept Animated Cursor

Other General Resources like icon sets, sound files etc.,

Moderator: Rathinagiri

User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: Resource file to acept Animated Cursor

Post by srvet_claudio »

Pablo César wrote: Pena que Claudio, no disponibilizó algun ejemplo en HMG utilizando esa misma funcion _bt_LoadFileFromResources.

Code: Select all

HGLOBAL __bt_LoadFileFromResources (TCHAR * FileName, TCHAR * TypeResource);

//       _LoadAnimatedCursor (FileName, TypeResource) --> Return hCursor
HB_FUNC (_LOADANIMATEDCURSOR)
{
    TCHAR   *FileName     = (TCHAR *) HMG_parc (1); 
    TCHAR   *TypeResource = (TCHAR *) HMG_parc (2);

    HCURSOR hCursor = NULL;

    HGLOBAL hGlobal = __bt_LoadFileFromResources (FileName, TypeResource);

    if (hGlobal)
    {   DWORD  nFileSize = GlobalSize (hGlobal);
        LPBYTE lpGlobalAlloc = (LPBYTE) GlobalLock (hGlobal);
        if (lpGlobalAlloc)
        {   hCursor = (HCURSOR) CreateIconFromResource  ((PBYTE)lpGlobalAlloc, nFileSize, FALSE, 0x00030000);
            
            if (hCursor == NULL && GetLastError() == ERROR_SUCCESS)
                MessageBox (NULL,_TEXT("hCursor == NULL bud The operation completed successfully ???"),_TEXT("Error"),0);
                
            GlobalUnlock (hGlobal);
        }
        GlobalFree (hGlobal);
    }
    else
       hCursor = LoadCursorFromFile (FileName);
    
    hb_retnl ((LONG) hCursor);
}
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: Resource file to acept Animated Cursor

Post by bpd2000 »

Fantastic
Thank you, Dr. Claudio
Regards
BPD
Convert Dream into Reality through HMG
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Resource file to acept Animated Cursor

Post by Pablo César »

srvet_claudio wrote:This the theory of load animated cursor from resource, but not work!!!
It's very rare error because CreateIconFromResource() return a NULL handle but GetLastError() return 0 (The operation completed successfully).
Sorry Claudio for my delayed response (I didn't see your message).

All this problem is not at loadable animated cursor whatever the code, the problem I think is on the windres.exe responsable to create object file to be assembled with exefile.

I reported at GitHub this problem thinking about hbmk2 and look this answer:
vszakats at 21 days ago wrote:Please report this problem to mingw / windres developers, or alternatively switch
to a C compiler which supports this specific case (MSVC?).

[ Note that hbmk2 doesn't by itself process the majority of input files of various formats,
but calls the appropriate external tool, in this case from the C compiler toolchain. ]
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: Resource file to acept Animated Cursor

Post by Pablo César »

bpd2000 wrote:
srvet_claudio wrote:

Code: Select all

HGLOBAL __bt_LoadFileFromResources (TCHAR * FileName, TCHAR * TypeResource);

//       _LoadAnimatedCursor (FileName, TypeResource) --> Return hCursor
HB_FUNC (_LOADANIMATEDCURSOR)
{
    TCHAR   *FileName     = (TCHAR *) HMG_parc (1); 
    TCHAR   *TypeResource = (TCHAR *) HMG_parc (2);

    HCURSOR hCursor = NULL;

    HGLOBAL hGlobal = __bt_LoadFileFromResources (FileName, TypeResource);

    if (hGlobal)
    {   DWORD  nFileSize = GlobalSize (hGlobal);
        LPBYTE lpGlobalAlloc = (LPBYTE) GlobalLock (hGlobal);
        if (lpGlobalAlloc)
        {   hCursor = (HCURSOR) CreateIconFromResource  ((PBYTE)lpGlobalAlloc, nFileSize, FALSE, 0x00030000);
            
            if (hCursor == NULL && GetLastError() == ERROR_SUCCESS)
                MessageBox (NULL,_TEXT("hCursor == NULL bud The operation completed successfully ???"),_TEXT("Error"),0);
                
            GlobalUnlock (hGlobal);
        }
        GlobalFree (hGlobal);
    }
    else
       hCursor = LoadCursorFromFile (FileName);
    
    hb_retnl ((LONG) hCursor);
}
Fantastic
Thank you, Dr. Claudio
Regards
Hi Dave, do you have run this example ? Could you post the code ?

I got previous example, but in this case does work... but I believe there other reasons.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Resource file to accept Animated Cursor

Post by Pablo César »

Hola Claudio,

Te agradezco cuando vos puedas ver este caso, que por lo que me parece le falta el retoque de un master...

En una reciente me funcionó aunque de forma limitada con el uso de 21 y ANICURSOR en el RC y lo hize através de la funcion SetWindowCursor(<ControlHandle>,<CursorName_or_IdAtRC>). Pena que lo hace para todos los componentes. Yo quisiera que solo altere el cursor de determinado control nomás, asi como lo hace la función InitHyperLinkCursor().

Comparé las dos funciones y noté que InitHyperLinkCursor tiene una SubClass.

Code: Select all

HB_FUNC( INITHYPERLINKCURSOR )
{
    HWND hwnd;
    hwnd = (HWND) HMG_parnl (1);
    HyperLinklpfnOldWndProc = (WNDPROC) SetWindowLongPtr ( hwnd , GWLP_WNDPROC, (LONG_PTR) HyperLinkSubClassFunc);
}

HB_FUNC ( SETWINDOWCURSOR )
{
    HCURSOR ch;

    if( HB_ISCHAR(2) )
    {
        ch = LoadCursor( GetModuleHandle( NULL ), HMG_parc( 2 ) ) ;

        if ( ch == NULL )
        {
            ch = LoadCursorFromFile ( HMG_parc( 2 ) ) ;
        }
    }
    else
    {
        ch = LoadCursor( NULL, MAKEINTRESOURCE( hb_parni( 2 ) ) ) ;
    }

    SetClassLongPtr ( (HWND) HMG_parnl(1),    // window handle 
        GCLP_HCURSOR,                         // change cursor 
        (LONG_PTR) ch );                      // new cursor 
}
Podrias indicarme como hacer correcto ?

Aqui dejo mi código para testear, si lo deseas:
AnimatedCursor.rar
Executable and source files
(1.24 MiB) Downloaded 256 times

Googled
Hello Claudio

For when you can see this case, that for what seems to me missing the retouching of a master ...

In a recent it worked me albeit limited with the use of 21 and ANICURSOR in the RC and I made it through the function SetWindowCursor (<ControlHandle>, <CursorName_or_IdAtRC>). The bad thing it does for all controls and I would like it to only alter the cursor of a certain control just like the InitHyperLinkCursor() function.

I compared the two functions and noticed that InitHyperLinkCursor has a SubClass.

<Source code listed above>

Could you tell me how to do it right?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: Resource file to accept Animated Cursor

Post by srvet_claudio »

Ok Pablo, lo voy a mirar
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
Post Reply