Click here to Skip to main content
16,008,183 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: WTL CString disaster !!! Pin
Michael Dunn31-Mar-01 7:56
sitebuilderMichael Dunn31-Mar-01 7:56 
GeneralRe: WTL CString disaster !!! Pin
Christian Graus31-Mar-01 12:47
protectorChristian Graus31-Mar-01 12:47 
GeneralGlobalFree Pin
Jamie Nordmeyer30-Mar-01 11:54
Jamie Nordmeyer30-Mar-01 11:54 
GeneralRe: GlobalFree Pin
Tim Deveaux30-Mar-01 13:31
Tim Deveaux30-Mar-01 13:31 
GeneralRe: GlobalFree Pin
Jamie Nordmeyer2-Apr-01 5:46
Jamie Nordmeyer2-Apr-01 5:46 
GeneralADO Problem Pin
#realJSOP30-Mar-01 9:57
professional#realJSOP30-Mar-01 9:57 
GeneralRe: ADO Problem Pin
Anders Molin31-Mar-01 6:52
professionalAnders Molin31-Mar-01 6:52 
GeneralHelp needed! Please help Pin
Mustafa Demirhan30-Mar-01 8:53
Mustafa Demirhan30-Mar-01 8:53 
Hi, Confused | :confused:
One of my programs uses keyboard hook and shell hook. However, under win9x/ME it does not work as expected.
What's the point:
When Winscheduler is active and it is minimised on try bar...
If you minimize another program (e.g. Word, Acad 14, Excel ...), the icon of minimised program disappear from task bar. If you use ALT+TAB you can steel switch between programs.
Moreover, when you open a new window, it is not seen on the taskbar.

Here is the source code for the dll file:
<br />
// SystemHook.cpp : Defines the entry point for the DLL application.<br />
<br />
#include "stdafx.h"<br />
#include "SystemHook.h"<br />
#include <stdlib.h><br />
<br />
#define ID_CMD_KEYPRESSED	WM_USER+200<br />
#define ID_CMD_WNDCREATED	WM_USER+201<br />
<br />
// Shared DATA<br />
#pragma data_seg("SHARDATA")<br />
static HWND	hwndMain = NULL;		// Main hwnd. We will get this from the App<br />
#pragma data_seg()<br />
<br />
// Globals for this module <br />
HWND     ghWndMain;				// Handle to main window -- used to post msgs<br />
HHOOK    hHookKey;			    // A handle to our installed hook <br />
HHOOK    hHookShell;	        // A handle to our installed hook <br />
<br />
static BOOL     bHookInstalled; // TRUE if hook has been installed <br />
<br />
HINSTANCE ghDLLInst;			// Handle to the DLL's instance.  Set in DllMain.<br />
<br />
<br />
BOOL APIENTRY DllMain( HANDLE hModule, <br />
                       DWORD  ul_reason_for_call, <br />
                       LPVOID lpReserved)<br />
{<br />
    switch (ul_reason_for_call)<br />
	{<br />
		case DLL_PROCESS_ATTACH:<br />
		case DLL_THREAD_ATTACH:<br />
		case DLL_THREAD_DETACH:<br />
		case DLL_PROCESS_DETACH:<br />
			break;<br />
    }<br />
	ghDLLInst=(HINSTANCE)hModule;<br />
    return TRUE;<br />
}<br />
<br />
// This is the constructor of a class that has been exported.<br />
// see SystemHook.h for the class definition<br />
CSystemHook::CSystemHook()<br />
{ <br />
	return; <br />
}<br />
<br />
// KeyboardHook() <br />
SYSTEMHOOK_API LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)<br />
{<br />
	if (nCode >= 0) <br />
	{<br />
	   if(nCode == HC_NOREMOVE)<br />
		  return CallNextHookEx(hHookKey, nCode, wParam, lParam);<br />
<br />
	    // Skip if the key was released or if it's a repeat<br />
	    if (!(lParam & 0x80000000 || lParam & 0x40000000))<br />
		{<br />
			{<br />
				static HWND h=::FindWindow(NULL,"WinScheduler");<br />
				PostMessage(h , ID_CMD_KEYPRESSED , wParam, lParam);<br />
			}<br />
		}<br />
	}<br />
	return CallNextHookEx(hHookKey, nCode, wParam, lParam); <br />
}<br />
<br />
SYSTEMHOOK_API LRESULT CALLBACK ShellProc(int nCode,WPARAM wParam,LPARAM lParam)<br />
{<br />
	return CallNextHookEx(hHookShell, nCode, wParam, lParam); <br />
}<br />
<br />
//********************************************************************** <br />
// InstallHook() <br />
// Installs/Removes Filter function for the WH_KEYBOARD hook. <br />
// Parameters: <br />
// HWND hWnd      Handle to main window to receive posted messages.  See <br />
//                KeyboardProc() for more info on how it works. <br />
// BOOL bCode     TRUE to hook, FALSE to unhook <br />
// Returns: <br />
// 1 if successful, 0 if not. <br />
// <br />
//********************************************************************** <br />
SYSTEMHOOK_API int WINAPI InstallHook (HWND hWnd, BOOL bCode )<br />
{<br />
    int nReturn = 1;<br />
	ghWndMain = hWnd;  // Store app's window handle in DLL global variable <br />
<br />
    // Make sure that we are installing/removing in the proper order <br />
    if (bCode == bHookInstalled) <br />
        return 0; <br />
 <br />
    if (bCode)<br />
    {<br />
        hHookKey=(HHOOK)SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,ghDLLInst,0);<br />
		hHookShell=(HHOOK)SetWindowsHookEx(WH_SHELL,(HOOKPROC)ShellProc,ghDLLInst,0);<br />
        if (!hHookKey)<br />
            return 0; <br />
		if (!hHookShell)<br />
			return 0;<br />
        bHookInstalled = TRUE; <br />
    }<br />
    else <br />
    { <br />
        nReturn = UnhookWindowsHookEx(hHookKey);<br />
		nReturn &= UnhookWindowsHookEx(hHookShell);<br />
        bHookInstalled = FALSE; <br />
    }<br />
    return nReturn; <br />
}<br />

As it is seen, even if I am not doing anything in the ShellProc, the program does not work correctly. If i do not install the WH_SHELL hook, everything works fine.

Please help me. What may be the reason for this stupid behavior?

Best regards

Mustafa Demirhan
GeneralRe: Help needed! Please help Pin
BenDev30-Mar-01 9:27
BenDev30-Mar-01 9:27 
GeneralProcedure/Function question Pin
Richard Cheng30-Mar-01 6:58
Richard Cheng30-Mar-01 6:58 
GeneralRe: Procedure/Function question Pin
Tim Deveaux30-Mar-01 7:17
Tim Deveaux30-Mar-01 7:17 
GeneralRe: Procedure/Function question Pin
Richard Cheng30-Mar-01 7:29
Richard Cheng30-Mar-01 7:29 
GeneralURGENT - Please Help! Pin
Mustafa Demirhan30-Mar-01 6:13
Mustafa Demirhan30-Mar-01 6:13 
GeneralRe: URGENT - Please Help! Pin
Masaaki Onishi30-Mar-01 6:45
Masaaki Onishi30-Mar-01 6:45 
GeneralWarnings compiling STL Pin
30-Mar-01 3:05
suss30-Mar-01 3:05 
GeneralRe: Warnings compiling STL Pin
Chris Losinger30-Mar-01 3:44
professionalChris Losinger30-Mar-01 3:44 
GeneralRe: Warnings compiling STL Pin
Anders Molin31-Mar-01 6:59
professionalAnders Molin31-Mar-01 6:59 
Generalsending messages from a worker thread to cdocument Pin
derhackler29-Mar-01 23:17
derhackler29-Mar-01 23:17 
GeneralRe: sending messages from a worker thread to cdocument Pin
markkuk30-Mar-01 0:09
markkuk30-Mar-01 0:09 
GeneralRe: sending messages from a worker thread to cdocument Pin
derhackler30-Mar-01 0:54
derhackler30-Mar-01 0:54 
GeneralRe: sending messages from a worker thread to cdocument Pin
BenDev30-Mar-01 3:03
BenDev30-Mar-01 3:03 
GeneralRe: sending messages from a worker thread to cdocument Pin
Ajit Jadhav30-Mar-01 6:47
Ajit Jadhav30-Mar-01 6:47 
GeneralRe: sending messages from a worker thread to cdocument Pin
derhackler30-Mar-01 6:50
derhackler30-Mar-01 6:50 
GeneralRe: sending messages from a worker thread to cdocument Pin
Ajit Jadhav30-Mar-01 7:19
Ajit Jadhav30-Mar-01 7:19 
GeneralRe: sending messages from a worker thread to cdocument Pin
derhackler30-Mar-01 8:50
derhackler30-Mar-01 8:50 

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.