🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Problem with global hook?

#128
From: Patryk B.
Date: Thu, 12 Jun 2008 06:33
73 lines
3086 bytes
Hello,

I've wrote code that make inactive window transparent.
It's works but not to good :) I've used global hook to detect when window
is going to be active/inactive. Here is my code (from dll):

HINSTANCE hDLL;
HHOOK hWin;
HWND hWindow;
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)
{
	if(nCode <0)
	{
		return CallNextHookEx(hWin, nCode, wParam, lParam);
	}

	if(nCode==HC_ACTION)
	{
		CWPSTRUCT* msg=(CWPSTRUCT*)lParam;
		hWindow=msg->hwnd;
		if(msg->message==WM_ACTIVATE)
		{
			if(IsWindowVisible(hWindow) && (GetWindow(hWindow, GW_OWNER) == NULL)
&&((GetWindowLong(hWindow, GWL_EXSTYLE) & WS_EX_TOOLWINDOW) == 0))
			{
				if(LOWORD(msg->wParam==WA_INACTIVE))
				{
					SetWindowLong(hWindow, GWL_EXSTYLE,GetWindowLong(hWindow, GWL_EXSTYLE)
| WS_EX_LAYERED);
					::SetLayeredWindowAttributes(hWindow, 0, 180, LWA_ALPHA);

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

	return CallNextHookEx(hWin, nCode, wParam, lParam);
}
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*
lpReserved)
{
	hDLL=hinst;
	return 1;
}
//---------------------------------------------------------------------------
void _stdcall SetHook(void)
{
	hWin=SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc, hDLL, NULL);
}
//---------------------------------------------------------------------------
void _stdcall RemoveHook(void)
{
	UnhookWindowsHookEx(hWin);
}
//---------------------------------------------------------------------------


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.
It's laging and I dont know why...
When I put for example Beep() instead of setting transparency, pc beeping
when window changing state but it not laging. When I set transparency for
window from normal program (exe) it works ok. So why it dont work when im
trying to set transparency from that dll?

Patryk. 
Technical Details
Message-ID: <bhxmq2m9ts12.1p5w7pvxgm2as.dlg@40tude.net>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!news2.arglkargh.de!feeder.erje.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,72542b542452aa66,start
X-Google-Attributes: gid10cc67,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Patryk B." <no.spam@spam.pl>
Subject: Problem with global hook?
Newsgroups: borland.public.cppbuilder.nativeapi
User-Agent: 40tude_Dialog/2.0.15.1pl
MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-2"
Content-Transfer-Encoding: 8bit
Reply-To: no.spam@spam.pl
Date: Thu, 12 Jun 2008 08:33:15 +0200
Message-ID: <bhxmq2m9ts12.1p5w7pvxgm2as.dlg@40tude.net>
NNTP-Posting-Host: 79.188.146.2
X-Trace: newsgroups.borland.com 1213252394 79.188.146.2 (11 Jun 2008 23:33:14 -0700)
Lines: 73
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!news2.arglkargh.de!feeder.erje.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail