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 

captura del raton fuera del Form. Ayudaaaaa genios

 
Publicar nuevo tema   Responder al tema    Foros de discusión -> Consultas
Ver tema anterior :: Ver tema siguiente  
Autor Mensaje
Mensaje    Asunto: captura del raton fuera del Form. Ayudaaaaa genios Responder citando

necesito capturar el icono del cursor fuera y dentro de la aplicacion. No logro capturar fuera del Form. Quiero hacer captura del icono del cursor del raton por ejemplo cuando esta sobre el escritorio. Crying or Very sad
Volver arriba
Mensaje    Asunto: Responder citando

Para ello debes, utilizar algo que se denomina "hook", mira te paso un ejemplo para que te des una idea, lo encontre buscando en la red...


/**********uhook**************
//---------------------------------------------------------------------------

#include <vcl.h>
#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"));

*/

DllHandle=LoadLibrary("HookDll.dll");
PRINTHOOKFCT InstHook=reinterpret_cast<PRINTHOOKFCT>(GetProcAddress(DllHandle,"_CCInstallPrintHook"));

if(!InstHook())
{
Label1->Caption="no se puede instalar el Gancho!";
}
else Label1->Caption="Gancho Instalado!";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{


/* MOUSEHOOKFCT RemHook=reinterpret_cast<MOUSEHOOKFCT>(GetProcAddress(DllHandle,"_RemoveMouseHook"));

*/
PRINTHOOKFCT RemHook=reinterpret_cast<PRINTHOOKFCT>(GetProcAddress(DllHandle,"_CCRemovePrintHook"));
if(!RemHook())
{
Label1->Caption="No se Puede Remover el Gancho!";
}
else Label1->Caption="Gancho Desinstalado!";
FreeLibrary(DllHandle);

}
//---------------------------------------------------------------------------
/********************uhook.h*******************/
//---------------------------------------------------------------------------

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

// place this before the class declaration
typedef bool (__stdcall *PRINTHOOKFCT)();
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
HINSTANCE DllHandle;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

/****************hjookdll.cpp*********************/
//---------------------------------------------------------------------------

#include <vcl.h>
#include <windows.h>
#pragma hdrstop
//---------------------------------------------------------------------------
// Important note about DLL memory management when your DLL uses the
// static version of the RunTime Library:
//
// If your DLL exports any functions that pass String objects (or structs/
// classes containing nested Strings) as parameter or function results,
// you will need to add the library MEMMGR.LIB to both the DLL project and
// any other projects that use the DLL. You will also need to use MEMMGR.LIB
// if any other projects which use the DLL will be performing new or delete
// operations on any non-TObject-derived classes which are exported from the
// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
// EXE's to use the BORLNDMM.DLL as their memory manager. In these cases,
// the file BORLNDMM.DLL should be deployed along with your DLL.
//
// To avoid using BORLNDMM.DLL, pass string information using "char *" or
// ShortString parameters.
//
// If your DLL uses the dynamic version of the RTL, you do not need to
// explicitly add MEMMGR.LIB as this will be done implicitly for you
//---------------------------------------------------------------------------
// 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){
return CallNextHookEx(HookHandle,code,wParam,lParam);
}
//Define a rectangle
POINT MousePos;
RECT UpperRightCorner=Rect(Screen->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);
}
/***********fin*********************/


si te das cuenta,
_________________
Cool
Volver arriba
Ver perfil de usuario Enviar mensaje privado Enviar email MSN Messenger
Mensaje    Asunto: Responder citando

MUUUUUUUUchisimas gracias
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.