Cesar C. Salazar Gonzalez Master


Registrado: 01 Oct 2002Mensajes: 2155Ubicación: San Cristóbal de Las Casas, Chiapas
|
Publicado: Mie 23 Abr, 2003 3:25 pm Asunto: |
|
|
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 _________________

Ultima edición por Cesar C. Salazar Gonzalez el Vie 12 Abr, 2019 2:24 am, editado 2 veces |
|