🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Problem with global hook?

#130
From: Remy Lebeau (TeamB)
Date: Thu, 12 Jun 2008 16:31
53 lines
2944 bytes
"Patryk B." <no.spam@spam.pl> wrote in message 
news:bhxmq2m9ts12.1p5w7pvxgm2as.dlg@40tude.net...

> HHOOK hWin;

That handle needs to be stored in a block of shared memory so that every 
instance of the DLL has access to it.  Use CreateFileMapping() and 
MapViewOfFile() to create such a memory block.

> extern "C" __declspec(dllexport) void _stdcall SetHook(void);
> extern "C" __declspec(dllexport) void _stdcall RemoveHook(void);
> LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)

You need to export your hook procedure as well:

    extern "C" __declspec(dllexport) LRESULT CALLBACK CallWndProc(int nCode, 
WPARAM wParam, LPARAM lParam);

> SetWindowLong(hWindow, GWL_EXSTYLE,GetWindowLong(hWindow, GWL_EXSTYLE)
> | WS_EX_LAYERED);

You should check if WS_EX_LAYERED is already applied before re-applying it:

    long exstyle = GetWindowLong(hWindow, GWL_EXSTYLE);
    if( (exstyle & WS_EX_LAYERED) == 0 )
        SetWindowLong(hWindow, GWL_EXSTYLE, exstyle | WS_EX_LAYERED);

> if(LOWORD(msg->wParam==WA_ACTIVE) ||
> LOWORD(msg->wParam==WA_CLICKACTIVE))
> {
> ::SetLayeredWindowAttributes(msg->hwnd, 0, 255, LWA_ALPHA);
> }

Likewise, you should check for WS_EX_LAYERED before calling 
SetLayeredWindowAttributes().

> Ok, code work like it should, inactive windows are transparent,
> active window not. But when im traying to move window it's
> move veeeery slow.

That is because your hook is getting called on every message that every 
window receives.  That is very inefficient.  You might consider using a 
WH_CBT hook instead, checking for the HCBT_ACTIVATE notification.

> When I put for example Beep() instead of setting transparency,
> pc beeping when window changing state but it not laging.

Applying and removing alpha blending is not a trivial task for the OS to 
perform.  So there is going to be some overhead to it.


Gambit 
Technical Details
Message-ID: <48514fa1$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <bhxmq2m9ts12.1p5w7pvxgm2as.dlg@40tude.net>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,72542b542452aa66
X-Google-Attributes: gid10cc67,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <bhxmq2m9ts12.1p5w7pvxgm2as.dlg@40tude.net>
Subject: Re: Problem with global hook?
Date: Thu, 12 Jun 2008 09:31:43 -0700
Lines: 55
Organization: Lebeau Software
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 207.178.157.90
Message-ID: <48514fa1$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1213288353 207.178.157.90 (12 Jun 2008 09:32:33 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail