Page 1 of 3

mouseover label

Posted: Fri Jun 08, 2018 4:07 pm
by koke
Buenos días.
¿Alguien a implementado el efecto mouseover para un label?

Vi un post donde se discutió en el 2009

http://hmgforum.com/viewtopic.php?f=5&t ... over#p7043

Pero no funciona bien en 3.4.3 y no pude encontrar ningún otro ejemplo.

Saludos.

traducido por google

Good Morning.
Has anyone implemented the mouseover effect for a label?

I saw a post where it was discussed in 2009

[url] http://hmgforum.com/viewtopic.php?f=5&t ... over#p7043 [/ url]

But it doesn´t work well on 3.4.3 and I could not find any other example.

Greetings.

Re: mouseover label

Posted: Fri Jun 08, 2018 6:56 pm
by mol
Fee years ago I've posted sample with mouseover effect.

Re: mouseover label

Posted: Fri Jun 08, 2018 8:56 pm
by andyglezl

Re: mouseover label

Posted: Sat Jun 09, 2018 8:09 pm
by KDJ
Can somebody know why WM_MOUSELEAVE message is not generated for LABEL and another controls?

Example of code:

Code: Select all

#include "hmg.ch"

MEMVAR _HMG_SYSDATA

FUNCTION Main()

  DEFINE WINDOW MainForm;
    WIDTH  300;
    HEIGHT 200;
    MAIN

    DEFINE LABEL Label1
      ROW       10
      COL       10
      WIDTH     140
      HEIGHT    45
      VALUE     "This is LABEL"
      ALIGNMENT Center
    END LABEL

    DEFINE BUTTON CloseButton
      ROW     70
      COL     10
      WIDTH   80
      HEIGHT  23
      CAPTION "Close"
      ACTION  MainForm.RELEASE
    END BUTTON

  END WINDOW

  HMG_ChangeWindowStyle(MainForm.Label1.HANDLE, 0x00800200 /*WS_BORDER|SS_CENTERIMAGE*/, NIL, .F., .T.)
  EventCreate("LabelEventHandler", MainForm.Label1.HANDLE)

  MainForm.CENTER
  MainForm.ACTIVATE

RETURN NIL

FUNCTION LabelEventHandler()
  STATIC lTracking := .F.
  LOCAL  nHWnd := EventHWND()
  LOCAL  nMsg  := EventMSG()

  SWITCH nMsg
    CASE WM_MOUSEMOVE
      IF ! lTracking
        MainForm.Label1.FONTCOLOR := {255, 0, 0}
        MainForm.Label1.FONTBOLD  := .T.
        lTracking := TrackMouseEvent(nHWnd, 0x00000002 /*TME_LEAVE*/)
      ENDIF
      EXIT

    CASE WM_MOUSELEAVE
      MainForm.Label1.FONTCOLOR := {0, 0, 0}
      MainForm.Label1.FONTBOLD  := .F.
      lTracking := .F.
      EXIT
  ENDSWITCH

RETURN NIL

#pragma BEGINDUMP
#include <windows.h>
#include "hbapi.h"
#include "SET_COMPILE_HMG_UNICODE.ch"
#include "HMG_UNICODE.h"

HB_FUNC( TRACKMOUSEEVENT )
{
  TRACKMOUSEEVENT tmi;

  tmi.cbSize      = sizeof(TRACKMOUSEEVENT);
  tmi.dwFlags     = hb_parni(2);
  tmi.hwndTrack   = (HWND) HMG_parnl(1);
  tmi.dwHoverTime = HOVER_DEFAULT;

  hb_retl(TrackMouseEvent(&tmi));
}
#pragma ENDDUMP

Re: mouseover label

Posted: Sat Jun 09, 2018 8:52 pm
by esgici
KDJ wrote: Sat Jun 09, 2018 8:09 pm Can somebody know why WM_MOUSELEAVE message is not generated for LABEL and another controls?
...
Thanks, good question
MOUSELEAVE.JPG
MOUSELEAVE.JPG (16.95 KiB) Viewed 5422 times

Re: mouseover label

Posted: Sun Jun 10, 2018 7:33 am
by gfilatov
KDJ wrote: Sat Jun 09, 2018 8:09 pm Can somebody know why WM_MOUSELEAVE message is not generated for LABEL and another controls?
...
Hi,

Add SS_NOTIFY style to your Label definition :idea:

Hope that helps.

Re: mouseover label

Posted: Sun Jun 10, 2018 12:19 pm
by KDJ
Hi, Grigory
MSDN wrote: SS_NOTIFY
Sends the parent window STN_CLICKED, STN_DBLCLK, STN_DISABLE, and STN_ENABLE notification codes when the user clicks or double-clicks the control.
So applying SS_NOTIFY style should not affect the WM_MOUSELEAVE message generation.

In addition, this LABEL already has SS_NOTIFY style:
0x50800301 == WS_CHILD | WS_VISIBLE | WS_BORDER | SS_CENTERIMAGE | SS_NOTIFY | SS_CENTER

There must be some other reason that WM_MOUSELEAVE is not received.

Re: mouseover label

Posted: Sun Jun 10, 2018 3:42 pm
by gfilatov
KDJ wrote: Sun Jun 10, 2018 12:19 pm this LABEL already has SS_NOTIFY style:
...
Hi,

You are right!

Please take a look for an updated sample below:

Code: Select all

#include "hmg.ch"

STATIC lTracking := .F.

FUNCTION Main()

  DEFINE WINDOW MainForm;
    WIDTH  300;
    HEIGHT 200;
    MAIN ;
    ON MOUSEMOVE (MainForm.Label1.FONTCOLOR := {0, 0, 0}, MainForm.Label1.FONTBOLD := .F., lTracking := .F.)

    DEFINE LABEL Label1
      ROW       10
      COL       10
      WIDTH     140
      HEIGHT    45
      VALUE     "This is LABEL"
      ALIGNMENT Center
    END LABEL

    DEFINE BUTTON CloseButton
      ROW     70
      COL     10
      WIDTH   80
      HEIGHT  23
      CAPTION "Close"
      ACTION  MainForm.RELEASE
    END BUTTON

  END WINDOW

  HMG_ChangeWindowStyle(MainForm.Label1.HANDLE, 0x00800200 /*WS_BORDER|SS_CENTERIMAGE*/, NIL, .F., .T.)
  EventCreate("LabelEventHandler", MainForm.Label1.HANDLE)

  MainForm.CENTER
  MainForm.ACTIVATE

RETURN NIL


FUNCTION LabelEventHandler()

  LOCAL  nHWnd := EventHWND()
  LOCAL  nMsg  := EventMSG()

  SWITCH nMsg
    CASE WM_MOUSEMOVE
      IF ! lTracking
        MainForm.Label1.FONTCOLOR := {255, 0, 0}
        MainForm.Label1.FONTBOLD  := .T.
        lTracking := TrackMouseEvent(nHWnd, 0x00000002 /*TME_LEAVE*/)
      ENDIF
      EXIT

    CASE WM_MOUSELEAVE
      MainForm.Label1.FONTCOLOR := {0, 0, 0}
      MainForm.Label1.FONTBOLD  := .F.
      lTracking := .F.
      EXIT
  ENDSWITCH

RETURN NIL


#pragma BEGINDUMP

#include <windows.h>
#include "hbapi.h"
#include "SET_COMPILE_HMG_UNICODE.ch"
#include "HMG_UNICODE.h"

HB_FUNC( TRACKMOUSEEVENT )
{
  TRACKMOUSEEVENT tmi;

  tmi.cbSize      = sizeof(TRACKMOUSEEVENT);
  tmi.dwFlags     = hb_parni(2);
  tmi.hwndTrack   = (HWND) HMG_parnl(1);
  tmi.dwHoverTime = HOVER_DEFAULT;

  hb_retl(TrackMouseEvent(&tmi));
}

#pragma ENDDUMP
Just idea. :idea:

Re: mouseover label

Posted: Sun Jun 10, 2018 4:11 pm
by esgici
gfilatov wrote: Sun Jun 10, 2018 3:42 pm ...
Please take a look for an updated sample below
OK :arrow:

Thanks Grigory and KDJ 8-)

Happy HMG'ing

Re: mouseover label

Posted: Sun Jun 10, 2018 4:36 pm
by KDJ
Grigory

Yes, thank you for the idea.
This can also be done by processing WM_SETCURSOR message in main window event handler (example is here: viewtopic.php?f=9&t=4806&hilit=mouse+andyglez ).
But WM_MOUSELEAVE is still not received.
Why WM_MOUSELEAVE in HMG Extended works and in classic HMG doesn't work?