Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros temas > Trucos
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Los mejores trucos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 05-02-2017
Avatar de escafandra
[escafandra] escafandra is offline
Miembro Premium
 
Registrado: nov 2007
Posts: 2.197
Poder: 20
escafandra Tiene un aura espectacularescafandra Tiene un aura espectacular
Lo que sigue es la versión de la misma clase para su uso en Builder C++

Código:
// MouseLeave.cpp
//--------------------------------------------------------------------------------------------------
// TMouseLeave (Versión Hook estilo C++)
// escafandra 2017
// Clase para manejo de WM_MOUSELEAVE de una ventana


#ifndef MouseLeaveCPP
#define MouseLeaveCPP

#include <Windows.h>

#ifndef STRICT
  typedef int  (__stdcall *PLRESULT)();
#else
  typedef WNDPROC PLRESULT;
#endif

//typedef void (__fastcall *POnMouseLeave)(HWND hWnd, BOOL Enter);
typedef void __fastcall(__closure* POnMouseLeave)(HWND hWnd);
typedef void __fastcall(__closure* POnMouseEnter)(HWND hWnd);


class TMouseLeave
{
  private:
  HWND Handle;
  PLRESULT OldWndProc;
  static LRESULT __stdcall DefWndProc(HWND hWnd, UINT Msg, WPARAM WParam, LPARAM LParam)
  {
    TMouseLeave* pMouseLeave = (TMouseLeave*)GetWindowLongPtr(hWnd, GWL_USERDATA);
    if(pMouseLeave)
      return pMouseLeave->WndProc(hWnd, Msg, WParam, LParam);
    else
      return DefWindowProc(hWnd, Msg, WParam, LParam);
  }

  LRESULT __stdcall WndProc(HWND hWnd, UINT Msg, WPARAM WParam, LPARAM LParam)
  {
    if(Msg == WM_MOUSELEAVE && OnMouseLeave)
      OnMouseLeave(Handle);

    else if(Msg == WM_MOUSEMOVE && OnMouseEnter){
      TRACKMOUSEEVENT TE = {sizeof(TRACKMOUSEEVENT)};
      TE.dwFlags = TME_LEAVE;
      TE.hwndTrack = Handle;
      TE.dwHoverTime = HOVER_DEFAULT;
      TrackMouseEvent(&TE);
      OnMouseEnter(Handle);
    }

    return CallWindowProc(OldWndProc, hWnd, Msg, WParam, LParam);
  }

  public:
  POnMouseLeave OnMouseLeave;
  POnMouseEnter OnMouseEnter;

  void SetHandle(HWND hWnd)
  {
    if(hWnd != INVALID_HANDLE_VALUE && hWnd != Handle){
      if(!hWnd){
        SetWindowLong(GetParent(Handle), GWL_USERDATA, 0);
        SetWindowLong(GetParent(Handle), GWL_WNDPROC, (LONG)OldWndProc);
      }
      if(hWnd){
        SetWindowLongPtr(hWnd, GWL_USERDATA, (LONG)this);
        OldWndProc = (PLRESULT)SetWindowLongPtr(hWnd, GWL_WNDPROC, (LONG)TMouseLeave::DefWndProc);
      }
      Handle = hWnd;
    }
  }

  TMouseLeave(HWND hWnd = 0): OnMouseLeave(0), OnMouseEnter(0)
  {
    SetHandle(hWnd);
  }

  ~TMouseLeave() {SetHandle(0);}
};
#endif
Y un ejemplo con un TButton:
Código:
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "MouseLeave.cpp"
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published:    // IDE-managed Components
  TButton *Button1;
private:
  TMouseLeave ML;
  void __fastcall OnMouseLeave(HWND hWnd);
  void __fastcall OnMouseEnter(HWND hWnd);
public:        // User declarations
  __fastcall TForm2(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
//---------------------------------------------------------------------------
#endif
Código:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
  : TForm(Owner)
{
  ML.SetHandle(Button1->Handle);
  ML.OnMouseLeave = OnMouseLeave;
  ML.OnMouseEnter = OnMouseEnter;
}
//---------------------------------------------------------------------------

void __fastcall TForm2::OnMouseLeave(HWND hWnd)
{
  TButton *B = static_cast<TButton*>(FindControl(hWnd));
  if(B) B->Caption = "Adios";
}

void __fastcall TForm2::OnMouseEnter(HWND hWnd)
{
  TButton *B = static_cast<TButton*>(FindControl(hWnd));
  if(B) B->Caption = "Hola";
}

Saludos.
Responder Con Cita
  #2  
Antiguo 05-02-2017
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.055
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Responder Con Cita
  #3  
Antiguo 06-02-2017
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.289
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto

Gracias.
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Llamada WM_MOUSELEAVE en un TrayIcon byfali Varios 10 12-11-2008 17:46:32


La franja horaria es GMT +2. Ahora son las 19:04:42.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi