Click here to Skip to main content
15,910,773 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: What type of c source do you prefer? Pin
Rinu_Raj17-Sep-06 18:20
Rinu_Raj17-Sep-06 18:20 
AnswerRe: What type of c source do you prefer? Pin
_AnsHUMAN_ 17-Sep-06 18:31
_AnsHUMAN_ 17-Sep-06 18:31 
AnswerRe: What type of c source do you prefer? Pin
Robert Buldoc17-Sep-06 18:56
Robert Buldoc17-Sep-06 18:56 
AnswerRe: What type of c source do you prefer? Pin
Christian Graus17-Sep-06 19:36
protectorChristian Graus17-Sep-06 19:36 
AnswerRe: What type of c source do you prefer? Pin
Joe Woodbury17-Sep-06 19:53
professionalJoe Woodbury17-Sep-06 19:53 
QuestionCFileDialog problem! Pin
toanmtkh@yahoo.com17-Sep-06 17:49
toanmtkh@yahoo.com17-Sep-06 17:49 
AnswerRe: CFileDialog problem! Pin
S Douglas17-Sep-06 23:17
professionalS Douglas17-Sep-06 23:17 
QuestionHow to use SetWindowsHookEx to hook onto CreateWindowEx ? Pin
jipai17-Sep-06 15:59
jipai17-Sep-06 15:59 
Hi all,
Here is what I'm trying to do. I write a windowless application running in the background. I want to detect every call to CreateWindowEx. Basically, if any other application is trying to create a window that pops up on top of the active window, I want to move it behind the active window, not suppressing it like thouse popup blocker though. I read about it in MSDN and I think I can use SetWindowsHookEx to detect HCBT_CREATEWND. According to the documentation, I need to place the CBTProc function inside a dll. I've followed the steps but it still can't seem to detect HCBT_CREATEWND when other applications create a window. However, it can if the window is created by my own application. Am I missing something?

This is what I have in my application code:
dllModule = LoadLibrary(_T("My.dll"));
if (dllModule) 
{
	CBTProcPtr = (HOOKPROC) GetProcAddress(dllModule, "CBTProc");
	if (CBTProcPtr)
		g_hHook = ::SetWindowsHookEx(WH_CBT, CBTProcPtr, dllModule, 0); 
}


This is what I have in my dll code:
#include "stdafx.h"
#include <TCHAR.H>
#include "strsafe.h"
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
    return TRUE;
}

LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	TCHAR tempStr[1028] = {0};
	_stprintf_s(tempStr, _T("Inside CBTProc. nCode: %d\n"), nCode);
	OutputDebugString(tempStr);
	if (nCode == HCBT_CREATEWND)
	{
		OutputDebugString(L"Inside HCBT_CREATEWND\n");

		CBT_CREATEWND* wndData = (CBT_CREATEWND*)lParam;
		if (wndData && wndData->lpcs)
		{
			OutputDebugString(wndData->lpcs->lpszName);
			OutputDebugString(wndData->lpcs->lpszClass);
		}
	}

	return ::CallNextHookEx(0, nCode, wParam, lParam);
}

AnswerRe: How to use SetWindowsHookEx to hook onto CreateWindowEx ? Pin
_AnsHUMAN_ 17-Sep-06 17:54
_AnsHUMAN_ 17-Sep-06 17:54 
GeneralRe: How to use SetWindowsHookEx to hook onto CreateWindowEx ? Pin
jipai17-Sep-06 18:36
jipai17-Sep-06 18:36 
GeneralRe: How to use SetWindowsHookEx to hook onto CreateWindowEx ? Pin
Stephen Hewitt17-Sep-06 19:21
Stephen Hewitt17-Sep-06 19:21 
GeneralRe: How to use SetWindowsHookEx to hook onto CreateWindowEx ? Pin
Stephen Hewitt17-Sep-06 20:29
Stephen Hewitt17-Sep-06 20:29 
GeneralRe: How to use SetWindowsHookEx to hook onto CreateWindowEx ? Pin
Stephen Hewitt17-Sep-06 20:34
Stephen Hewitt17-Sep-06 20:34 
GeneralRe: How to use SetWindowsHookEx to hook onto CreateWindowEx ? Pin
jipai18-Sep-06 6:33
jipai18-Sep-06 6:33 
GeneralRe: How to use SetWindowsHookEx to hook onto CreateWindowEx ? Pin
Stephen Hewitt18-Sep-06 13:56
Stephen Hewitt18-Sep-06 13:56 
GeneralRe: How to use SetWindowsHookEx to hook onto CreateWindowEx ? Pin
jipai20-Sep-06 15:39
jipai20-Sep-06 15:39 
AnswerRe: How to use SetWindowsHookEx to hook onto CreateWindowEx ? Pin
Naveen17-Sep-06 17:58
Naveen17-Sep-06 17:58 
GeneralRe: How to use SetWindowsHookEx to hook onto CreateWindowEx ? Pin
jipai17-Sep-06 18:44
jipai17-Sep-06 18:44 
AnswerRe: How to use SetWindowsHookEx to hook onto CreateWindowEx ? Pin
Hamid_RT17-Sep-06 19:52
Hamid_RT17-Sep-06 19:52 
GeneralRe: How to use SetWindowsHookEx to hook onto CreateWindowEx ? Pin
jipai18-Sep-06 6:36
jipai18-Sep-06 6:36 
GeneralRe: How to use SetWindowsHookEx to hook onto CreateWindowEx ? Pin
Hamid_RT18-Sep-06 9:43
Hamid_RT18-Sep-06 9:43 
Questionworking with a COM port in C++/MFC Pin
jet91517-Sep-06 14:29
jet91517-Sep-06 14:29 
QuestionPassing data from modal dialog. Pin
SzyKam17-Sep-06 12:57
SzyKam17-Sep-06 12:57 
AnswerRe: Passing data from modal dialog. Pin
Christian Graus17-Sep-06 13:02
protectorChristian Graus17-Sep-06 13:02 
GeneralRe: Passing data from modal dialog. Pin
SzyKam17-Sep-06 13:12
SzyKam17-Sep-06 13:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.