Shell Hooks and explorer.exe

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RomeoPapacy
    New Member
    • Aug 2008
    • 11

    Shell Hooks and explorer.exe

    I'm trying to write a replacement shell for Windows at the moment i have a working system tray and (sort-of) working taskbar.

    The issue at the moment is the Taskbar is failing to receive window created/activated/destroyed messages when run on it's own.
    If I run it on top of explorer it works fine. Even if i kill explorer and run it, it will work fine, but if a log into my user account with cmd.exe as shell and run it from there it receives no messages.

    At the moment I'm using SetWindowsHookE x, Does this function rel on some other process to do it's job? or is there and alternative function that will do this job with the need for explorer to have run?
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    What happens if you run your program as the shell as opposed to a command prompt?

    Comment

    • RomeoPapacy
      New Member
      • Aug 2008
      • 11

      #3
      Thank you for your reply:

      Same symptoms as when cmd is shell:
      - Notification area works wonderfully
      - Taskbar only seems to receive HSHELL_LANGUAGE messages

      Comment

      • RomeoPapacy
        New Member
        • Aug 2008
        • 11

        #4
        If it will help, here is the code for the hook. This is compiled as a DLL using VC++ 2008 Express:
        dllmain.cpp:
        Code:
        HINSTANCE hInst;
        BOOL APIENTRY DllMain( HMODULE hModule,
                               DWORD  ul_reason_for_call,
                               LPVOID lpReserved
        					 )
        {
        	switch (ul_reason_for_call)
        	{
        	case DLL_PROCESS_ATTACH:
        		hInst = (HINSTANCE) hModule;
        		break;
        	case DLL_THREAD_ATTACH:
        	case DLL_THREAD_DETACH:
        	case DLL_PROCESS_DETACH:
        		break;
        	}
        	return TRUE;
        }
        Hook.cpp:
        Code:
        extern HINSTANCE hInst;
        HWND callback=0;
        HHOOK hHook=0;
        std::fstream fLog("C:\\Logs\\Hook.log",std::fstream::out);
        HOOK_API void				SetHook(HWND hWnd){
        	hHook=SetWindowsHookEx(WH_SHELL,ShellProc,hInst,NULL);
        }
        LRESULT CALLBACK	ShellProc(int nCode, WPARAM wParam, LPARAM lParam){ 
        	if(nCode<0)return CallNextHookEx(hHook,nCode,wParam,lParam);
        	HWND h=FindWindow(TEXT("Shell_TrayWnd"),NULL);
        	fLog<<"Hook Message:"<<nCode<<endl;
        	switch(nCode){
        		case HSHELL_WINDOWCREATED:
        		case HSHELL_WINDOWACTIVATED:
        		case HSHELL_WINDOWDESTROYED:
        			PostMessage(h,WM_HOOKPROXY,(WPARAM)nCode,(LPARAM)wParam);
        			break;
        		case HSHELL_WINDOWREPLACED:
        			PostMessage(h,WM_HOOKPROXY,(WPARAM)HSHELL_WINDOWREPLACING,(LPARAM)wParam);
        			PostMessage(h,WM_HOOKPROXY,(WPARAM)HSHELL_WINDOWREPLACED,(LPARAM)wParam);
        			break;
        	}
        	return 0L;
        };

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          From the MSDN page on SetWindowsHookE h this paragraph seems relevant

          Originally posted by MSDN
          Note that custom shell applications do not receive WH_SHELL messages. Therefore, any application that registers itself as the default shell must call the SystemParameter sInfo function before it (or any other application) can receive WH_SHELL messages. This function must be called with SPI_SETMINIMIZE DMETRICS and a MINIMIZEDMETRIC S structure. Set the iArrange member of this structure to ARW_HIDE.
          I found it by Googling "WH_SHELL"

          Comment

          • RomeoPapacy
            New Member
            • Aug 2008
            • 11

            #6
            Once again Banfa - you're a lifesaver
            I must have read that page at least 5 times and never noticed that.

            Thank you.

            Comment

            Working...