Article View: borland.public.cppbuilder.nativeapi
Article #7262Re: Global window hook
From: roger
Date: Thu, 24 Feb 2005 11:58
Date: Thu, 24 Feb 2005 11:58
113 lines
4152 bytes
4152 bytes
Hi REMY...
I have found a snippet that you posted some while ago which i have created
and added the lib to the below project, but i am not getting any response
from the dll when a window opens or closes.
=============================
****** Header File contents *******
=============================
#ifndef mainUnitH
#define mainUnitH
//--------------------------------------------------------------------------
-
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//--------------------------------------------------------------------------
-
class TForm1 : public TForm
{
__published: // IDE-managed Components
TMemo *Memo1;
void __fastcall WMCopyData(TMessage &Message);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
public:
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(WM_COPYDATA, TMessage, WMCopyData)
END_MESSAGE_MAP(TForm)
__fastcall TForm1(TComponent* Owner);
};
//--------------------------------------------------------------------------
-
extern PACKAGE TForm1 *Form1;
//--------------------------------------------------------------------------
-
#endif
==========================
******* cpp file contents *******
==========================
//--------------------------------------------------------------------------
-
#include <vcl.h>
#pragma hdrstop
#include "mainUnit.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
extern "C" {
bool __stdcall __declspec(dllexport) InstallHook(void);
bool __stdcall __declspec(dllexport) RemoveHook(void);
}
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
InstallHook();
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::WMCopyData(TMessage &Message)
{
COPYDATASTRUCT *cds = (COPYDATASTRUCT*)Message.LParam;
if(cds->dwData == 10000) // message we sent ourselves
{
char *buffer = new char[cds->cbData];
memcpy(buffer, cds->lpData, cds->cbData);
Memo1->Lines->Add(buffer);
}
else
// we're not interested in this message, pass to default handling
TForm::Dispatch(&Message);
}
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
RemoveHook();
}
//--------------------------------------------------------------------------
-
***** end *****
"roger" <rogersmail@ntlworld.com> wrote in message
news:421d891c@newsgroups.borland.com...
> Thanks
>
> "Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
> news:421d81d6@newsgroups.borland.com...
> >
> > "roger" <rogersmail@ntlworld.com> wrote in message
> > news:421d76a8@newsgroups.borland.com...
> >
> > > Can someone please tell me the best way(if poss) to hook via
> > > a DLL when windows opens or closes a new window of any
> > > kind
> >
> > Look at the WH_CBT hook. It has HCBT_CREATEWND and HCBT_DESTROYWND
> > notifications.
> >
> >
> > Gambit
> >
> >
>
>
Technical Details
Message-ID:
<421dc13d$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<421d76a8@newsgroups.borland.com> <421d81d6@newsgroups.borland.com> <421d891c@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,9b9eac270d6034d6 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "roger" <rogersmail@ntlworld.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <421d76a8@newsgroups.borland.com> <421d81d6@newsgroups.borland.com> <421d891c@newsgroups.borland.com> Subject: Re: Global window hook Date: Thu, 24 Feb 2005 11:58:13 -0000 Lines: 115 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2739.300 NNTP-Posting-Host: 81.103.71.81 Message-ID: <421dc13d$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1109246269 81.103.71.81 (24 Feb 2005 03:57:49 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail