Club Builder - Foros de discusión Club Builder
Foro de C++Builder en español
 
 FAQFAQ   BuscarBuscar   MiembrosMiembros   Grupos de UsuariosGrupos de Usuarios   RegistrarseRegistrarse 
 PerfilPerfil   Entra para ver tus mensajes privadosEntra para ver tus mensajes privados   EntrarEntrar 

Capturar el icono del raton fuera del form. fuerza Leo ayuda

 
Publicar nuevo tema   Responder al tema    Foros de discusión -> Consultas
Ver tema anterior :: Ver tema siguiente  
Autor Mensaje
Mensaje    Asunto: Capturar el icono del raton fuera del form. fuerza Leo ayuda Responder citando

Necesito capturar el icono del raton fuera de la aplicacion.
Volver arriba
Ver perfil de usuario Enviar mensaje privado
Mensaje    Asunto: Responder citando

Debes crear un "hook" al mouse, tiene que hacerse desde una DLL necesariamente, en este ejemplo se activa el boton de inicio o protector de pantalla (debe estar activo el protector para que funcione).

Código:

**************************uhook.cpp**************
//---------------------------------------------------------------------------

#include <vcl>
#pragma hdrstop
#include "UHook.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
 DllHandle=LoadLibrary("HookDll.dll");
  MOUSEHOOKFCT InstHook=reinterpret_cast<MOUSEHOOKFCT>
        (GetProcAddress(DllHandle,"_InstallMouseHook"));
  if(!InstHook())
  {
    Label1->Caption="Unable to install mouse hook!";
  }
  else Label1->Caption="Mouse hook installed!";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{

MOUSEHOOKFCT RemHook=reinterpret_cast<MOUSEHOOKFCT>
        (GetProcAddress(DllHandle,"_RemoveMouseHook"));
  if(!RemHook())
  {
    Label1->Caption="Unable to remove mouse hook!";
  }
  else Label1->Caption="Mouse hook removed!";
  FreeLibrary(DllHandle);
}
//---------------------------------------------------------------------------



LO SIGUIENTE VA DENTRO DEL MISMO PROYECTO PERO EN LA UNIDAD .H

Código:


//---------------------------------------------------------------------------

#ifndef UHookH
#define UHookH
//---------------------------------------------------------------------------
#include <Classes>
#include <Controls>
#include <StdCtrls>
#include <Forms>
//---------------------------------------------------------------------------

// para la programacion del gancho..
typedef  bool (__stdcall *MOUSEHOOKFCT)();

class TForm1 : public TForm
{
__published:   // IDE-managed Components
    TButton *Button1;
    TButton *Button2;
    TLabel *Label1;
    void __fastcall Button1Click(TObject *Sender);
    void __fastcall Button2Click(TObject *Sender);
private:   // User declarations

// variable privada, para la declaracion.
   HINSTANCE DllHandle;

public:      // User declarations
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif



TODO ESTO DENTRO DE UN SOLO PROYECTO. OJO NOTA LA REFERENCIA AL ARCHIVO DLL, EN LA PARTE DEL BUTTON1CLICK
EN LoadLibrary(<nombre>); que si le cambias el nombre debe ser el mismo,
LO ULTIMO QUE PONGO ES LA CREACION DE LA DLL,

Código:


//---------------------------------------------------------------------------

#include <vcl>
#include <windows>
#pragma hdrstop
//---------------------------------------------------------------------------
// Exported functions
extern "C" __declspec(dllexport)bool InstallMouseHook();
extern "C" __declspec(dllexport)bool RemoveMouseHook();

// Callback Procedure Declaration
LRESULT CALLBACK MouseProc(int code, WPARAM wParam, LPARAM lParam);

// Global variables
HHOOK HookHandle;
HINSTANCE DllInstance;
bool IsInRect=false;

#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
    DllInstance=hinst;
    return 1;
}
//---------------------------------------------------------------------------

bool InstallMouseHook()
{
  HookHandle=SetWindowsHookEx(WH_MOUSE,reinterpret_cast<HOOKPROC>(MouseProc),DllInstance,0);
  if (HookHandle==NULL)
    return false;
  else
    return true;
}
//---------------------------------------------------------------------------
bool RemoveMouseHook()
{
  if(UnhookWindowsHookEx(HookHandle)==0){
    return false;
  }else
    return true;
}
//---------------------------------------------------------------------------
LRESULT CALLBACK MouseProc(int code, WPARAM wParam, LPARAM lParam)
{
 if (code<0>Width-2,0,Screen->Width,2);
  //Get the mouse position
  GetCursorPos(&MousePos);
  //Check if the mouse is in the rectangle
  if((PtInRect(&UpperRightCorner,MousePos))&&(IsInRect==false))
  {
    //if the mouse is in the rectangle, launch the screensaver
    IsInRect=true;
    SendMessage(GetDesktopWindow(),WM_SYSCOMMAND,SC_SCREENSAVE,0);  // activa el quemador

//    SendMessage(GetDesktopWindow(),WM_SYSCOMMAND,SC_TASKLIST,0); //activa la bara de tareas

  }
  else IsInRect=false;
  //Call the next hook in the chain
  return CallNextHookEx(HookHandle,code,wParam,lParam);
}




LOS DOS PRIMEROS SON UN PROYECTO, LA DLL, BUENO ES UNA DLLL, DESDE FILE / NEW / DLL, bueno ya sabras como hacerle
_________________
Cool


Ultima edición por Cesar C. Salazar Gonzalez el Vie 12 Abr, 2019 2:24 am, editado 2 veces
Volver arriba
Ver perfil de usuario Enviar mensaje privado Enviar email MSN Messenger
Mensaje    Asunto: Responder citando

muchiiiiiiiiisimas gracias, me salvaste
Volver arriba
Mostrar mensajes de anteriores:   
Cambiar a:  
No puedes publicar temas nuevos en este foro
No puedes responder a temas en este foro
No puedes editar tus mensajes en este foro
No puedes borrar tus mensajes en este foro
No puedes votar en las encuestas de este foro


Hosting WordPress Indedmedia desde 3,99 €
© 2002–2026 Club Builder · Funciona con phpBB.