Author Topic: Set Color On a Static When Mouse is Over It  (Read 187 times)

blue_devil

  • Member
  • **
  • Posts: 112
    • SCTZine
Set Color On a Static When Mouse is Over It
« on: September 20, 2018, 03:47:59 AM »
Hello

I want my static (a.k.a label) to get colored when mouse cursor is on it. But also i want it to be a hyperlink and change the arrow cursor to "hand" cursor.
So here is my code:
I changed @gunner's code for myself:
SubClass:
Code: [Select]
ColorTheStatic proc hSTC:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL rect:RECT

.if uMsg==WM_MOUSEMOVE
    invoke  GetClientRect, hSTC, addr rect
invoke  GetCapture
;#####  Make sure the mouse is in our control
.if eax != hSTC
mov bMouseOver, TRUE
invoke  SetCapture, hSTC
.endif
mov edx,lParam
movzx eax,dx
shr edx,16
.if eax > rect.right || edx > rect.bottom
    ;#####  moved out of control
mov bMouseOver, FALSE
invoke  ReleaseCapture
.endif
invoke InvalidateRect,hSTC,NULL,TRUE
invoke UpdateWindow,hSTC
ret
.elseif uMsg==WM_LBUTTONUP
invoke InvalidateRect,hSTC,NULL,TRUE
invoke UpdateWindow,hSTC
invoke  GetWindowLong, hSTC, GWL_USERDATA
invoke  ShellExecute, hMain, offset szShellOpen, eax, NULL, NULL, SW_SHOWNORMAL
ret
.elseif uMsg==WM_SETCURSOR
invoke LoadCursor,NULL,IDC_HAND
invoke SetCursor, eax

.else
invoke CallWindowProc, lpPrevWndFunc, hSTC, uMsg, wParam, lParam
ret
.endif

xor eax, eax
ret

ColorTheStatic endp

The WindowProc:
Code: [Select]
PencereIslemi proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

mov eax,hWin
mov hMain,eax
mov eax,uMsg
.if eax==WM_INITDIALOG
invoke GetDlgItem,hWin,IDC_STCMAIL
mov hStcMail,eax
invoke  SetWindowLong, eax, GWL_USERDATA, offset SCTemail
invoke SetWindowLong,hStcMail,GWL_WNDPROC,ADDR ColorTheStatic
mov lpPrevWndFunc,eax

invoke GetDlgItem,hWin,IDC_STCLNK
mov hStcLink,eax
invoke  SetWindowLong, eax, GWL_USERDATA, offset SCTweb
invoke SetWindowLong,hStcLink,GWL_WNDPROC,ADDR ColorTheStatic
mov lpPrevWndFunc,eax

    invoke  GetSysColorBrush,COLOR_HIGHLIGHT ; COLOR_3DFACE
    mov     hBrush, eax
.elseif eax==WM_COMMAND

.elseif eax==WM_CTLCOLORSTATIC
mov     ecx, hStcMail
mov     edx, hStcLink
.if ecx == lParam || edx == lParam
.if bMouseOver
mov eax, Red
.else
    mov     eax, Blue
.endif
invoke  SetTextColor, wParam, eax
invoke  SetBkMode, wParam, TRANSPARENT
mov eax, hBrush
.endif
INVOKE GetSysColor, COLOR_BTNFACE
mov hBrush,eax
INVOKE CreateSolidBrush, hBrush
ret
       
.elseif eax==WM_CLOSE
invoke  DeleteObject, hBrush
invoke EndDialog,hWin,0
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret

PencereIslemi endp

I also Attached my source : ColorStaticOnMouseOver.zip
And two other sources which are awesome and working.

My code is also working but i have questions?
1. Gunner sends WM_SETFONT message via SendMessage API. Instead i use InvalidateRect API. Because i don't want to change fonts. Is my code OK? (Please don't say"hey if it works dont ask why  :bgrin:")
Quote
https://www.dreamincode.net/forums/topic/241669-masm-creating-a-hyperlink/
2. If you check Hyperlink source, the subclass is big and very functional. It is ok to use but i need a simpler solution.I want a lightweight code to color the static when mouse is on it and de-color when mouse is not on it. Is the code above ok for it?
Quote
http://masm32.com/board/index.php?topic=1031.msg12171#msg12171
..Dreams make the future
But the past never lies..
BlueDeviL // SCT
My Code Site:
SCTZine Assembly