🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #14265

Re: Urgent FindWindow() with minimized window!!

#14265
From: Martin C
Date: Wed, 20 Aug 2003 07:25
152 lines
5875 bytes
Remy, I have the same problem as schandler, and I tried your solution
although the problem now is that I get ONLY the text entered through my
application windows and I can't capture any text entered through any other
running application, so please find below my code for the dll and my project
and please let me know what exactly I am doing wrong...

Regards

//Code in the
DLL/////////////////////////////////////////////////////////////////////////
////////////////////////////////

#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#define WM_KEYHOOK WM_USER+100

HHOOK ghhookKB;
HINSTANCE ghInst;
HWND ghAppWnd;

extern "C" __declspec(dllexport) __stdcall void SetHook(HWND);
extern "C" __declspec(dllexport) __stdcall void RemoveHook(void);
extern "C" __declspec(dllexport) __stdcall DWORD CheckKey(int, WORD, LONG);
//--------------------------------------------------------------------------
-
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*
lpReserved)
{
    ghInst = hinst;
    return (1);
}
//--------------------------------------------------------------------------
-
void __stdcall SetHook(HWND ghpWmd)
{
    ghAppWnd=ghpWmd;  //here I pass the Application Form Handle to the DLL
handle so I can use it every time I use SendMessage

    HOOKPROC lpfnHookProc = NULL;
    lpfnHookProc = GetProcAddress(GetModuleHandle("KBHookD.DLL"),
"CheckKey");
    ghhookKB = SetWindowsHookEx(WH_KEYBOARD, lpfnHookProc, ghInst, NULL);
}
//--------------------------------------------------------------------------
----
void __stdcall RemoveHook(void)
{
    UnhookWindowsHookEx(ghhookKB);
}
//--------------------------------------------------------------------------
----
DWORD __stdcall CheckKey(int nCode, WORD wParam, LONG lParam)
{
    if((nCode < 0) || nCode == HC_NOREMOVE)
        return CallNextHookEx(ghhookKB, nCode, wParam, lParam);

    // Skip if it's a repeat
    if(lParam & 0x40000000)
        return CallNextHookEx(ghhookKB, nCode, wParam, lParam);

    // Send key information to the main window
    SendMessage(ghAppWnd, WM_KEYHOOK, 0, lParam);

    return CallNextHookEx(ghhookKB, nCode, wParam, lParam);
}
//--------------------------------------------------------------------------
----


//Code in My Application
cpp/////////////////////////////////////////////////////////////////////////
////////////////////////////////

extern "C" __declspec(dllexport) __stdcall void SetHook(HWND);
extern "C" __declspec(dllexport) __stdcall void RemoveHook(void);
extern "C" __declspec(dllexport) __stdcall DWORD CheckKey(int, WORD,LONG);
//--------------------------------------------------------------------------
-
__fastcall TKeyMonitor::TKeyMonitor(TComponent* Owner)
        : TForm(Owner)
{
}
//--------------------------------------------------------------------------
-
void __fastcall TKeyMonitor::KeyHook(TMessage &Message)
{
    char MyKey[80];

    GetKeyNameText(Message.LParam, MyKey, 80);

     if (String(MyKey) != SpecialInput(MyKey))
        RichEdit1->Text = RichEdit1->Text + MyKey;

}
//--------------------------------------------------------------------------
-
void __fastcall TKeyMonitor::StartKeyMapping()
{
     SetHook(KeyMonitor->Handle);
}
//--------------------------------------------------------------------------
-
void __fastcall TKeyMonitor::EndKeyMapping()
{
     RemoveHook();
}
//--------------------------------------------------------------------------
-

//Code in My Application
Header//////////////////////////////////////////////////////////////////////
///////////////////////////////////

    MESSAGE void __fastcall KeyHook(TMessage &);

    BEGIN_MESSAGE_MAP
        MESSAGE_HANDLER(WM_KEYHOOK, TMessage, KeyHook);
    END_MESSAGE_MAP(TForm);





"Remy Lebeau (TeamB)" <gambit47@yahoo.com> wrote in message
news:3f425676$1@newsgroups.borland.com...
>
> "Schandler" <theslider@programmer.net> wrote in message
> news:3f41defb@newsgroups.borland.com...
> > I'm tyring to use the  FindWindow("className","title")  api in
> > a dll that will send Messages I receive using a Windows Hook
> > to a window in my application that have the className, and title
> > I pass to the FindWindow function.
>
> A better approach would be to store a HWND in the same block of memory
that
> you are storing the HHOOK handle, and then you don't have to find the
window
> each time, you already have it.  When the application installs the hook,
> have it pass its HWND to the DLL as well so it can be stored for later
use.
>
>
> Gambit
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.510 / Virus Database: 307 - Release Date: 8/14/03
>
>
Technical Details
Message-ID: <3f428826@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!in.100proofnews.com!in.100proofnews.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3f41defb@newsgroups.borland.com> <3f425676$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,2982d6ee34563d56
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-08-19 13:49:38 PST
From: "Martin C" <martinc@aol.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f41defb@newsgroups.borland.com> <3f425676$1@newsgroups.borland.com>
Subject: Re: Urgent FindWindow() with minimized window!!
Date: Tue, 19 Aug 2003 23:25:49 -0800
Lines: 154
Organization: V Safe
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 62.135.6.87
Message-ID: <3f428826@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1061324838 62.135.6.87 (19 Aug 2003 13:27:18 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!in.100proofnews.com!in.100proofnews.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail