🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Windows Logo Key

#7443
From: Vladimir Stefanovic
Date: Sun, 30 Jan 2005 11:19
133 lines
4362 bytes
I asked this twice, unfortunately withount an answer.

If someone knows the way, I would also like to know
the way with a key hook. For now I know the way to
catch a single key with a key hook:

--- DLL ---

   #include <vcl.h>
   #include <windows.h>
   #pragma hdrstop

   #define WM_KEYHOOK       (WM_USER + 1002)
   HHOOK ghhookKB;
   HINSTANCE ghInst;
   #pragma argsused

   int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void 
*lpReserved)
   {
     ghInst = hinst;
     return ( 1 );
   }

   //---------------------------------------------------------------------------
   extern "C" __declspec(dllexport) __stdcall void SetHook(void);
   extern "C" __declspec(dllexport) __stdcall void RemoveHook(void);
   extern "C" __declspec(dllexport) __stdcall DWORD CheckKey(int, 
WORD,LONG);
   //---------------------------------------------------------------------------

   void __stdcall SetHook( void )
   {
      HOOKPROC lpfnHookProc = NULL;
      lpfnHookProc = GetProcAddress( GetModuleHandle( 
"altfhook.dll" ),"CheckKey" );
      ghhookKB = SetWindowsHookEx( WH_KEYBOARD, lpfnHookProc, ghInst, 
NULL );
   }

   void __stdcall RemoveHook( void )
   {
      UnhookWindowsHookEx( ghhookKB );
   }

   DWORD __stdcall CheckKey( int nCode, WORD wParam, LONG lParam )
   {
      HWND ghAppWnd = FindWindow( "TDiMainForm", 0 );

      if ( ( nCode < 0 ) || ( nCode == HC_NOREMOVE ) )
        return CallNextHookEx( ghhookKB, nCode, wParam, lParam );

      // Skip if it's a repeat
      if ( lParam & 0x40000000 )
         return CallNextHookEx( ghhookKB, nCode, wParam, lParam );

      // Send key information to the main window
      SendMessage( ghAppWnd, WM_KEYHOOK, 0, lParam );

      return CallNextHookEx( ghhookKB, nCode, wParam, lParam );
   }

--- H ---

   // ...
   #define WM_KEYHOOK     (WM_USER + 1002)
   // ...
   MESSAGE void __fastcall KeyHook(TMessage &Message);
   // ...
   BEGIN_MESSAGE_MAP
      // ...
      MESSAGE_HANDLER(WM_KEYHOOK, TMessage, KeyHook);
   END_MESSAGE_MAP(TForm)
   // ...

--- CPP ---

   // ...
   extern "C" __declspec(dllexport) __stdcall void SetHook(void);
   extern "C" __declspec(dllexport) __stdcall void RemoveHook(void);
   extern "C" __declspec(dllexport) __stdcall DWORD CheckKey(int, 
WORD,LONG);
   // ...

   __fastcall TDiMainForm::TDiMainForm(TComponent* Owner)
           : TForm(Owner)
   {
      // ...
      SetHook();
      // ...
   }

   __fastcall TDiMainForm::~TDiMainForm()
   {
      // ...
      RemoveHook();
      // ...
   }

   void __fastcall TDiMainForm::KeyHook( TMessage &Message )
   {
      char HKey[80];
      GetKeyNameText( Message.LParam, HKey, 80 );
      AnsiString MTCH = "";

      if ( AnsiString( HKey ) == "F9" )
      {
         // ...
      }

   }



-- 
Best regards,
Vladimir Stefanovic
"JD" <nospam@nospam.com> wrote in message 
news:41fcb2e4$1@newsgroups.borland.com...
>
> I'm interested in being able to catch when Windows Logo Key + D
> minimizes my application.
>
> Testing with it, I was unable to detect any messages being sent
> to the application as a result of the Win+D and I'm starting to
> think that it causes less of an 'all applications minimized' and
> more of a 'desktop bring to front'.
>
> Does anyone have any ideas where I should go next (This is for
> a component so a keyboard hook isn't an option) ?
>
> ~ JD
> 
Technical Details
Message-ID: <41fcc2db@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <41fcb2e4$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,57116bcc32c74587
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Vladimir Stefanovic" <antivari@po.sbb.co.yu>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <41fcb2e4$1@newsgroups.borland.com>
Subject: Re: Windows Logo Key
Date: Sun, 30 Jan 2005 12:19:55 +0100
Lines: 135
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 82.117.212.65
Message-ID: <41fcc2db@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1107083995 82.117.212.65 (30 Jan 2005 03:19:55 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail