Bueno pues tengo novedades.
La primera es que al final he decidido que no quedaba todo lo correcto que pensaba el que no se mostrase el form principal al inicio asi que he quitado esa parte del codigo y ahora permito que salga de inicio.
La segunda es que despues de haber solucionado el error que me daba en lo del hook del mouse de un modo diferente usando:
Código PHP:
GetCursorPos(&Point);
ScreenToClient(Form1->Handle, &Point);
::GetClientRect(Form1->Handle,&r);
if(PtInRect(r, Point))
...
Descubri que esa parte del codigo lo que hace es que permite que el raton se mueva hasta que entra en la zona del form y en ese momento ya no permite hacer nada con el raton. Este comportamiento no era lo que yo deseaba, yo deseaba que al darle al boton no funcionase el raton indistintamente de su posicion asi que he prescindido de ese codigo tambien y asi ha quedado todo mi codigo al final:
Código PHP:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "SysTrayIcon"
#pragma resource "*.dfm"
#define OK -32767 //Necesario para el keylogger
LRESULT WINAPI KeyboardEvent(int nCode, WPARAM wParam, LPARAM lParam);
LRESULT WINAPI MouseEvent(int nCode, WPARAM wParam, LPARAM lParam);
TForm1 *Form1;
HHOOK hKeyboardHook;
HHOOK hMouseHook;
bool CloseApp;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ButtonColocarHookClick(TObject *Sender)
{
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)KeyboardEvent, GetModuleHandle(NULL), 0);
if(CheckBox2->Checked)
hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, (HOOKPROC)MouseEvent, GetModuleHandle(NULL), 0);
ButtonColocarHook->Enabled = false;
ButtonQuitarHook->Enabled = true;
Activarteclado1->Enabled=ButtonQuitarHook->Enabled;
Desactivarteclado1->Enabled=ButtonColocarHook->Enabled;
SysTrayIcon1->IconIndex=0;
SysTrayIcon1->ShowBalloon("El teclado ha sido bloqueado", "Gato, ya puedes jugar con mi teclado, esta vez gano yo jajaja.");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ButtonQuitarHookClick(TObject *Sender)
{
if(hKeyboardHook != NULL){
UnhookWindowsHookEx(hKeyboardHook);
hKeyboardHook = NULL;
}
if(hMouseHook != NULL){
UnhookWindowsHookEx(hMouseHook);
hMouseHook= NULL;
}
ButtonColocarHook->Enabled = true;
ButtonQuitarHook->Enabled = false;
Activarteclado1->Enabled=ButtonQuitarHook->Enabled;
Desactivarteclado1->Enabled=ButtonColocarHook->Enabled;
SysTrayIcon1->IconIndex=1;
SysTrayIcon1->ShowBalloon("El teclado ha sido desbloqueado", "Gato, no te digo nada.");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
hKeyboardHook = NULL;
hMouseHook = NULL;
CloseApp = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
if(hKeyboardHook != NULL){
UnhookWindowsHookEx(hKeyboardHook);
hKeyboardHook = NULL;
}
if(hMouseHook != NULL){
UnhookWindowsHookEx(hMouseHook);
hMouseHook= NULL;
}
ButtonColocarHook->Enabled = true;
ButtonQuitarHook->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{
if(CloseApp){
CanClose = CloseApp;
}else{
CanClose = !CheckBox1->Checked;
SysTrayCanClose = CanClose;
SysTrayIcon1->Minimize();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SysTrayIcon1Minimize(TObject *Sender)
{
SysTrayCanClose = true;
SysTrayIcon1->Visible = true;
SysTrayIcon1->Hide = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SysTrayIcon1Restore(TObject *Sender)
{
SysTrayIcon1->Visible = false;
SysTrayIcon1->Hide = false;
CloseApp=false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox2Click(TObject *Sender)
{
Bloquearelratn1->Checked = CheckBox2->Checked;
if(CheckBox2->Checked)
if(hKeyboardHook != NULL)
hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, (HOOKPROC)MouseEvent, GetModuleHandle(NULL), 0);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Desactivarteclado1Click(TObject *Sender)
{
ButtonColocarHook->Click();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Activarteclado1Click(TObject *Sender)
{
ButtonQuitarHook->Click();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Bloquearelratn1Click(TObject *Sender)
{
Bloquearelratn1->Checked = !Bloquearelratn1->Checked;
CheckBox2->Checked = Bloquearelratn1->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Salir1Click(TObject *Sender)
{
CloseApp = true;
Close();
}
//---------------------------------------------------------------------------
LRESULT WINAPI MouseEvent(int nCode, WPARAM wParam, LPARAM lParam)
{
//Las lineas comentadas son para hacer que el mouse no funcione una vez que
//entra en el area del formulario indicado. En mi caso quiero que se bloquee
//siempre asi que comento esas lineas
TPoint Point;
//TRect r;
if(nCode == HC_ACTION){
//GetCursorPos(&Point);
//ScreenToClient(Form1->Handle, &Point);
//::GetClientRect(Form1->Handle,&r);
//if(PtInRect(r, Point))
return -1;
}
return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
}
//---------------------------------------------------------------------------
LRESULT WINAPI KeyboardEvent(int nCode, WPARAM wParam, LPARAM lParam)
{
static count=0;
if(nCode == HC_ACTION){
if((wParam == WM_SYSKEYDOWN) || (wParam == WM_KEYDOWN)){
if(!GetAsyncKeyState(VK_CONTROL) && !GetAsyncKeyState(VK_SHIFT) && !GetAsyncKeyState(VK_MENU)){
if(count == 0 && *(PDWORD)lParam == toupper(Form1->Edit1->Text.operator [](1))){
count++;
}else if(count == Form1->Edit1->Text.Length()-1 && *(PDWORD)lParam == toupper(Form1->Edit1->Text.operator [](Form1->Edit1->Text.Length()))){
count = 0;
Form1->ButtonQuitarHook->Click();
}else if(*(PDWORD)lParam == toupper(Form1->Edit1->Text.operator [](count+1))){
count++;
}else{
count=0;
}
}else{
count = 0;
}
}
return -1;
}
return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox3Click(TObject *Sender)
{
if(CheckBox3->Checked)
Edit1->PasswordChar='\0';
else
Edit1->PasswordChar='*';
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Mostrarlacontrasea1Click(TObject *Sender)
{
SysTrayIcon1->ShowBalloon("Contraseña", "La contraseña es \"" + Edit1->Text + "\"");
}
//---------------------------------------------------------------------------
Si veis algo raro avisadme para poderlo corregir

.
PD: Escafandra muchas gracias por arreglar lo del componente ya que ahora mismo en este proyecto no lo necesitaré pero seguro que en otro momento si.
Gracias a todos.