Skip to content
⌘ NSIS Forum Archive

How to change cursor when it is over the definite control?

9 posts

oldfriend#

How to change cursor when it is over the definite control?

Actually this is my question.

I have an image on my custom page and it is clickable (works like a link) but nobody knows it works like thine because cursor is not changed from ARROW to HAND.

Any thoughts how to fix this?

P.S. I know about http://sourceforge.net/tracker/?func...49&atid=373088 but anyway maybe ...
oldfriend#
Using GetWindowRect and GetCursorPos I almost did what I wanted. But once again a problem))

Seems the only plug-in which could change cursor - SetCursor - doesn't change pointer over the custom control. Damn ...

Any thoughts?
oldfriend#
Seems I'm talking to myself but anyway ...

It is possible to load own cursor using LoadImage and SetSystemCursor, but hope you agree it would be stupidly as user may have his own pointers scheme.

New question)) Does anyone know how to load exactly system cursor using SetSystemCursor function?
oldfriend#
Thank you, jpderuiter.

The only question: why this macros changes cursor everywhere but not above custom control (image)?
Afrow UK#
The simple answer is, how should it know that that is what you want? In other words, to do what you want requires more code. Unfortunately, something like this is not doable from NSIS code. You will need to write a plug-in to do it or modify nsDialogs (or InstallOptions). nsDialogs and InstallOptions already change the cursor for links so it would be very similar to that.

Stu
oldfriend#
Actually there is nothing special in my code. Almost everything was given from this forum.
There is an image which should work like a link. It is dome.

The only problem is cursor changing. For this purpose logically I have to know rectangle of the image and change cursor pointer when it is out of it's area. It is done too (checked). Unfortunately, exactly above the image SetSystemCursor magically doesn't work 🙁

Function OnClick
   ExecShell "open" "http://google.com"
FunctionEnd
Function nsImgLink
   Push $0
   Push $1
   nsDialogs::Create 1018
   Pop $0
   ${NSD_CreateBitmap} 0 0 100% 100% ""
   Pop $0
   ${NSD_SetImage} $0 $PLUGINSDIR\imagefinish.bmp $1
   Push $1
   ${NSD_OnClick} $0 OnClick
   var /Global ImageHWND
   StrCpy $ImageHWND $0
   GetDlgItem $R0 $HWNDPARENT 2
   SendMessage $R0 ${WM_SETTEXT} `` `STR:&Install>>`
    System::Call "User32::SetFocus(i) i ($R0) .r0"
   SendMessage $HWNDPARENT ${WM_NEXTDLGCTL} $R0 1
   ${NSD_CreateTimer} OnTimer 500
   nsDialogs::Show
   Pop $1
   ${NSD_FreeImage} $1
   Pop $1
   Pop $0
FunctionEnd
Function Process
    System::Alloc 56
    Pop $0
    System::Call "*$0(i 56)"
    System::Call "User32::GetWindowInfo(i $ImageHWND,i r0) i .r1"
    ## rcWindow
        IntOp $R0 $0 + 4
        System::Call "*$R0(i .r1,i .r2,i .r3,i .r4)"
    ## rcClient
        IntOp $R0 $0 + 20
        System::Call "*$R0(i .r5,i .r6,i .r7,i .r8)"
        System::Free $0
    Pop $hwnd
    System::Call "*(i, i, i, i) i .r1"
    System::Call "User32::GetWindowRect(i, i) i ($ImageHWND, r1) .r2"
    System::Call "*$1(i, i, i, i) i (.r2, .r3, .r4, .r5)"
;   Get mouse cursor's position on screen
    System::Call "*(l, l) i .r6"
    System::Call "User32::GetCursorPos(i) i (r6) .r7"
    System::Call "*$6(i, i) i (.r7, .r8)"
;   Derive mouse cursor position relative to control
    IntOp $0 $7 - $2
    IntOp $1 $8 - $3
     ${If} $0 >= 0
           ${If} $0 < 450
                ${If} $1 >= 0
                      ${If} $1 < 225
                            ${SetSystemCursor} OCR_HAND
                      ${Else}
                            ${SetSystemCursor} OCR_NORMAL
                      ${EndIf}
                ${Else}
                      ${SetSystemCursor} OCR_NORMAL
                ${EndIf}
           ${Else}
                  ${SetSystemCursor} OCR_NORMAL
           ${EndIf}
     ${Else}
           ${SetSystemCursor} OCR_NORMAL
     ${EndIf}
FunctionEnd
Function OnTimer
         call Process
FunctionEnd 
oldfriend#
seems I did it 🙂

SetSystemCursor works with the parent window only and the is no way to point what window I need cursor to be changed on. So in the SetCursor.nsh manually had to change handle from the parent window to handle of my image.